Generated by Spark: Fix all reported errors.

This commit is contained in:
2026-01-17 15:29:39 +00:00
committed by GitHub
parent 0488b46184
commit e9beb0548a
2 changed files with 155 additions and 175 deletions

View File

@@ -1,4 +1,4 @@
{ {
"templateVersion": 0, "templateVersion": 0,
"dbType": null "dbType": "kv"
} }

View File

@@ -1,174 +1,154 @@
import { useState, useMemo } from 'react' import { useState, useMemo } from 'react'
import { Badge } from '@/components/ui/badge' import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button' import { Button } from '@/components/ui/button'
import { Card } from '@/components/ui/card' import { Card } from '@/components/ui/card'
import { Copy, Pencil, Trash, Ey import { Copy, Pencil, Trash, Eye } from '@phosphor-icons/react'
import { Snippet, LANGUAGE_COLORS } from '@/lib/types'
snippet: Snippet
interface SnippetCardProps {
onView: (snippet: Snippet) snippet: Snippet
onEdit: (snippet: Snippet) => void
const [isCopied, setIsCopied] = us onDelete: (id: string) => void
onCopy: (code: string) => void
try { onView: (snippet: Snippet) => void
const code = snippet?.code || }
export function SnippetCard({ snippet, onEdit, onDelete, onCopy, onView }: SnippetCardProps) {
return { const [isCopied, setIsCopied] = useState(false)
description,
fullCode: code, const snippetData = useMemo(() => {
try {
} const code = snippet?.code || ''
set const description = snippet?.description || ''
title: 'Error Loading Snippet', const maxLength = 150
displayCode: '', const isTruncated = code.length > maxLength
isTruncated: false, const displayCode = isTruncated ? code.slice(0, maxLength) + '...' : code
hasPreview: false
} return {
description,
displayCode,
setIsCopie fullCode: code,
} isTruncated,
const handleEdit = hasPreview: snippet?.hasPreview || false
onEdit(snippet) }
} catch (error) {
e.stopPropagatio return {
} description: '',
const handleView = (e: React.MouseEvent) => { displayCode: '',
onV fullCode: '',
isTruncated: false,
return ( hasPreview: false
<p cla }
) }
}, [snippet])
<Card
'group overfl const handleCopy = (e: React.MouseEvent) => {
)} e.stopPropagation()
<div className="p-6 onCopy(snippetData.fullCode)
<div className= setIsCopied(true)
setTimeout(() => setIsCopied(false), 2000)
}
const handleEdit = (e: React.MouseEvent) => {
<Badge e.stopPropagation()
className={ onEdit(snippet)
LANGUAGE_COLORS[sa }
>
</Badge> const handleDelete = (e: React.MouseEvent) => {
e.stopPropagation()
onDelete(snippet.id)
</pre> }
<p classNam
</p> const handleView = (e: React.MouseEvent) => {
onView(snippet)
}
<div className="flex-1 flex items-center
<Button if (!snippet) {
variant="g return (
<Card className="p-6">
<p className="text-muted-foreground">Error loading snippet</p>
</Button> </Card>
)
size="s }
return (
<Copy class <Card
</di className="group overflow-hidden hover:border-accent/50 transition-all cursor-pointer"
<div className="flex items-center gap-2 onClick={handleView}
size="sm" >
o <div className="p-6 space-y-4">
<div className="flex items-start justify-between gap-3">
<div className="flex-1 min-w-0">
<h3 className="text-lg font-semibold text-foreground mb-1 truncate">
{snippet.title}
</h3>
aria-lab {snippetData.description && (
<Trash className="h-4 w-4" /> <p className="text-sm text-muted-foreground line-clamp-2">
</div> {snippetData.description}
</Ca </p>
} )}
</div>
<Badge
className={`shrink-0 ${LANGUAGE_COLORS[snippet.language] || LANGUAGE_COLORS['Other']}`}
>
{snippet.language}
</Badge>
</div>
<div className="rounded-md bg-secondary/30 p-3 border border-border">
<pre className="text-xs text-muted-foreground overflow-x-auto whitespace-pre-wrap break-words font-mono">
{snippetData.displayCode}
</pre>
{snippetData.isTruncated && (
<p className="text-xs text-accent mt-2">
Click to view full code...
</p>
)}
</div>
<div className="flex items-center justify-between gap-2 pt-2">
<div className="flex-1 flex items-center gap-2">
<Button
variant="ghost"
size="sm"
onClick={handleView}
className="gap-2"
>
<Eye className="h-4 w-4" />
View
</Button>
</div>
<div className="flex items-center gap-2">
<Button
variant="ghost"
size="sm"
onClick={handleCopy}
className="gap-2"
aria-label="Copy code"
>
<Copy className="h-4 w-4" />
{isCopied ? 'Copied!' : 'Copy'}
</Button>
<Button
variant="ghost"
size="sm"
onClick={handleEdit}
aria-label="Edit snippet"
>
<Pencil className="h-4 w-4" />
</Button>
<Button
variant="ghost"
size="sm"
onClick={handleDelete}
className="text-destructive hover:text-destructive hover:bg-destructive/10"
aria-label="Delete snippet"
>
<Trash className="h-4 w-4" />
</Button>
</div>
</div>
</div>
</Card>
)
}