diff --git a/spark.meta.json b/spark.meta.json index fd74d91..81f8456 100644 --- a/spark.meta.json +++ b/spark.meta.json @@ -1,4 +1,4 @@ { "templateVersion": 0, - "dbType": null + "dbType": "kv" } \ No newline at end of file diff --git a/src/components/SnippetCard.tsx b/src/components/SnippetCard.tsx index 0e3f016..3bb8efa 100644 --- a/src/components/SnippetCard.tsx +++ b/src/components/SnippetCard.tsx @@ -1,174 +1,154 @@ -import { useState, useMemo } from 'react' -import { Badge } from '@/components/ui/badge' -import { Button } from '@/components/ui/button' -import { Card } from '@/components/ui/card' -import { Copy, Pencil, Trash, Ey - - snippet: Snippet - - onView: (snippet: Snippet) - - const [isCopied, setIsCopied] = us - - try { - const code = snippet?.code || - - - return { - description, - fullCode: code, - - } - set - title: 'Error Loading Snippet', - displayCode: '', - isTruncated: false, - hasPreview: false - } - - - setIsCopie - } - const handleEdit = - onEdit(snippet) - - e.stopPropagatio - } - const handleView = (e: React.MouseEvent) => { - onV - - return ( -
- - void + onDelete: (id: string) => void + onCopy: (code: string) => void + onView: (snippet: Snippet) => void +} + +export function SnippetCard({ snippet, onEdit, onDelete, onCopy, onView }: SnippetCardProps) { + const [isCopied, setIsCopied] = useState(false) + + const snippetData = useMemo(() => { + try { + const code = snippet?.code || '' + const description = snippet?.description || '' + const maxLength = 150 + const isTruncated = code.length > maxLength + const displayCode = isTruncated ? code.slice(0, maxLength) + '...' : code + + return { + description, + displayCode, + fullCode: code, + isTruncated, + hasPreview: snippet?.hasPreview || false + } + } catch (error) { + return { + description: '', + displayCode: '', + fullCode: '', + isTruncated: false, + hasPreview: false + } + } + }, [snippet]) + + const handleCopy = (e: React.MouseEvent) => { + e.stopPropagation() + onCopy(snippetData.fullCode) + setIsCopied(true) + setTimeout(() => setIsCopied(false), 2000) + } + + const handleEdit = (e: React.MouseEvent) => { + e.stopPropagation() + onEdit(snippet) + } + + const handleDelete = (e: React.MouseEvent) => { + e.stopPropagation() + onDelete(snippet.id) + } + + const handleView = (e: React.MouseEvent) => { + onView(snippet) + } + + if (!snippet) { + return ( +Error loading snippet
++ {snippetData.description} +
+ )} +
+ {snippetData.displayCode}
+
+ {snippetData.isTruncated && (
+ + Click to view full code... +
+ )} +