diff --git a/src/components/SnippetCard.tsx b/src/components/SnippetCard.tsx index 8d0d7ed..b493722 100644 --- a/src/components/SnippetCard.tsx +++ b/src/components/SnippetCard.tsx @@ -1,184 +1,174 @@ -import { useState, useMemo } from 'react' -import { Badge } from '@/components/ui/badg -import { cn } from '@/lib/utils' -import { Copy, Pencil, Trash, Eye } from '@phos -interface SnippetCardProps { - onEdit: (snippet: Snippet) => void - onCopy: (code: string) => void - -export function SnippetCard( - const [hasRender - const safeSnippet = useMemo(() => - const title = snippet?.tit - const description = snippe - const isTruncated = code.lengt - - -export function SnippetCard({ snippet, onEdit, onDelete, onCopy, onView }: SnippetCardProps) { - const [isCopied, setIsCopied] = useState(false) - const [hasRenderError, setHasRenderError] = useState(false) - - const safeSnippet = useMemo(() => { - try { - const title = snippet?.title || 'Untitled Snippet' - const code = snippet?.code || '' - const description = snippet?.description || '' - const maxCodeLength = 100 - const isTruncated = code.length > maxCodeLength - const displayCode = isTruncated ? code.slice(0, maxCodeLength) + '...' : code - - return { - title, - description, - displayCode, - fullCode: code, - isTruncated, - language: snippet?.language || 'Other', - hasPreview: snippet?.hasPreview || false - } - } catch { - setHasRenderError(true) - return { - title: 'Error Loading Snippet', - description: 'This snippet could not be loaded properly', - displayCode: '', - fullCode: '', - isTruncated: false, - language: 'Other', - hasPreview: false - } - } - }, [snippet]) - - const handleCopy = (e: React.MouseEvent) => { - e.stopPropagation() - onCopy(safeSnippet.fullCode) - setIsCopied(true) - setTimeout(() => setIsCopied(false), 2000) - } - - const handleEdit = (e: React.MouseEvent) => { - e.stopPropagation() - onEdit(snippet) - } - - > - - ) - - - 'group overflow - )} -
-

-

-

- {safeSnippet.displayCode} - {safeSnippet.isTrunc - - - e.stopPropagation() - }} - - )} - - - variant="gho - onClick={handleDelet - className="h-8 w-8 p-0 text-destructi - - < -

- ) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +import { useState, useMemo } from 'react' +import { Badge } from '@/components/ui/badge' +import { Button } from '@/components/ui/button' +import { Card } from '@/components/ui/card' +import { cn } from '@/lib/utils' +import { Copy, Pencil, Trash, Eye } from '@phosphor-icons/react' +import { Snippet, LANGUAGE_COLORS } from '@/lib/types' + +interface SnippetCardProps { + snippet: Snippet + onEdit: (snippet: Snippet) => 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 [hasRenderError, setHasRenderError] = useState(false) + + const safeSnippet = useMemo(() => { + try { + const title = snippet?.title || 'Untitled Snippet' + const code = snippet?.code || '' + const description = snippet?.description || '' + const maxCodeLength = 100 + const isTruncated = code.length > maxCodeLength + const displayCode = isTruncated ? code.slice(0, maxCodeLength) + '...' : code + + return { + title, + description, + displayCode, + fullCode: code, + isTruncated, + language: snippet?.language || 'Other', + hasPreview: snippet?.hasPreview || false + } + } catch { + setHasRenderError(true) + return { + title: 'Error Loading Snippet', + description: 'This snippet could not be loaded properly', + displayCode: '', + fullCode: '', + isTruncated: false, + language: 'Other', + hasPreview: false + } + } + }, [snippet]) + + const handleCopy = (e: React.MouseEvent) => { + e.stopPropagation() + onCopy(safeSnippet.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) => { + e.stopPropagation() + onView(snippet) + } + + if (hasRenderError) { + return ( + +

Error rendering snippet

+
+ ) + } + + return ( + +
+
+
+

+ {safeSnippet.title} +

+ {safeSnippet.description && ( +

+ {safeSnippet.description} +

+ )} +
+ + {safeSnippet.language} + +
+ +
+
+            {safeSnippet.displayCode}
+          
+ {safeSnippet.isTruncated && ( +

+ Click to view full code +

+ )} +
+
+ +
+
+ {safeSnippet.isTruncated && ( + + )} + + +
+ +
+ + + +
+
+
+ ) +}