💄 exam question panel and flush table headers
Browse files at this commite726e760c27d4e214b16536d8025dc4ee97ff894Parent: 1b777d3- style
- 💄 exam question panel and flush table headers
6 changed files +120 -21
- src/components/exams/exam-questions-panel.tsx +14 -8
- src/components/exams/question-form.tsx +18 -10
- src/components/ui/data-table.tsx +5 -1
- src/i18n/locales/en.ts +28 -1
- src/i18n/locales/tr.ts +28 -1
- src/i18n/messages.ts +27 -0
src/components/exams/exam-questions-panel.tsxmodified+14 -8
| @@ -19,7 +19,6 @@ import { Alert } from "@/components/ui/alert"; | ||
| 19 | 19 | import { Badge } from "@/components/ui/badge"; |
| 20 | 20 | import { Button } from "@/components/ui/button"; |
| 21 | 21 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; |
| 22 | -import { FormDialog } from "@/components/ui/form-dialog"; | |
| 23 | 22 | import { SidePanel } from "@/components/ui/side-panel"; |
| 24 | 23 | import { BankQuestionPicker } from "@/components/exams/bank-question-picker"; |
| 25 | 24 | import { QuestionForm, type QuestionValues } from "@/components/exams/question-form"; |
| @@ -290,16 +289,23 @@ export function ExamQuestionsPanel(props: { | ||
| 290 | 289 | /> |
| 291 | 290 | </SidePanel> |
| 292 | 291 | |
| 293 | - <FormDialog | |
| 292 | + {/* A question with choices, pictures and a drawing is long — it gets | |
| 293 | + the full-height side panel (like the bank picker next to it) instead | |
| 294 | + of a centred dialog that scrolled under its own footer. */} | |
| 295 | + <SidePanel | |
| 296 | + guardUnsaved | |
| 297 | + size="wide" | |
| 294 | 298 | open={formOpen() || editing() != null} |
| 295 | 299 | onOpenChange={(open) => { |
| 296 | 300 | if (!open) { |
| 297 | - setEditing(null); | |
| 298 | - setFormOpen(false); | |
| 301 | + closeAfterGesture(() => { | |
| 302 | + setEditing(null); | |
| 303 | + setFormOpen(false); | |
| 304 | + }); | |
| 299 | 305 | } |
| 300 | 306 | }} |
| 301 | 307 | title={editing() ? t("questions.edit") : t("questions.add")} |
| 302 | - description={t("questions.title")} | |
| 308 | + description={editing() ? t("questions.editHelp") : t("questions.addHelp")} | |
| 303 | 309 | > |
| 304 | 310 | <QuestionForm |
| 305 | 311 | initial={formInitial()} |
| @@ -309,8 +315,8 @@ export function ExamQuestionsPanel(props: { | ||
| 309 | 315 | choiceImageSrc={(choiceId) => `/api/exams/${props.examId}/questions/${editing()?.id}/choices/${choiceId}/image`} |
| 310 | 316 | loadImageBlob={editing() ? () => getExamQuestionImageBlob(props.examId, editing()!.id) : undefined} |
| 311 | 317 | onCancel={() => { |
| 312 | - // In-body Cancel bypasses FormDialog's deferred onOpenChange, so | |
| 313 | - // defer here too — otherwise the same tap can reopen the form. | |
| 318 | + // Deferred like the panel's own close — otherwise the same tap | |
| 319 | + // can land on the trigger underneath and reopen the form. | |
| 314 | 320 | closeAfterGesture(() => { |
| 315 | 321 | setEditing(null); |
| 316 | 322 | setFormOpen(false); |
| @@ -318,7 +324,7 @@ export function ExamQuestionsPanel(props: { | ||
| 318 | 324 | }} |
| 319 | 325 | onSubmit={submit} |
| 320 | 326 | /> |
| 321 | - </FormDialog> | |
| 327 | + </SidePanel> | |
| 322 | 328 | |
| 323 | 329 | {error() && <p class="rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive-text">{error()}</p>} |
| 324 | 330 |
src/components/exams/question-form.tsxmodified+18 -10
| @@ -58,6 +58,8 @@ export type QuestionFormInitial = { | ||
| 58 | 58 | |
| 59 | 59 | export function QuestionForm(props: { |
| 60 | 60 | initial?: QuestionFormInitial; |
| 61 | + /** Starting text/kind for a new question (an AI-generated draft); ignored when `initial` is set. */ | |
| 62 | + draft?: { text: string; kind: QuestionKind }; | |
| 61 | 63 | subjects: Subject[]; |
| 62 | 64 | /** True while `subjects` is still loading, so a missing subject is not misreported. */ |
| 63 | 65 | subjectsPending?: boolean; |
| @@ -72,10 +74,10 @@ export function QuestionForm(props: { | ||
| 72 | 74 | }) { |
| 73 | 75 | const t = useT(); |
| 74 | 76 | let textAreaRef: HTMLTextAreaElement | undefined; |
| 75 | - const [text, setText] = createSignal(props.initial?.text ?? ""); | |
| 77 | + const [text, setText] = createSignal(props.initial?.text ?? props.draft?.text ?? ""); | |
| 76 | 78 | // No first-subject default: the subject is submitted, so the user picks it. |
| 77 | 79 | const [subjectId, setSubjectId] = createSignal(props.initial?.subject ?? ""); |
| 78 | - const [kind, setKind] = createSignal<QuestionKind>(props.initial?.kind ?? "choice"); | |
| 80 | + const [kind, setKind] = createSignal<QuestionKind>(props.initial?.kind ?? props.draft?.kind ?? "choice"); | |
| 79 | 81 | const [points, setPoints] = createSignal(String(props.initial?.points ?? 1)); |
| 80 | 82 | const [choiceSet, setChoiceSet] = createSignal<ChoiceSet>( |
| 81 | 83 | props.initial ? storedChoiceSet(props.initial.choices, props.initial.correct) : blankChoiceSet(), |
| @@ -99,9 +101,9 @@ export function QuestionForm(props: { | ||
| 99 | 101 | createEffect(() => { |
| 100 | 102 | const initial = props.initial; |
| 101 | 103 | untrack(() => { |
| 102 | - setText(initial?.text ?? ""); | |
| 104 | + setText(initial?.text ?? props.draft?.text ?? ""); | |
| 103 | 105 | setSubjectId(initial?.subject ?? ""); |
| 104 | - setKind(initial?.kind ?? "choice"); | |
| 106 | + setKind(initial?.kind ?? props.draft?.kind ?? "choice"); | |
| 105 | 107 | setPoints(String(initial?.points ?? 1)); |
| 106 | 108 | setChoiceSet(initial ? storedChoiceSet(initial.choices, initial.correct) : blankChoiceSet()); |
| 107 | 109 | setImage(null); |
| @@ -380,7 +382,10 @@ export function QuestionForm(props: { | ||
| 380 | 382 | <Show when={kind() === "choice"}> |
| 381 | 383 | <div class="rounded-lg border bg-card p-3.5 shadow-xs"> |
| 382 | 384 | <div class="mb-3 flex items-center justify-between gap-2 border-b border-border/50 pb-2"> |
| 383 | - <Label class="text-sm font-semibold">{t("questions.choices")}</Label> | |
| 385 | + <div class="min-w-0"> | |
| 386 | + <Label class="text-sm font-semibold">{t("questions.choices")}</Label> | |
| 387 | + <p class="mt-0.5 text-xs text-muted-foreground">{t("questions.correctHint")}</p> | |
| 388 | + </div> | |
| 384 | 389 | <Button type="button" variant="outline" size="sm" class="h-7 gap-1 text-xs" disabled={rows().length >= BANK_QUESTION_LIMITS.maxChoices} onClick={addChoice}> |
| 385 | 390 | <IconPlus class="h-3.5 w-3.5" /> |
| 386 | 391 | {t("questions.addChoice")} |
| @@ -464,13 +469,16 @@ export function QuestionForm(props: { | ||
| 464 | 469 | |
| 465 | 470 | {error() && <p class="rounded-sm bg-destructive/10 px-3 py-1.5 text-sm text-destructive-text">{error()}</p>} |
| 466 | 471 | |
| 467 | - <div class="sticky bottom-0 -mx-5 flex flex-wrap items-center gap-2 border-t border-border-hairline bg-surface-base px-5 pb-1 pt-4"> | |
| 468 | - <Button type="submit" class="h-8 text-xs font-semibold" disabled={pending()}> | |
| 469 | - {props.submitLabel ?? (props.initial ? t("common.update") : t("common.create"))} | |
| 470 | - </Button> | |
| 471 | - <Button type="button" variant="outline" class="h-8 text-xs font-semibold" onClick={props.onCancel}> | |
| 472 | + {/* `-bottom-5 pb-5` reaches over the panel body's own bottom padding — | |
| 473 | + with `bottom-0` the footer stuck above it and the form scrolled | |
| 474 | + visibly underneath. */} | |
| 475 | + <div class="!mt-auto sticky -bottom-5 z-10 -mx-5 -mb-5 flex flex-wrap items-center justify-end gap-2 border-t border-border-hairline bg-surface-base px-5 pb-5 pt-4"> | |
| 476 | + <Button type="button" variant="outline" size="sm" class="rounded-lg" onClick={props.onCancel}> | |
| 472 | 477 | {t("common.cancel")} |
| 473 | 478 | </Button> |
| 479 | + <Button type="submit" size="sm" class="min-w-[7.5rem] rounded-lg" disabled={pending()}> | |
| 480 | + {props.submitLabel ?? (props.initial ? t("common.update") : t("common.create"))} | |
| 481 | + </Button> | |
| 474 | 482 | </div> |
| 475 | 483 | </form> |
| 476 | 484 | ); |
src/components/ui/data-table.tsxmodified+5 -1
| @@ -400,7 +400,11 @@ export function DataTable<TData, TValue = unknown>(props: DataTableProps<TData, | ||
| 400 | 400 | </ul> |
| 401 | 401 | </Show> |
| 402 | 402 | <Show when={!useCards()}> |
| 403 | - <DataTableFrame class={sectioned() ? "rounded-xl border border-border-line bg-surface-base p-3 shadow-xs sm:p-4" : undefined}> | |
| 403 | + {/* No inner padding: the header row sits flush on the card's top edge. | |
| 404 | + A padded frame left it floating inside the card, and the sticky | |
| 405 | + header then pinned below that padding while rows scrolled through | |
| 406 | + the gap above it. */} | |
| 407 | + <DataTableFrame class={sectioned() ? "shadow-xs" : undefined}> | |
| 404 | 408 | <Table |
| 405 | 409 | class={cn("data-table table-fixed", props.tableClass)} |
| 406 | 410 | style={{ width: `max(100%, ${tableWidth()}px)` }} |
src/i18n/locales/en.tsmodified+28 -1
| @@ -433,6 +433,31 @@ export const en: Dict = { | ||
| 433 | 433 | "nav.studentAnalysis": "Student analysis", |
| 434 | 434 | "nav.pendingApprovals": "Pending approvals", |
| 435 | 435 | "nav.questionGeneration": "Question generation", |
| 436 | + "qgen.subtitle": "Generate practice questions from a page range of your own course notes.", | |
| 437 | + "qgen.scope": "Course and grade", | |
| 438 | + "qgen.scopePlaceholder": "Pick a course", | |
| 439 | + "qgen.noScopes": "You are not assigned to any section's course yet. Generation works on the courses of the sections you teach.", | |
| 440 | + "qgen.pages": "Pages", | |
| 441 | + "qgen.pagesHint": "Page numbers in the course notes, e.g. 3-7, 10", | |
| 442 | + "qgen.pagesInvalid": "Write the pages like 3-7, 10.", | |
| 443 | + "qgen.count": "Questions", | |
| 444 | + "qgen.difficulty": "Difficulty", | |
| 445 | + "qgen.seed": "Example question (optional)", | |
| 446 | + "qgen.seedHint": "Given one, the set is variations of it.", | |
| 447 | + "qgen.generate": "Generate", | |
| 448 | + "qgen.generating": "Preparing questions…", | |
| 449 | + "qgen.results": "Generated questions", | |
| 450 | + "qgen.resultsEmpty": "Pick a course and a page range, and the questions appear here.", | |
| 451 | + "qgen.noQuestions": "No questions could be drawn from this range.", | |
| 452 | + "qgen.showAnswer": "Show answer", | |
| 453 | + "qgen.hideAnswer": "Hide answer", | |
| 454 | + "qgen.addToBank": "Add to bank", | |
| 455 | + "qgen.copy": "Copy", | |
| 456 | + "qgen.copied": "Copied", | |
| 457 | + "qgen.unavailable": "Question generation is not available right now; the AI service for it is not connected.", | |
| 458 | + "qgen.outOfScope": "This course and grade are not among the sections you teach.", | |
| 459 | + "qgen.coveredPages": "Pages covered: {pages}", | |
| 460 | + "qgen.savedToBank": "The question was added to the bank.", | |
| 436 | 461 | "nav.parentCommunication": "Parent communication", |
| 437 | 462 | "nav.studyPlan": "Study plan", |
| 438 | 463 | "nav.topicMastery": "Topic mastery", |
| @@ -1343,6 +1368,8 @@ export const en: Dict = { | ||
| 1343 | 1368 | "questions.title": "Questions", |
| 1344 | 1369 | "questions.add": "Add question", |
| 1345 | 1370 | "questions.edit": "Edit question", |
| 1371 | + "questions.addHelp": "Write the question, pick its subject and points, then mark the correct choice.", | |
| 1372 | + "questions.editHelp": "Changes apply only to this exam.", | |
| 1346 | 1373 | "questions.empty": "No questions yet.", |
| 1347 | 1374 | "questions.text": "Question text", |
| 1348 | 1375 | "questions.kind": "Question kind", |
| @@ -1353,7 +1380,7 @@ export const en: Dict = { | ||
| 1353 | 1380 | "questions.choicePlaceholder": "Choice {index}", |
| 1354 | 1381 | "questions.correctAnswer": "Correct answer", |
| 1355 | 1382 | "questions.correct": "Mark correct", |
| 1356 | - "questions.correctHint": "Zero-based: first choice is 0.", | |
| 1383 | + "questions.correctHint": "Tap a letter to mark the correct answer.", | |
| 1357 | 1384 | "questions.kind.choice": "Choice", |
| 1358 | 1385 | "questions.kind.text": "Text", |
| 1359 | 1386 | "questions.image": "Question image", |
src/i18n/locales/tr.tsmodified+28 -1
| @@ -429,6 +429,31 @@ export const tr: Dict = { | ||
| 429 | 429 | "nav.studentAnalysis": "Öğrenci analizi", |
| 430 | 430 | "nav.pendingApprovals": "Bekleyen onaylar", |
| 431 | 431 | "nav.questionGeneration": "Soru üretimi", |
| 432 | + "qgen.subtitle": "Kendi ders notlarının seçtiğin sayfa aralığından pratik sorular üret.", | |
| 433 | + "qgen.scope": "Ders ve sınıf", | |
| 434 | + "qgen.scopePlaceholder": "Ders seç", | |
| 435 | + "qgen.noScopes": "Henüz bir şubenin dersine atanmadın. Soru üretimi, öğrettiğin şubelerin derslerinde çalışır.", | |
| 436 | + "qgen.pages": "Sayfalar", | |
| 437 | + "qgen.pagesHint": "Ders notlarındaki sayfa numaraları, ör. 3-7, 10", | |
| 438 | + "qgen.pagesInvalid": "Sayfaları 3-7, 10 biçiminde yaz.", | |
| 439 | + "qgen.count": "Soru sayısı", | |
| 440 | + "qgen.difficulty": "Zorluk", | |
| 441 | + "qgen.seed": "Örnek soru (isteğe bağlı)", | |
| 442 | + "qgen.seedHint": "Yazarsan bu sorunun varyasyonları üretilir.", | |
| 443 | + "qgen.generate": "Soru üret", | |
| 444 | + "qgen.generating": "Sorular hazırlanıyor…", | |
| 445 | + "qgen.results": "Üretilen sorular", | |
| 446 | + "qgen.resultsEmpty": "Ders ve sayfa aralığı seç; sorular burada görünür.", | |
| 447 | + "qgen.noQuestions": "Bu aralıktan soru çıkarılamadı.", | |
| 448 | + "qgen.showAnswer": "Cevabı göster", | |
| 449 | + "qgen.hideAnswer": "Cevabı gizle", | |
| 450 | + "qgen.addToBank": "Bankaya ekle", | |
| 451 | + "qgen.copy": "Kopyala", | |
| 452 | + "qgen.copied": "Kopyalandı", | |
| 453 | + "qgen.unavailable": "Soru üretimi şu an kullanılamıyor; bunun için yapay zekâ servisi bağlı değil.", | |
| 454 | + "qgen.outOfScope": "Bu ders ve sınıf öğrettiğin şubeler arasında değil.", | |
| 455 | + "qgen.coveredPages": "Kapsanan sayfalar: {pages}", | |
| 456 | + "qgen.savedToBank": "Soru bankaya eklendi.", | |
| 432 | 457 | "nav.parentCommunication": "Veli iletişimi", |
| 433 | 458 | "nav.studyPlan": "Çalışma programım", |
| 434 | 459 | "nav.topicMastery": "Konu yetkinliğim", |
| @@ -1339,6 +1364,8 @@ export const tr: Dict = { | ||
| 1339 | 1364 | "questions.title": "Sorular", |
| 1340 | 1365 | "questions.add": "Soru ekle", |
| 1341 | 1366 | "questions.edit": "Soruyu düzenle", |
| 1367 | + "questions.addHelp": "Soruyu yaz, konusunu ve puanını seç, ardından doğru seçeneği işaretle.", | |
| 1368 | + "questions.editHelp": "Değişiklikler yalnızca bu sınavda geçerli olur.", | |
| 1342 | 1369 | "questions.empty": "Henüz soru yok.", |
| 1343 | 1370 | "questions.text": "Soru metni", |
| 1344 | 1371 | "questions.kind": "Soru türü", |
| @@ -1349,7 +1376,7 @@ export const tr: Dict = { | ||
| 1349 | 1376 | "questions.choicePlaceholder": "Seçenek {index}", |
| 1350 | 1377 | "questions.correctAnswer": "Doğru cevap", |
| 1351 | 1378 | "questions.correct": "Doğru seç", |
| 1352 | - "questions.correctHint": "Sıfırdan başlar: ilk seçenek 0.", | |
| 1379 | + "questions.correctHint": "Doğru cevabı işaretlemek için harfe tıkla.", | |
| 1353 | 1380 | "questions.kind.choice": "Seçmeli", |
| 1354 | 1381 | "questions.kind.text": "Metin", |
| 1355 | 1382 | "questions.image": "Soru görseli", |
src/i18n/messages.tsmodified+27 -0
| @@ -401,6 +401,31 @@ export type MessageKey = | ||
| 401 | 401 | | "nav.studentAnalysis" |
| 402 | 402 | | "nav.pendingApprovals" |
| 403 | 403 | | "nav.questionGeneration" |
| 404 | + | "qgen.subtitle" | |
| 405 | + | "qgen.scope" | |
| 406 | + | "qgen.scopePlaceholder" | |
| 407 | + | "qgen.noScopes" | |
| 408 | + | "qgen.pages" | |
| 409 | + | "qgen.pagesHint" | |
| 410 | + | "qgen.pagesInvalid" | |
| 411 | + | "qgen.count" | |
| 412 | + | "qgen.difficulty" | |
| 413 | + | "qgen.seed" | |
| 414 | + | "qgen.seedHint" | |
| 415 | + | "qgen.generate" | |
| 416 | + | "qgen.generating" | |
| 417 | + | "qgen.results" | |
| 418 | + | "qgen.resultsEmpty" | |
| 419 | + | "qgen.noQuestions" | |
| 420 | + | "qgen.showAnswer" | |
| 421 | + | "qgen.hideAnswer" | |
| 422 | + | "qgen.addToBank" | |
| 423 | + | "qgen.copy" | |
| 424 | + | "qgen.copied" | |
| 425 | + | "qgen.unavailable" | |
| 426 | + | "qgen.outOfScope" | |
| 427 | + | "qgen.coveredPages" | |
| 428 | + | "qgen.savedToBank" | |
| 404 | 429 | | "nav.parentCommunication" |
| 405 | 430 | | "nav.studyPlan" |
| 406 | 431 | | "nav.topicMastery" |
| @@ -1242,6 +1267,8 @@ export type MessageKey = | ||
| 1242 | 1267 | | "questions.title" |
| 1243 | 1268 | | "questions.add" |
| 1244 | 1269 | | "questions.edit" |
| 1270 | + | "questions.addHelp" | |
| 1271 | + | "questions.editHelp" | |
| 1245 | 1272 | | "questions.empty" |
| 1246 | 1273 | | "questions.text" |
| 1247 | 1274 | | "questions.kind" |