45b886e398
Five S-sized items from HANDOFF.md's new-features backlog, all wiring up previously-orphaned infra: - createNotification now sends web push + email for every notification type (follow/comment/reply/reaction/rating/mention), not just comments - Personal recipe notes: private per-user notes on any viewable recipe (recipeNotes table had zero API/UI before this) - Recipe fork/clone: deep-copies a viewable recipe into your own library as a private draft, linked via recipeVariations, respects tier quota - Pantry-aware shopping lists: meal-plan-generated lists now subtract on-hand pantry quantities (ingredientId match, falling back to normalized name match) and flag partial/ambiguous matches instead of guessing - GDPR data export: downloadable JSON of a user's own content and activity across every relevant table, secrets/internal tables excluded New migrations 0025 (unique index for recipe-notes upsert) and 0026 (shopping_list_items.in_pantry) generated, left unapplied like 0023/0024. Verified with typecheck, lint, and a full local `docker build`. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
48 lines
1.6 KiB
TypeScript
48 lines
1.6 KiB
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
import { useTranslations } from "next-intl";
|
|
import { useRouter } from "next/navigation";
|
|
import { GitFork, Loader2 } from "lucide-react";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
|
|
import { toast } from "sonner";
|
|
|
|
export function ForkRecipeButton({ recipeId }: { recipeId: string }) {
|
|
const t = useTranslations("recipe");
|
|
const router = useRouter();
|
|
const [forking, setForking] = useState(false);
|
|
|
|
async function handleFork() {
|
|
setForking(true);
|
|
try {
|
|
const res = await fetch(`/api/v1/recipes/${recipeId}/fork`, { method: "POST" });
|
|
if (!res.ok) {
|
|
const data = await res.json() as { error?: string };
|
|
throw new Error(
|
|
res.status === 403 ? t("forkLimitReached") : (data.error ?? t("forkFailed"))
|
|
);
|
|
}
|
|
const data = await res.json() as { id: string };
|
|
toast.success(t("forked"));
|
|
router.push(`/recipes/${data.id}`);
|
|
} catch (err) {
|
|
toast.error(err instanceof Error ? err.message : t("forkFailed"));
|
|
setForking(false);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<TooltipProvider>
|
|
<Tooltip>
|
|
<TooltipTrigger render={
|
|
<Button variant="ghost" size="icon" onClick={() => { void handleFork(); }} disabled={forking} aria-label={t("forkTooltip")}>
|
|
{forking ? <Loader2 className="h-4 w-4 animate-spin" /> : <GitFork className="h-4 w-4" />}
|
|
</Button>
|
|
} />
|
|
<TooltipContent>{t("forkTooltip")}</TooltipContent>
|
|
</Tooltip>
|
|
</TooltipProvider>
|
|
);
|
|
}
|