From f42459e3fb092d9852abfd595494e7efd1d023a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Sat, 19 Sep 2026 21:27:01 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20teacher=20question=20genera?= =?UTF-8?q?tor,=20live=20nav=20for=20pending=20approvals=20and=20analysis?= =?UTF-8?q?=20-=20/ai/question-generation:=20pick=20one=20of=20the=20teach?= =?UTF-8?q?er's=20own=20(grade,=20course)=20=20=20pairs,=20a=20page=20rang?= =?UTF-8?q?e,=20difficulty,=20count=20and=20an=20optional=20example=20ques?= =?UTF-8?q?tion;=20=20=20POST=20/rag/questions=20returns=20the=20set,=20ea?= =?UTF-8?q?ch=20question=20can=20be=20copied=20or=20opened=20=20=20in=20th?= =?UTF-8?q?e=20bank=20form=20prefilled=20-=20"Bekleyen=20onaylar"=20links?= =?UTF-8?q?=20to=20the=20question=20pool's=20pending=20tab,=20the=20teache?= =?UTF-8?q?r=20=20=20approval=20queue;=20nav=20entries=20can=20now=20carry?= =?UTF-8?q?=20search=20params=20and=20win=20over=20the=20=20=20plain=20ent?= =?UTF-8?q?ry=20for=20the=20same=20path=20-=20"=C3=96=C4=9Frenci=20analizi?= =?UTF-8?q?"=20is=20the=20analysis=20board=20under=20Tracking=20for=20teac?= =?UTF-8?q?hers,=20so=20=20=20their=20AI=20group=20no=20longer=20lists=20i?= =?UTF-8?q?t=20twice=20-=20the=20three=20entries=20leave=20the=20"yak?= =?UTF-8?q?=C4=B1nda"=20shelf=20and=20their=20placeholder=20routes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/exams/bank-question-form.tsx | 5 +- src/components/layout/command-palette.tsx | 2 +- src/components/layout/mobile-nav-sheet.tsx | 5 +- src/components/layout/nav-items.test.ts | 20 +- src/components/layout/nav-items.ts | 38 ++- src/components/layout/side-nav.tsx | 7 +- .../generated-question-card.tsx | 61 ++++ src/lib/__tests__/question-generation.test.ts | 21 ++ src/lib/question-generation.ts | 73 +++++ src/pages/coming-soon-page.tsx | 3 - src/pages/question-generation-page.tsx | 261 ++++++++++++++++++ src/routes/router.tsx | 11 +- 12 files changed, 479 insertions(+), 28 deletions(-) create mode 100644 src/components/question-generation/generated-question-card.tsx create mode 100644 src/lib/__tests__/question-generation.test.ts create mode 100644 src/lib/question-generation.ts create mode 100644 src/pages/question-generation-page.tsx diff --git a/src/components/exams/bank-question-form.tsx b/src/components/exams/bank-question-form.tsx index 90ede15..4774654 100644 --- a/src/components/exams/bank-question-form.tsx +++ b/src/components/exams/bank-question-form.tsx @@ -24,6 +24,8 @@ import { useT } from "@/stores/preferences-context"; */ export function BankQuestionForm(props: { initial?: BankQuestion; + /** A new template started from generated text, filed under this course. */ + draft?: { courseId: string; text: string }; courses: Course[]; onSaved: (question: BankQuestion) => void; onCancel: () => void; @@ -34,7 +36,7 @@ export function BankQuestionForm(props: { () => props.initial?.subject ?? null, async (subjectId) => (await getSubjectById(subjectId).catch(() => null))?.course ?? "", ); - const [courseId, setCourseId] = createSignal(""); + const [courseId, setCourseId] = createSignal(props.draft?.courseId ?? ""); // Editing keeps the template's own course even when it is not one of ours (it is // shown as a disabled option); only a new template falls back to the first course. const selectedCourse = () => @@ -126,6 +128,7 @@ export function BankQuestionForm(props: { void navigate({ to: item.to }), + onSelect: () => void navigate({ to: item.to, search: item.search as never }), }); } } diff --git a/src/components/layout/mobile-nav-sheet.tsx b/src/components/layout/mobile-nav-sheet.tsx index 38188ba..83b7155 100644 --- a/src/components/layout/mobile-nav-sheet.tsx +++ b/src/components/layout/mobile-nav-sheet.tsx @@ -35,11 +35,12 @@ export function MobileNavSheet(props: { const feed = useShellFeed(); const modules = useModules(); const pathname = useRouterState({ select: (state) => state.location.pathname }); + const search = useRouterState({ select: (state) => state.location.search as Record }); // The primary destinations are already one tap away in the tab bar, so the // sheet lists everything else. const groups = () => visibleNavGroups(auth.user()?.role, modules.enabled()); - const current = () => routeNavItem(pathname(), auth.user()?.role); + const current = () => routeNavItem(pathname(), auth.user()?.role, search()); const badgeFor = (item: NavItem) => (item.id === "messages" ? feed.unreadMessages().total : 0); const runAction = (item: NavItem) => { props.onClose(); @@ -218,7 +219,7 @@ export function MobileNavSheet(props: { } > - + {content} diff --git a/src/components/layout/nav-items.test.ts b/src/components/layout/nav-items.test.ts index 4ee1ac2..bf47077 100644 --- a/src/components/layout/nav-items.test.ts +++ b/src/components/layout/nav-items.test.ts @@ -54,19 +54,18 @@ test("manager sees the same admin tree minus the admin-only entries", () => { expect(ids).not.toContain("data-protection"); }); -test("teacher's sidebar splits into short labelled sections with the soon shelf last", () => { +test("teacher's sidebar splits into short labelled sections, every entry live", () => { expect( visibleNavGroups("teacher").map((group) => ({ id: group.id, items: group.items.map((item) => item.id), })), ).toEqual([ - { id: "ai", items: ["ai-studio", "ai-study", "ai-insights", "ai-celebi"] }, + { id: "ai", items: ["ai-studio", "ai-study", "ai-celebi"] }, { id: "my-classroom", items: ["my-classes", "my-schedule", "courses"] }, - { id: "tracking", items: ["student-attendance", "student-marks", "student-pomodoros"] }, - { id: "teaching", items: ["homework", "exams", "question-bank", "questions", "notes", "whiteboards"] }, + { id: "tracking", items: ["student-attendance", "student-marks", "student-pomodoros", "student-analysis"] }, + { id: "teaching", items: ["homework", "exams", "question-bank", "question-generation", "questions", "pending-approvals", "notes", "whiteboards"] }, { id: "other", items: ["parent-communication", "appointments", "events", "meals", "work", "settings-teacher"] }, - { id: "soon", items: ["student-analysis", "pending-approvals", "question-generation"] }, ]); }); @@ -152,7 +151,10 @@ test("entries with no backend yet are flagged soon and route to the shared place }); test("the AI group exposes four separate module routes", () => { - for (const role of ["student", "teacher", "manager", "admin"] as const) { + // A teacher reaches the analysis board as "Öğrenci analizi" under Tracking. + expect(visibleNavGroups("teacher").find((group) => group.id === "ai")?.items.map((item) => item.id)).toEqual(["ai-studio", "ai-study", "ai-celebi"]); + expect(routeNavItem("/ai/insights", "teacher")?.id).toBe("student-analysis"); + for (const role of ["student", "manager", "admin"] as const) { const ai = visibleNavGroups(role).find((group) => group.id === "ai"); expect(ai?.items.map((item) => item.id)).toEqual(["ai-studio", "ai-study", "ai-insights", "ai-celebi"]); expect(ai?.items.every((item) => !item.soon)).toBe(true); @@ -252,3 +254,9 @@ test("module gate hides nests the school did not buy", () => { test("ungated entries never drop on module filtering", () => { expect(moduleVisible({ id: "x", to: "/calendar", labelKey: "nav.calendar", Icon: (() => null) as never }, [])).toBe(true); }); + +test("a search-carrying entry wins over the plain entry for the same path", () => { + expect(routeNavItem("/questions", "teacher", { status: "pending" })?.id).toBe("pending-approvals"); + expect(routeNavItem("/questions", "teacher", { status: "approved" })?.id).toBe("questions"); + expect(routeNavItem("/questions", "teacher")?.id).toBe("questions"); +}); diff --git a/src/components/layout/nav-items.ts b/src/components/layout/nav-items.ts index 7e85c4f..4766612 100644 --- a/src/components/layout/nav-items.ts +++ b/src/components/layout/nav-items.ts @@ -48,6 +48,12 @@ export type NavItem = { maxRole?: Role; exactRole?: Role; exact?: boolean; + /** + * Search params the entry links with (`/questions?status=pending`). It is + * active only while the URL carries them, and then wins over a plain entry + * for the same path. + */ + search?: Record; /** Backend module nest behind this entry; hidden when the school did not buy it. */ module?: string; /** No backend yet — routes to the shared placeholder and carries a "yakında" badge. */ @@ -112,6 +118,15 @@ const AI_GROUP: NavGroup = { items: [AI_STUDIO_ITEM, AI_STUDY_ITEM, AI_INSIGHTS_ITEM, AI_CELEBI_ITEM], }; +// A teacher's student analysis is the same board, listed under Tracking as +// "Öğrenci analizi" — so their AI group leaves it out instead of listing it twice. +const TEACHER_AI_GROUP: NavGroup = { + id: "ai", + labelKey: "nav.group.ai", + Icon: IconSparkles, + items: [AI_STUDIO_ITEM, AI_STUDY_ITEM, AI_CELEBI_ITEM], +}; + const PARENT_AI_GROUP: NavGroup = { id: "ai", labelKey: "nav.group.ai", @@ -204,7 +219,7 @@ const ADMIN_GROUPS: NavGroup[] = [ ]; const TEACHER_GROUPS: NavGroup[] = [ - AI_GROUP, + TEACHER_AI_GROUP, { id: "my-classroom", labelKey: "nav.group.myClassroom", @@ -223,6 +238,7 @@ const TEACHER_GROUPS: NavGroup[] = [ { id: "student-attendance", to: "/management/student-attendance", labelKey: "nav.attendance", Icon: IconClipboardCheck, module: "attendance" }, { id: "student-marks", to: "/management/student-marks", labelKey: "nav.studentMarks", Icon: IconChart, module: "marks" }, { id: "student-pomodoros", to: "/management/pomodoros", labelKey: "nav.studentPomodoro", Icon: IconTimer, module: "pomodoro" }, + { id: "student-analysis", to: "/ai/insights", labelKey: "nav.studentAnalysis", Icon: IconChart }, ], }, { @@ -233,7 +249,11 @@ const TEACHER_GROUPS: NavGroup[] = [ { id: "homework", to: "/homework", labelKey: "nav.homework", Icon: IconHomework, module: "homework" }, { id: "exams", to: "/exams", labelKey: "nav.exams", Icon: IconExam, module: "exams" }, { id: "question-bank", to: "/question-bank", labelKey: "nav.questionBank", Icon: IconArchive, module: "bank_questions" }, + { id: "question-generation", to: "/ai/question-generation", labelKey: "nav.questionGeneration", Icon: IconSparkles }, { id: "questions", to: "/questions", labelKey: "nav.questions", Icon: IconHelpCircle, module: "questions" }, + // The pool's own pending tab: for a teacher, `?status=pending` is the + // approval queue (`POST /questions/{id}/approve`). + { id: "pending-approvals", to: "/questions", search: { status: "pending" }, labelKey: "nav.pendingApprovals", Icon: IconClipboardCheck, module: "questions" }, { id: "notes", to: "/notes", labelKey: "nav.notes", Icon: IconNote, module: "notes" }, { id: "whiteboards", to: "/whiteboards", labelKey: "nav.whiteboards", Icon: IconEdit, module: "boards" }, ], @@ -251,11 +271,6 @@ const TEACHER_GROUPS: NavGroup[] = [ settingsAction("settings-teacher"), ], }, - soonGroup([ - { id: "student-analysis", to: "/coming-soon/ogrenci-analizi", labelKey: "nav.studentAnalysis", Icon: IconChart, soon: true }, - { id: "pending-approvals", to: "/coming-soon/bekleyen-onaylar", labelKey: "nav.pendingApprovals", Icon: IconHelpCircle, soon: true }, - { id: "question-generation", to: "/coming-soon/soru-uretimi", labelKey: "nav.questionGeneration", Icon: IconEdit, soon: true }, - ]), ]; const STUDENT_GROUPS: NavGroup[] = [ @@ -408,10 +423,15 @@ export function primaryPathActive(pathname: string, item: NavItem) { return pathActive(pathname, item.to, item.exact); } -export function routeNavItem(pathname: string, role: Role | undefined): NavItem | undefined { +function searchMatches(item: NavItem, search: Record | undefined) { + if (!item.search) return true; + return Object.entries(item.search).every(([key, value]) => search?.[key] === value); +} + +export function routeNavItem(pathname: string, role: Role | undefined, search?: Record): NavItem | undefined { return [...primaryNavItems(role), ...visibleNavItems(role)] - .filter((item) => pathActive(pathname, item.to, item.exact)) - .sort((a, b) => b.to.length - a.to.length)[0]; + .filter((item) => pathActive(pathname, item.to, item.exact) && searchMatches(item, search)) + .sort((a, b) => b.to.length - a.to.length || Number(!!b.search) - Number(!!a.search))[0]; } // Routes that are reachable but carry no sidebar entry — the account menu, a diff --git a/src/components/layout/side-nav.tsx b/src/components/layout/side-nav.tsx index 20381e8..ba5486c 100644 --- a/src/components/layout/side-nav.tsx +++ b/src/components/layout/side-nav.tsx @@ -32,10 +32,11 @@ export function SideNav(props: { const modules = useModules(); const navigate = useNavigate(); const pathname = useRouterState({ select: (state) => state.location.pathname }); + const search = useRouterState({ select: (state) => state.location.search as Record }); const home = () => (auth.user() ? [HOME_ITEM] : []); const groups = () => visibleNavGroups(auth.user()?.role, modules.enabled()); - const current = () => routeNavItem(pathname(), auth.user()?.role); + const current = () => routeNavItem(pathname(), auth.user()?.role, search()); const unread = () => feed.unreadMessages().total; const badgeFor = (item: NavItem) => (item.id === "messages" ? unread() : 0); @@ -143,7 +144,7 @@ export function SideNav(props: { } > - props.onNavigate?.()} title={t(item.labelKey)} aria-current={itemActive() ? "page" : undefined} class={linkClass()}> + props.onNavigate?.()} title={t(item.labelKey)} aria-current={itemActive() ? "page" : undefined} class={linkClass()}> {content} @@ -204,7 +205,7 @@ export function SideNav(props: { return; } props.onNavigate?.(); - void navigate({ to: item.to }); + void navigate({ to: item.to, search: item.search as never }); }} > diff --git a/src/components/question-generation/generated-question-card.tsx b/src/components/question-generation/generated-question-card.tsx new file mode 100644 index 0000000..8214c9e --- /dev/null +++ b/src/components/question-generation/generated-question-card.tsx @@ -0,0 +1,61 @@ +import { Show, createSignal } from "solid-js"; +import { Button } from "@/components/ui/button"; +import { IconCheck, IconCopy, IconPlus } from "@/components/ui/icons"; +import { useT } from "@/stores/preferences-context"; + +/** One AI-generated practice question with its range-bounded answer. */ +export function GeneratedQuestionCard(props: { + index: number; + question: string; + answer: string; + /** Absent when the school has no question bank. */ + onAddToBank?: () => void; +}) { + const t = useT(); + const [open, setOpen] = createSignal(false); + const [copied, setCopied] = createSignal(false); + const copy = async () => { + try { + await navigator.clipboard.writeText(`${props.question}\n\n${props.answer}`); + setCopied(true); + window.setTimeout(() => setCopied(false), 1500); + } catch { + // Clipboard can be blocked (insecure origin, permissions); nothing to undo. + } + }; + + return ( +
  • +
    + + {props.index + 1} + +
    +

    {props.question}

    + +
    +

    {props.answer}

    +
    +
    +
    + + + + + +
    +
    +
    +
  • + ); +} diff --git a/src/lib/__tests__/question-generation.test.ts b/src/lib/__tests__/question-generation.test.ts new file mode 100644 index 0000000..b955e9a --- /dev/null +++ b/src/lib/__tests__/question-generation.test.ts @@ -0,0 +1,21 @@ +import { MAX_PAGES, parsePages } from "@/lib/question-generation"; + +describe("parsePages", () => { + it("expands ranges and single pages, sorted and de-duplicated", () => { + expect(parsePages("3-5, 10, 4")).toEqual([3, 4, 5, 10]); + expect(parsePages(" 7 ")).toEqual([7]); + }); + + it("refuses anything that is not a page list", () => { + expect(parsePages("")).toBeNull(); + expect(parsePages("abc")).toBeNull(); + expect(parsePages("5-3")).toBeNull(); + expect(parsePages("0")).toBeNull(); + expect(parsePages("2,,x")).toBeNull(); + }); + + it("refuses more pages than one request may name", () => { + expect(parsePages(`1-${MAX_PAGES}`)).toHaveLength(MAX_PAGES); + expect(parsePages(`1-${MAX_PAGES + 1}`)).toBeNull(); + }); +}); diff --git a/src/lib/question-generation.ts b/src/lib/question-generation.ts new file mode 100644 index 0000000..7806e8a --- /dev/null +++ b/src/lib/question-generation.ts @@ -0,0 +1,73 @@ +import { getClasses } from "@/api/classes"; +import type { ClassGroup, Course } from "@/api/client"; +import { getCourseById } from "@/api/courses"; +import { getMyInstances } from "@/api/instances"; +import { FAN_OUT_LIMIT, mapConcurrent } from "@/lib/map-concurrent"; + +/** Pages one request may name; a wider range is almost always a typo. */ +export const MAX_PAGES = 200; + +/** + * "3-7, 10" → [3, 4, 5, 6, 7, 10]. Null for anything that is not a list of + * positive page numbers and ascending ranges, or that names more than + * MAX_PAGES pages — the form says so instead of sending a guess. + */ +export function parsePages(input: string): number[] | null { + const parts = input.split(",").map((part) => part.trim()).filter(Boolean); + if (parts.length === 0) return null; + const pages = new Set(); + for (const part of parts) { + const range = /^(\d+)\s*-\s*(\d+)$/.exec(part); + if (range) { + const from = Number(range[1]); + const to = Number(range[2]); + if (from < 1 || to < from || to - from + 1 > MAX_PAGES) return null; + for (let page = from; page <= to; page += 1) pages.add(page); + } else if (/^\d+$/.test(part) && Number(part) >= 1) { + pages.add(Number(part)); + } else { + return null; + } + if (pages.size > MAX_PAGES) return null; + } + return [...pages].sort((a, b) => a - b); +} + +/** One `(sinif, ders)` pair a teacher may generate over, with the catalog course behind it. */ +export type StudyScopeOption = { + key: string; + ders: string; + /** The şube grade; null for a school-wide club/etüt corpus. */ + sinif: string | null; + course: Course; + label: string; +}; + +/** + * The backend derives a caller's RAG scope from their own sections' instances + * — `ders` is the catalog course, `sinif` the şube's grade — and refuses any + * other pair, so the picker offers exactly those. Several şubeler of the same + * grade and course collapse into one pair. + */ +export async function loadStudyScopes(): Promise { + const [instances, classes] = await Promise.all([ + getMyInstances({ limit: 200 }), + getClasses({ limit: 200 }).catch(() => ({ items: [] as ClassGroup[] })), + ]); + const gradeOf = new Map(classes.items.map((klass) => [klass.id, klass.grade])); + const courseIds = [...new Set(instances.items.map((instance) => instance.course))]; + const courses = await mapConcurrent(courseIds, FAN_OUT_LIMIT, (id) => getCourseById(id).catch(() => null)); + const courseById = new Map(courses.filter((course): course is Course => course !== null).map((course) => [course.id, course])); + + const options = new Map(); + for (const instance of instances.items) { + const course = courseById.get(instance.course); + if (!course) continue; + const sinif = course.kind === "course" ? gradeOf.get(instance.class)?.trim() || null : null; + const key = `${course.title}\u0000${sinif ?? ""}`; + if (!options.has(key)) { + options.set(key, { key, ders: course.title, sinif, course, label: sinif ? `${course.title} · ${sinif}` : course.title }); + } + } + return [...options.values()].sort((a, b) => a.label.localeCompare(b.label, "tr")); +} diff --git a/src/pages/coming-soon-page.tsx b/src/pages/coming-soon-page.tsx index f78b1fc..face25c 100644 --- a/src/pages/coming-soon-page.tsx +++ b/src/pages/coming-soon-page.tsx @@ -17,9 +17,6 @@ const COMING_SOON_LABELS: Record = { "optik-okuma": "nav.opticalReading", raporlar: "nav.reports", "kvkk-denetim": "nav.dataProtection", - "ogrenci-analizi": "nav.studentAnalysis", - "bekleyen-onaylar": "nav.pendingApprovals", - "soru-uretimi": "nav.questionGeneration", "calisma-programim": "nav.studyPlan", }; diff --git a/src/pages/question-generation-page.tsx b/src/pages/question-generation-page.tsx new file mode 100644 index 0000000..7d50a46 --- /dev/null +++ b/src/pages/question-generation-page.tsx @@ -0,0 +1,261 @@ +import { For, Match, Show, Switch, createMemo, createSignal } from "solid-js"; +import { createResource } from "@/lib/create-resource"; +import { ApiError, formatApiError, type RagQuestionSet } from "@/api/client"; +import { postRagQuestions } from "@/api/rag"; +import { BankQuestionForm } from "@/components/exams/bank-question-form"; +import { PageHeader } from "@/components/layout/page-header"; +import { RouteGuard } from "@/components/layout/route-guard"; +import { GeneratedQuestionCard } from "@/components/question-generation/generated-question-card"; +import { ragCopy } from "@/components/rag/rag-copy"; +import { Alert } from "@/components/ui/alert"; +import { Button } from "@/components/ui/button"; +import { EmptyInline } from "@/components/ui/empty-inline"; +import { IconSparkles } from "@/components/ui/icons"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; +import { SearchableSelect } from "@/components/ui/searchable-select"; +import { SidePanel } from "@/components/ui/side-panel"; +import { Textarea } from "@/components/ui/textarea"; +import { createFlash } from "@/lib/flash"; +import { cn } from "@/lib/cn"; +import { loadStudyScopes, parsePages } from "@/lib/question-generation"; +import { useModules } from "@/stores/modules-context"; +import { usePreferences, useT } from "@/stores/preferences-context"; + +export default function QuestionGenerationPage() { + return ( + + + + ); +} + +/** The service's own difficulty vocabulary; the backend defaults to `orta`. */ +const DIFFICULTIES = ["kolay", "orta", "zor"] as const; +type Difficulty = (typeof DIFFICULTIES)[number]; +/** The door holds `n` to 1..=20. */ +const MAX_COUNT = 20; + +type Draft = { courseId: string; text: string }; + +/** + * A teacher's question generator: practice questions over a page range of + * the course notes behind one of their own (grade, course) pairs, via + * `POST /rag/questions`. Nothing is stored — a question worth keeping goes to + * the bank through the ordinary bank form, prefilled. + */ +function QuestionGenerationContent() { + const t = useT(); + const { locale } = usePreferences(); + const rag = () => ragCopy(locale()); + const modules = useModules(); + const [flash, setFlash] = createFlash(); + + const [scopes] = createResource(() => loadStudyScopes()); + const [scopeKey, setScopeKey] = createSignal(""); + const [pagesInput, setPagesInput] = createSignal(""); + const [difficulty, setDifficulty] = createSignal("orta"); + const [count, setCount] = createSignal("5"); + const [seed, setSeed] = createSignal(""); + const [pending, setPending] = createSignal(false); + const [error, setError] = createSignal(""); + const [pagesError, setPagesError] = createSignal(""); + const [result, setResult] = createSignal(null); + const [draft, setDraft] = createSignal(null); + + const scope = () => scopes()?.find((option) => option.key === scopeKey()) ?? null; + const courses = createMemo(() => [...new Map((scopes() ?? []).map((option) => [option.course.id, option.course])).values()]); + const canBank = () => modules.isEnabled("bank_questions"); + const difficultyLabel = (value: Difficulty) => + value === "kolay" ? rag().difficultyEasy : value === "zor" ? rag().difficultyHard : rag().difficultyMedium; + + const generate = async (event: SubmitEvent) => { + event.preventDefault(); + const current = scope(); + if (!current || pending()) return; + const pages = parsePages(pagesInput()); + if (!pages) { + setPagesError(t("qgen.pagesInvalid")); + return; + } + setPagesError(""); + setError(""); + setPending(true); + try { + setResult( + await postRagQuestions({ + ders: current.ders, + sinif: current.sinif, + pages, + n: Math.min(MAX_COUNT, Math.max(1, Math.trunc(Number(count())) || 5)), + difficulty: difficulty(), + seed_question: seed().trim() || null, + }), + ); + } catch (err) { + setResult(null); + if (err instanceof ApiError && err.status === 503) setError(t("qgen.unavailable")); + else if (err instanceof ApiError && err.status === 403) setError(t("qgen.outOfScope")); + else setError(formatApiError(err)); + } finally { + setPending(false); + } + }; + + return ( +
    +
    + +
    + + + {flash()} + + +
    +
    void generate(event)}> + 0} + fallback={

    {t("qgen.noScopes")}

    } + > +
    + + ({ value: option.key, label: option.label }))} + /> +
    + +
    + + { + setPagesInput(event.currentTarget.value); + setPagesError(""); + }} + /> +

    + {pagesError() || t("qgen.pagesHint")} +

    +
    + +
    +
    + +
    + + {(value) => ( + + )} + +
    +
    +
    + + setCount(event.currentTarget.value)} /> +
    +
    + +
    + +