"use client"; import { useState, useEffect } from "react"; export function GenerateTab({ importType }: { importType: "flashcards" | "quizzes" | "connections" | "crossword" }) { const [instructions, setInstructions] = useState(""); const [loading, setLoading] = useState(true); const [saving, setSaving] = useState(false); const [saveResult, setSaveResult] = useState<"success" | "error" | null>(null); const [copied, setCopied] = useState(false); const [packCount, setPackCount] = useState(1); const batchOverride = importType === "connections" && packCount > 1 ? `TEMPORARY BATCH OVERRIDE:\nGenerate exactly ${packCount} distinct Connections packs. Return one raw JSON array containing exactly ${packCount} objects that each follow the schema below. Make the packs meaningfully different from one another. This override takes precedence over any later instruction to return one object.\n\n` : ""; const displayedInstructions = `${batchOverride}${instructions}`; useEffect(() => { fetch(`/api/settings/llm-instructions?type=${importType}`) .then((res) => res.json()) .then((data) => setInstructions(data.value)) .finally(() => setLoading(false)); }, [importType]); async function handleSave() { setSaving(true); setSaveResult(null); try { const res = await fetch(`/api/settings/llm-instructions?type=${importType}`, { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ value: instructions }), }); if (!res.ok) throw new Error("Failed to save"); setSaveResult("success"); } catch { setSaveResult("error"); } finally { setSaving(false); setTimeout(() => setSaveResult(null), 2500); } } async function handleReset() { if (!confirm("Reset to default instructions?")) return; setSaving(true); try { const res = await fetch(`/api/settings/llm-instructions?type=${importType}`, { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ value: "__RESET__" }), }); const data = await res.json(); setInstructions(data.value); } finally { setSaving(false); } } async function handleCopy() { await navigator.clipboard.writeText(displayedInstructions); setCopied(true); setTimeout(() => setCopied(false), 2000); } if (loading) { return
Copy these instructions and paste them into an LLM chat along with your study material. The LLM will generate JSON you can paste into the Import tab.
{importType === "connections" && (This temporarily updates the copied prompt. Your saved instructions stay unchanged.