2026-06-25 19:47:57 +02:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import { useState } from 'react';
|
|
|
|
|
import { CheckCircle, Pin } from 'lucide-react';
|
2026-07-19 15:35:18 +02:00
|
|
|
import { addPin } from '@/lib/api/pins';
|
2026-06-25 19:47:57 +02:00
|
|
|
|
|
|
|
|
interface PinBadgeProps {
|
|
|
|
|
cid: string;
|
|
|
|
|
isPinned: boolean;
|
|
|
|
|
onPin: (cid: string) => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function PinBadge({ cid, isPinned, onPin }: PinBadgeProps) {
|
|
|
|
|
const [pinning, setPinning] = useState(false);
|
|
|
|
|
|
|
|
|
|
async function handlePin() {
|
|
|
|
|
setPinning(true);
|
|
|
|
|
try {
|
|
|
|
|
await addPin(cid);
|
|
|
|
|
onPin(cid);
|
2026-07-19 15:35:18 +02:00
|
|
|
} catch (err) {
|
|
|
|
|
console.error('[PinBadge] Failed to pin CID:', err);
|
2026-06-25 19:47:57 +02:00
|
|
|
} finally {
|
|
|
|
|
setPinning(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isPinned) {
|
|
|
|
|
return (
|
|
|
|
|
<span className="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-accent-green/10 text-accent-green text-xs font-medium">
|
|
|
|
|
<CheckCircle className="w-3.5 h-3.5" />
|
|
|
|
|
Pinned
|
|
|
|
|
</span>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<button
|
|
|
|
|
onClick={handlePin}
|
|
|
|
|
disabled={pinning}
|
|
|
|
|
className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-surface-600 text-surface-300 text-xs font-medium hover:bg-surface-700 hover:border-surface-500 transition-colors disabled:opacity-50"
|
|
|
|
|
>
|
|
|
|
|
<Pin className="w-3.5 h-3.5" />
|
|
|
|
|
{pinning ? 'Pinning…' : 'Pin this CID'}
|
|
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
}
|