Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | 33x 72x 72x 3x 3x 72x 72x 72x 33x 39x 72x | import { Copy, Pencil, Trash2 } from "lucide-react";
import { Button } from "./button";
import { Card, CardContent, CardFooter } from "./card";
import DeleteConfirmDialog from "@/pages/main-page/components/delete-dialog";
import { useState } from "react";
import { Badge } from "./badge";
import { ToolTipCover } from "./tooltip";
import { useFlowsheetCopyCreateMutation } from "../../api/apiStore.gen";
export type FlowsheetCardData = {
id: number;
name: string;
description: string;
imgUrl: string;
onClick?: () => void;
onDelete?: () => void;
onEdit?: () => void;
lastAccessed?: string;
showCopyButton?: boolean;
showDeleteButton?: boolean;
showEditButton?: boolean;
};
type CardGalleryProps = {
data: FlowsheetCardData[];
};
type FlowsheetCardProps = {
info: FlowsheetCardData;
};
const FlowsheetCard = ({ info }: FlowsheetCardProps) => {
const [copyFlowsheet] = useFlowsheetCopyCreateMutation();
const handleCardClick = (e: React.MouseEvent) => {
// Only trigger card click if the click wasn't on a button
if (!showDeleteDialog) {
info.onClick?.();
}
};
const [showDeleteDialog, setShowDeleteDialog] = useState(false);
const handleDelete = () => {
info.onDelete?.();
setShowDeleteDialog(false);
};
return (
<Card
className=" bg-red-500 bg-card shadow-md hover:shadow-lg p-4 hover:bg-white/15 duration-300 ease-in-out"
onClick={handleCardClick}
aria-label={"Project-Card " + info.name}
>
<CardContent>
{info.imgUrl && (
<img src={info.imgUrl} className="w-full h-40 object-cover" />
)}
</CardContent>
<CardFooter className="flex flex-col gap-2">
<p className="line-clamp-2">{info.name}</p>
<div className="flex flex-row justify-between items-center flex-wrap">
<ToolTipCover content={`Last Accessed: ${info.description}`} asChild>
<Badge
variant="secondary"
className="flex flex-row items-center gap-1 font-light"
>
{info.description}
</Badge>
</ToolTipCover>
<div className="flex flex-row">
{/* Show Edit button only for templates */}
{info.showEditButton && (
<Button
size="icon"
variant="ghost"
aria-label={"Edit " + info.name}
onClick={(e) => {
e.stopPropagation();
info.onEdit?.();
}}
>
<Pencil />
</Button>
)}
{/* Only show Copy button if showCopyButton is true*/}
{info.showCopyButton !== false && (
<Button
size="icon"
variant="ghost"
aria-label={"Copy " + info.name}
onClick={(e) => {
e.stopPropagation();
copyFlowsheet({ flowsheet: info.id });
}}
>
<Copy />
</Button>
)}
{/* Only show Delete button if showDeleteButton is true*/}
{info.showDeleteButton !== false && (
<Button
size="icon"
variant="ghost"
aria-label="Delete-Flowsheet"
onClick={(e) => {
e.stopPropagation();
setShowDeleteDialog(true);
}}
>
<Trash2 />
</Button>
)}
{showDeleteDialog && (
<DeleteConfirmDialog
fileName={info.name}
onDelete={handleDelete}
onCancel={() => setShowDeleteDialog(false)}
/>
)}
</div>
</div>
</CardFooter>
</Card>
);
};
const CardGallery = (props: CardGalleryProps) => {
return (
<div className="grid grid-cols-1 mb-56 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-4 w-full">
{props.data.map((info: FlowsheetCardData, index: number) => (
<FlowsheetCard key={index} info={info} />
))}
</div>
);
};
export default CardGallery; |