forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits

generated-question-card.tsx61 lines, 2.6 KiBHistoryRawDownload
1import { Show, createSignal } from "solid-js";
2import { Button } from "@/components/ui/button";
3import { IconCheck, IconCopy, IconPlus } from "@/components/ui/icons";
4import { useT } from "@/stores/preferences-context";
5
6/** One AI-generated practice question with its range-bounded answer. */
7export function GeneratedQuestionCard(props: {
8 index: number;
9 question: string;
10 answer: string;
11 /** Absent when the school has no question bank. */
12 onAddToBank?: () => void;
13}) {
14 const t = useT();
15 const [open, setOpen] = createSignal(false);
16 const [copied, setCopied] = createSignal(false);
17 const copy = async () => {
18 try {
19 await navigator.clipboard.writeText(`${props.question}\n\n${props.answer}`);
20 setCopied(true);
21 window.setTimeout(() => setCopied(false), 1500);
22 } catch {
23 // Clipboard can be blocked (insecure origin, permissions); nothing to undo.
24 }
25 };
26
27 return (
28 <li class="rounded-xl border border-border-line bg-surface-base p-4 shadow-xs">
29 <div class="flex gap-3">
30 <span class="flex h-7 w-7 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-xs font-semibold tabular-nums text-primary-text">
31 {props.index + 1}
32 </span>
33 <div class="min-w-0 flex-1 space-y-3">
34 <p class="whitespace-pre-wrap text-sm leading-6 text-text-strong">{props.question}</p>
35 <Show when={open()}>
36 <div class="rounded-lg border border-border-hairline bg-surface-tint px-3 py-2.5 text-sm leading-6 text-text-default">
37 <p class="whitespace-pre-wrap">{props.answer}</p>
38 </div>
39 </Show>
40 <div class="flex flex-wrap items-center gap-2">
41 <Button type="button" size="sm" variant="outline" class="h-8 rounded-lg touch:h-10" aria-expanded={open()} onClick={() => setOpen((value) => !value)}>
42 {open() ? t("qgen.hideAnswer") : t("qgen.showAnswer")}
43 </Button>
44 <Button type="button" size="sm" variant="ghost" class="h-8 rounded-lg touch:h-10" onClick={() => void copy()}>
45 <Show when={copied()} fallback={<IconCopy class="h-3.5 w-3.5" />}>
46 <IconCheck class="h-3.5 w-3.5" />
47 </Show>
48 {copied() ? t("qgen.copied") : t("qgen.copy")}
49 </Button>
50 <Show when={props.onAddToBank}>
51 <Button type="button" size="sm" variant="ghost" class="ml-auto h-8 rounded-lg touch:h-10" onClick={() => props.onAddToBank?.()}>
52 <IconPlus class="h-3.5 w-3.5" />
53 {t("qgen.addToBank")}
54 </Button>
55 </Show>
56 </div>
57 </div>
58 </div>
59 </li>
60 );
61}