✨ add question button in exam detail section header
Browse files at this commit41ee7b677012bf86aefad74c311a9e4bb9ef855eParent: bae9525- feat
- ✨ add question button in exam detail section header
2 changed files +34 -10
src/components/exams/exam-questions-panel.tsxmodified+13 -8
| @@ -23,7 +23,7 @@ import { useT } from "@/stores/preferences-context"; | |||
| 23 | 23 | ||
| 24 | const QUESTION_PAGE_SIZE = 5; | 24 | const QUESTION_PAGE_SIZE = 5; |
| 25 | 25 | ||
| 26 | -export function ExamQuestionsPanel(props: { examId: string; courseId: string; readOnly?: boolean; embedded?: boolean }) { | 26 | +export function ExamQuestionsPanel(props: { examId: string; courseId: string; readOnly?: boolean; embedded?: boolean; createOpen?: boolean; onCreateOpenChange?: (open: boolean) => void }) { |
| 27 | const t = useT(); | 27 | const t = useT(); |
| 28 | const [subjects] = createResource(() => props.courseId, async (courseId) => (await getCourseSubjects(courseId)).items); | 28 | const [subjects] = createResource(() => props.courseId, async (courseId) => (await getCourseSubjects(courseId)).items); |
| 29 | const [questions, { refetch }] = createResource(() => props.examId, async (examId) => { | 29 | const [questions, { refetch }] = createResource(() => props.examId, async (examId) => { |
| @@ -41,6 +41,11 @@ export function ExamQuestionsPanel(props: { examId: string; courseId: string; re | |||
| 41 | const [imagePending, setImagePending] = createSignal(""); | 41 | const [imagePending, setImagePending] = createSignal(""); |
| 42 | const [flash, setFlash] = createFlash(); | 42 | const [flash, setFlash] = createFlash(); |
| 43 | const [page, setPage] = createSignal(0); | 43 | const [page, setPage] = createSignal(0); |
| 44 | + const formOpen = () => props.createOpen ?? showForm(); | ||
| 45 | + const setFormOpen = (open: boolean) => { | ||
| 46 | + props.onCreateOpenChange?.(open); | ||
| 47 | + setShowForm(open); | ||
| 48 | + }; | ||
| 44 | 49 | ||
| 45 | const formInitial = createMemo(() => editing() ?? undefined); | 50 | const formInitial = createMemo(() => editing() ?? undefined); |
| 46 | const questionList = createMemo(() => questions() ?? []); | 51 | const questionList = createMemo(() => questions() ?? []); |
| @@ -55,7 +60,7 @@ export function ExamQuestionsPanel(props: { examId: string; courseId: string; re | |||
| 55 | createEffect(() => { | 60 | createEffect(() => { |
| 56 | if (!props.readOnly) return; | 61 | if (!props.readOnly) return; |
| 57 | setEditing(null); | 62 | setEditing(null); |
| 58 | - setShowForm(false); | 63 | + setFormOpen(false); |
| 59 | setRemoveQuestion(null); | 64 | setRemoveQuestion(null); |
| 60 | }); | 65 | }); |
| 61 | 66 | ||
| @@ -83,7 +88,7 @@ export function ExamQuestionsPanel(props: { examId: string; courseId: string; re | |||
| 83 | setFlash(t("common.created")); | 88 | setFlash(t("common.created")); |
| 84 | } | 89 | } |
| 85 | setEditing(null); | 90 | setEditing(null); |
| 86 | - setShowForm(false); | 91 | + setFormOpen(false); |
| 87 | await refetch(); | 92 | await refetch(); |
| 88 | if (isNewQuestion) setPage(Math.max(0, Math.ceil(questionList().length / QUESTION_PAGE_SIZE) - 1)); | 93 | if (isNewQuestion) setPage(Math.max(0, Math.ceil(questionList().length / QUESTION_PAGE_SIZE) - 1)); |
| 89 | } catch (err) { | 94 | } catch (err) { |
| @@ -130,14 +135,14 @@ export function ExamQuestionsPanel(props: { examId: string; courseId: string; re | |||
| 130 | <Show when={!props.embedded}> | 135 | <Show when={!props.embedded}> |
| 131 | <h2 class="font-display text-lg font-semibold">{t("questions.title")}</h2> | 136 | <h2 class="font-display text-lg font-semibold">{t("questions.title")}</h2> |
| 132 | </Show> | 137 | </Show> |
| 133 | - <Show when={!props.readOnly}> | 138 | + <Show when={!props.readOnly && !props.embedded}> |
| 134 | <Button | 139 | <Button |
| 135 | type="button" | 140 | type="button" |
| 136 | variant="outline" | 141 | variant="outline" |
| 137 | size="sm" | 142 | size="sm" |
| 138 | onClick={() => { | 143 | onClick={() => { |
| 139 | setEditing(null); | 144 | setEditing(null); |
| 140 | - setShowForm(true); | 145 | + setFormOpen(true); |
| 141 | }} | 146 | }} |
| 142 | > | 147 | > |
| 143 | <IconPlus class="h-4 w-4" /> | 148 | <IconPlus class="h-4 w-4" /> |
| @@ -147,11 +152,11 @@ export function ExamQuestionsPanel(props: { examId: string; courseId: string; re | |||
| 147 | </div> | 152 | </div> |
| 148 | 153 | ||
| 149 | <FormDialog | 154 | <FormDialog |
| 150 | - open={showForm() || editing() != null} | 155 | + open={formOpen() || editing() != null} |
| 151 | onOpenChange={(open) => { | 156 | onOpenChange={(open) => { |
| 152 | if (!open) { | 157 | if (!open) { |
| 153 | setEditing(null); | 158 | setEditing(null); |
| 154 | - setShowForm(false); | 159 | + setFormOpen(false); |
| 155 | } | 160 | } |
| 156 | }} | 161 | }} |
| 157 | title={editing() ? t("questions.edit") : t("questions.add")} | 162 | title={editing() ? t("questions.edit") : t("questions.add")} |
| @@ -162,7 +167,7 @@ export function ExamQuestionsPanel(props: { examId: string; courseId: string; re | |||
| 162 | subjects={subjects() ?? []} | 167 | subjects={subjects() ?? []} |
| 163 | onCancel={() => { | 168 | onCancel={() => { |
| 164 | setEditing(null); | 169 | setEditing(null); |
| 165 | - setShowForm(false); | 170 | + setFormOpen(false); |
| 166 | }} | 171 | }} |
| 167 | onSubmit={submit} | 172 | onSubmit={submit} |
| 168 | /> | 173 | /> |
src/pages/exam-detail-page.tsxmodified+21 -2
| @@ -27,7 +27,7 @@ import { Badge } from "@/components/ui/badge"; | |||
| 27 | import { Button } from "@/components/ui/button"; | 27 | import { Button } from "@/components/ui/button"; |
| 28 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; | 28 | import { ConfirmDialog } from "@/components/ui/confirm-dialog"; |
| 29 | import { DataTable } from "@/components/ui/data-table"; | 29 | import { DataTable } from "@/components/ui/data-table"; |
| 30 | -import { IconChevronLeft, IconEdit, IconExam, IconEye, IconTrash } from "@/components/ui/icons"; | 30 | +import { IconChevronLeft, IconEdit, IconExam, IconEye, IconPlus, IconTrash } from "@/components/ui/icons"; |
| 31 | import { PageSpinner } from "@/components/ui/page-spinner"; | 31 | import { PageSpinner } from "@/components/ui/page-spinner"; |
| 32 | import { SectionDisclosure } from "@/components/ui/section-disclosure"; | 32 | import { SectionDisclosure } from "@/components/ui/section-disclosure"; |
| 33 | import { SidePanel } from "@/components/ui/side-panel"; | 33 | import { SidePanel } from "@/components/ui/side-panel"; |
| @@ -85,6 +85,7 @@ function ExamDetailContent() { | |||
| 85 | const [removeUserId, setRemoveUserId] = createSignal<string | null>(null); | 85 | const [removeUserId, setRemoveUserId] = createSignal<string | null>(null); |
| 86 | const [sheetUserId, setSheetUserId] = createSignal<string | null>(null); | 86 | const [sheetUserId, setSheetUserId] = createSignal<string | null>(null); |
| 87 | const [gradeOpen, setGradeOpen] = createSignal(false); | 87 | const [gradeOpen, setGradeOpen] = createSignal(false); |
| 88 | + const [questionCreateOpen, setQuestionCreateOpen] = createSignal(false); | ||
| 88 | const [openSections, setOpenSections] = createSignal({ | 89 | const [openSections, setOpenSections] = createSignal({ |
| 89 | schedule: false, | 90 | schedule: false, |
| 90 | ownResult: false, | 91 | ownResult: false, |
| @@ -503,9 +504,27 @@ function ExamDetailContent() { | |||
| 503 | onToggle={() => toggleSection("questions")} | 504 | onToggle={() => toggleSection("questions")} |
| 504 | title={t("questions.title")} | 505 | title={t("questions.title")} |
| 505 | description={t("exams.examQuestions")} | 506 | description={t("exams.examQuestions")} |
| 507 | + actions={ | ||
| 508 | + <Show when={hasCourseManagementRights() && !isFinished()}> | ||
| 509 | + <Button | ||
| 510 | + type="button" | ||
| 511 | + variant="outline" | ||
| 512 | + size="sm" | ||
| 513 | + class="rounded-lg" | ||
| 514 | + onClick={(event) => { | ||
| 515 | + event.stopPropagation(); | ||
| 516 | + setOpenSections((current) => ({ ...current, questions: true })); | ||
| 517 | + setQuestionCreateOpen(true); | ||
| 518 | + }} | ||
| 519 | + > | ||
| 520 | + <IconPlus class="h-4 w-4" /> | ||
| 521 | + {t("questions.add")} | ||
| 522 | + </Button> | ||
| 523 | + </Show> | ||
| 524 | + } | ||
| 506 | > | 525 | > |
| 507 | <Show when={openSections().questions}> | 526 | <Show when={openSections().questions}> |
| 508 | - <ExamQuestionsPanel examId={id()} courseId={ex().course} readOnly={isFinished() || isUpcoming()} embedded /> | 527 | + <ExamQuestionsPanel examId={id()} courseId={ex().course} readOnly={isFinished()} embedded createOpen={questionCreateOpen()} onCreateOpenChange={setQuestionCreateOpen} /> |
| 509 | </Show> | 528 | </Show> |
| 510 | </SectionDisclosure> | 529 | </SectionDisclosure> |
| 511 | 530 | ||