Something went wrong. Try again.
Synapse is a study workspace. Organize courses read and annotate the material, train with generated exercises and watch your progress forked from denishovart.com/synapse
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150<script lang="ts"> import { Dumbbell, FileDown, RotateCcw, Settings, Timer } from 'lucide-svelte'; import { Button, ButtonGroup, Icon, confirm, confirmChoice, reportOutcome, toast, whileRunning, } from '@design-system'; import * as progressRepo from '@web/lib/data/repos/progress'; import { exportCoursePdf } from '@web/pages/course/workspaceExport'; import { saveFile } from '@web/lib/documents/savePack'; import { daysUntil, fmtDate } from '@web/lib/format'; import type { CourseDetail } from '@web/lib/types'; import { m } from '@web/paraglide/messages'; import { href } from '@web/app/router';
interface Props { course: CourseDetail; courseId: string; /** Called after the progress reset so the page can reload. */ onChanged: () => void; } const { course, courseId, onChanged }: Props = $props();
let exporting = $state(false); async function exportPdf() { // Let the user choose what travels into the PDF before building it. const choice = await confirmChoice(m.course_pdf_export_title(), { confirmLabel: m.course_pdf_export_confirm(), checkboxes: [ { key: 'annotations', label: m.course_pdf_opt_annotations(), checked: true }, { key: 'pageNotes', label: m.course_pdf_opt_page_notes(), checked: false }, ], }); if (!choice.ok) return;
exporting = true; await whileRunning(m.course_pdf_exporting(), async () => { const built = await exportCoursePdf(courseId, { annotations: choice.choices.annotations, pageNotes: choice.choices.pageNotes, }); await built.match( async (bytes) => { const res = await saveFile( new Blob([bytes.slice()], { type: 'application/pdf' }), `${course.name}.pdf`, { name: 'PDF', ext: 'pdf' }, ); reportOutcome( res.saved ? m.course_pdf_exported({ name: res.name }) : { outcome: 'cancelled', text: m.common_cancelled() }, ); }, async (e) => toast(m.common_error({ message: e.message }), 'error'), ); }); exporting = false; }
const examLabel = $derived.by(() => { if (!course.exam_date) return ''; const days = daysUntil(course.exam_date); return days !== null && days >= 0 ? m.course_exam_in_days({ date: fmtDate(course.exam_date), days }) : m.course_exam_past({ date: fmtDate(course.exam_date) }); });
async function resetProgress() { if (!(await confirm(m.course_confirm_reset_progress(), { tone: 'danger' }))) return; (await progressRepo.resetCourse(courseId)).match( () => { toast(m.course_progress_reset_done(), 'success'); onChanged(); }, (e) => toast(e.message, 'error'), ); }</script>
<div class="course-head"> <!-- Skip the exam line when there is no date, so the code stays centered. --> <div> <div class="meta">{course.code}</div> {#if examLabel}<div class="meta">{examLabel}</div>{/if} </div> <!-- The actions grouped into one segmented toolbar so they read as a single control and stay compact on a phone (the group scrolls if it must). Each keeps its colour: Training is primary, reset is danger. Navigations are links (the router soft-intercepts them), only the reset mutates state. Training/exam appear once exercises exist, reset once there's progress. --> <ButtonGroup label={m.course_section_actions()}> {#if course.exercises_count > 0} <a class="btn primary" href={href('exercises', { query: { course: courseId, mode: 'practice' } })} > <Icon icon={Dumbbell} size={14} /> {m.course_btn_training()} </a> <a class="btn" href={href('exercises', { query: { course: courseId, mode: 'mock_exam' } })}> <Icon icon={Timer} size={14} /> {m.course_btn_mock_exam()} </a> {/if} {#if course.documents.length > 0} <Button onclick={exportPdf} disabled={exporting} title={m.course_btn_export_pdf_hint()}> <Icon icon={FileDown} size={14} /> {m.course_btn_export_pdf()} </Button> {/if} {#if course.attempts_count > 0} <Button variant="danger" onclick={resetProgress}> <Icon icon={RotateCcw} size={14} /> {m.course_btn_reset_progress()} </Button> {/if} <a class="btn icon-only" href={href('courseSettings', { params: { id: courseId } })} title={m.course_settings_link()} aria-label={m.course_settings_link()} > <Icon icon={Settings} size={16} /> </a> </ButtonGroup></div>
<style> .course-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; } /* Settings is the icon-only end cap of the group. Keep the base button's vertical padding so its height matches the labelled segments, and pad it symmetrically so the gear sits centered whether or not it has neighbours. */ .course-head :global(.btn.icon-only) { padding-left: var(--space-sm); padding-right: var(--space-sm); }</style>