(null);
- const [mode, setMode] = createSignal<"image" | "loading" | "playback" | "plain">("image");
-
- const enterPlayback = async () => {
- if (scene()) {
- setMode("playback");
- return;
- }
- setMode("loading");
- try {
- const blob = await getStudentAnswerImage(props.examId, props.userId, props.questionId);
- const parsed = pngBytesToScene(new Uint8Array(await blob.arrayBuffer()));
- if (parsed && parsed.strokes.length > 0) {
- setScene(parsed);
- setMode("playback");
- } else {
- setMode("plain"); // plain image or no strokes → keep the img, hide Play
- }
- } catch {
- setMode("image"); // fetch failed → keep the img, allow a retry
- }
- };
-
- return (
-
- {/* local boundary: the lazy playback chunk must not suspend the whole answer sheet */}
- }>
- }
- >
- {(s) => }
-
-
-
-
-
-
- );
-}
-
export function AnswerSheetView(props: { examId: string; userId: string }) {
const t = useT();
const [data] = createResource(
@@ -145,7 +83,13 @@ export function AnswerSheetView(props: { examId: string; userId: string }) {
{t("exams.textAnswer")}
{row.answer?.text || "—"}
-
+ getStudentAnswerImage(d().sheet.exam, d().sheet.user.id, row.question.id)}
+ src={`/api/exams/${d().sheet.exam}/attempts/${d().sheet.user.id}/answers/${row.question.id}/image`}
+ alt={t("exams.drawAnswer")}
+ imgClass="h-64 w-full max-w-2xl rounded-md border bg-background object-contain"
+ />
}
diff --git a/src/components/ui/draw-canvas.tsx b/src/components/ui/draw-canvas.tsx
index 6d7530f..134c903 100644
--- a/src/components/ui/draw-canvas.tsx
+++ b/src/components/ui/draw-canvas.tsx
@@ -2,7 +2,7 @@ import { For, Match, Show, Switch, createEffect, createSignal, onCleanup, onMoun
import { Button } from "@/components/ui/button";
import { IconDownload, IconEdit, IconEraser, IconGrid, IconMove, IconRuled, IconSave, IconSquareOff, IconTrash, IconUndo, IconZoomIn, IconZoomOut } from "@/components/ui/icons";
import { cn } from "@/lib/cn";
-import { PAPER_CELL, PAPER_LINE, paintStroke, paintTip, strokesBounds, type BgKind, type DrawScene, type Point, type Stroke } from "@/lib/draw-stroke";
+import { PAPER_CELL, PAPER_LINE, canvasPx, paintStroke, paintTip, strokesBounds, type BgKind, type DrawScene, type Point, type Stroke } from "@/lib/draw-stroke";
import { canvasToImageBlob, sceneToPngFile } from "@/lib/drawing-file";
import { useT } from "@/stores/preferences-context";
@@ -249,14 +249,16 @@ export function DrawCanvas(props: {
const dx = EXPORT_MARGIN - b.x;
const dy = EXPORT_MARGIN - b.y;
const off = document.createElement("canvas");
- off.width = Math.round(w * scale);
- off.height = Math.round(h * scale);
+ off.width = canvasPx(w, scale);
+ off.height = canvasPx(h, scale);
const oc = off.getContext("2d");
if (!oc) return null;
oc.setTransform(scale, 0, 0, scale, dx * scale, dy * scale);
for (const s of list) paintStroke(oc, s);
const shifted = list.map((s) => ({ ...s, points: s.points.map((p) => ({ x: p.x + dx, y: p.y + dy })) }));
- const scene: DrawScene = { v: 1, w, h, strokes: shifted, bg: bg() };
+ // dpr rides along: the PNG is baked at this ratio, so a viewer on a different
+ // display can size the replay to the same pixels instead of its own ratio.
+ const scene: DrawScene = { v: 1, w, h, strokes: shifted, bg: bg(), dpr: scale };
return { canvas: off, scene };
};
diff --git a/src/components/exams/drawing-playback.tsx b/src/components/ui/drawing-playback.tsx
similarity index 82%
rename from src/components/exams/drawing-playback.tsx
rename to src/components/ui/drawing-playback.tsx
index 590eff9..e401e69 100644
--- a/src/components/exams/drawing-playback.tsx
+++ b/src/components/ui/drawing-playback.tsx
@@ -1,7 +1,7 @@
import { createSignal, onCleanup, onMount } from "solid-js";
import { Button } from "@/components/ui/button";
import { cn } from "@/lib/cn";
-import { PAPER_CELL, paintPaper, paintStroke, sliceStrokes, type DrawScene } from "@/lib/draw-stroke";
+import { PAPER_CELL, canvasPx, paintPaper, paintStroke, sliceStrokes, type DrawScene } from "@/lib/draw-stroke";
import { useT } from "@/stores/preferences-context";
// ponytail: synthetic order-only pace — the drawing carries no per-point timing, so
@@ -15,7 +15,7 @@ const POINTS_PER_SECOND = 220;
* transparent layer (erasers cut only ink), then that layer is composited over
* white + paper ruling. No timestamps are read — order + a synthetic pace only.
*/
-export function DrawingPlayback(props: { scene: DrawScene; class?: string }) {
+export function DrawingPlayback(props: { scene: DrawScene; class?: string; canvasClass?: string }) {
const t = useT();
let canvas: HTMLCanvasElement | undefined;
let layer: HTMLCanvasElement | undefined; // offscreen transparent stroke layer (the export's `source`)
@@ -23,8 +23,9 @@ export function DrawingPlayback(props: { scene: DrawScene; class?: string }) {
let startedAt = 0; // performance.now() when the current run began
let baseCount = 0; // points already revealed when the run began (so pause/resume continues)
let revealed = 0;
- // ponytail: DPR snapshotted at mount so the backing store and the paint transform can't
- // drift apart when browser zoom changes mid-run; re-inits on remount (Show image → Play).
+ // The scene's own export DPR when it has one (older scenes fall back to this display's),
+ // so the canvas gets the saved PNG's exact pixels instead of the viewer's ratio. Snapshotted
+ // at mount so backing store and paint transform can't drift apart if zoom changes mid-run.
let scale = 1;
const total = () => props.scene.strokes.reduce((n, s) => n + s.points.length, 0);
@@ -81,9 +82,9 @@ export function DrawingPlayback(props: { scene: DrawScene; class?: string }) {
};
onMount(() => {
- scale = window.devicePixelRatio || 1;
- const w = Math.max(1, Math.round(props.scene.w * scale));
- const h = Math.max(1, Math.round(props.scene.h * scale));
+ scale = props.scene.dpr ?? (window.devicePixelRatio || 1);
+ const w = canvasPx(props.scene.w, scale);
+ const h = canvasPx(props.scene.h, scale);
if (canvas) {
canvas.width = w;
canvas.height = h;
@@ -98,7 +99,8 @@ export function DrawingPlayback(props: { scene: DrawScene; class?: string }) {
return (
-
+ {/* Sized by the caller so the replay matches the static image it replaces. */}
+
+ {/* Draw instead of upload: the pad saves a PNG File, so it rides the same upload. */}
+
setDrawing((open) => !open)}>
+
+ {t("questions.draw")}
+
+
+ }>
+ {
+ setFile(drawn);
+ setDrawing(false);
+ }}
+ />
+
+
diff --git a/src/pages/questions-page.tsx b/src/pages/questions-page.tsx
index a5a73ab..a3b68f0 100644
--- a/src/pages/questions-page.tsx
+++ b/src/pages/questions-page.tsx
@@ -1,4 +1,4 @@
-import { For, Show, Suspense, createResource, createSignal } from "solid-js";
+import { For, Show, Suspense, createResource, createSignal, lazy } from "solid-js";
import { Link, useSearch, useNavigate } from "@tanstack/solid-router";
import { getQuestions, postQuestion } from "@/api/shared";
import { formatApiError } from "@/api/client";
@@ -11,7 +11,7 @@ import { FormDialog } from "@/components/ui/form-dialog";
import { Label } from "@/components/ui/label";
import { Input } from "@/components/ui/input";
import { Textarea } from "@/components/ui/textarea";
-import { IconPlus, IconClock, IconCheck, IconPhoto, IconX } from "@/components/ui/icons";
+import { IconPlus, IconClock, IconCheck, IconPhoto, IconX, IconEdit } from "@/components/ui/icons";
import { personLabel } from "@/lib/person";
import { ErrorAlert } from "@/components/ui/error-alert";
@@ -20,6 +20,9 @@ import { useT } from "@/stores/preferences-context";
import { useAuth } from "@/stores/auth-context";
import { cn } from "@/lib/cn";
+// Lazy so the drawing pad rides its own chunk, off the question list's initial load.
+const DrawCanvas = lazy(() => import("@/components/ui/draw-canvas").then((m) => ({ default: m.DrawCanvas })));
+
export default function QuestionsPage() {
return (
@@ -137,6 +140,7 @@ function AskQuestionDialog(props: { onClose: () => void; onSuccess: () => void }
const [title, setTitle] = createSignal("");
const [body, setBody] = createSignal("");
const [file, setFile] = createSignal(null);
+ const [drawing, setDrawing] = createSignal(false);
const handleSubmit = async (e: Event) => {
e.preventDefault();
@@ -206,6 +210,22 @@ function AskQuestionDialog(props: { onClose: () => void; onSuccess: () => void }
onChange={(e) => setFile(e.currentTarget.files?.[0] || null)}
/>
+ {/* Draw instead of upload: the pad saves a PNG File, so it rides the same upload. */}
+ setDrawing((open) => !open)}>
+
+ {t("questions.draw")}
+
+
+ }>
+ {
+ setFile(drawn);
+ setDrawing(false);
+ }}
+ />
+
+