Files
Epicure/apps/web/components/collections/fork-collection-button.tsx
T
Arnaud 9d02a69250 feat(social): follows, favorites, comments, reactions, collections, public profiles
Follow/unfollow users. Recipe favorites. Threaded comments with emoji reactions.
Collections (public/private) with shared member invite. Activity feed.
Public profile pages at /u/[username].
2026-07-01 08:10:30 +02:00

37 lines
1.2 KiB
TypeScript

"use client";
import { useState } from "react";
import { useRouter } from "next/navigation";
import { GitFork } from "lucide-react";
import { Button } from "@/components/ui/button";
import { toast } from "sonner";
export function ForkCollectionButton({ collectionId }: { collectionId: string }) {
const [forking, setForking] = useState(false);
const router = useRouter();
async function handleFork() {
setForking(true);
try {
const res = await fetch(`/api/v1/collections/${collectionId}/fork`, { method: "POST" });
if (!res.ok) {
const data = await res.json() as { error?: string };
throw new Error(data.error ?? "Fork failed");
}
const { id } = await res.json() as { id: string };
toast.success("Collection forked to your library");
router.push(`/collections/${id}`);
} catch (err) {
toast.error(err instanceof Error ? err.message : "Fork failed");
setForking(false);
}
}
return (
<Button variant="outline" size="sm" onClick={() => { void handleFork(); }} disabled={forking} className="gap-2 shrink-0">
<GitFork className="h-4 w-4" />
{forking ? "Forking…" : "Fork collection"}
</Button>
);
}