Skip to content

Commit 69657a3

Browse files
committed
add qr-code to assignments and fix flashing with slider
1 parent 1cdf215 commit 69657a3

File tree

4 files changed

+158
-15
lines changed

4 files changed

+158
-15
lines changed

apps/web/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"lucide-react": "^0.507.0",
4747
"motion": "catalog:",
4848
"papaparse": "workspace:papaparse__5.x@*",
49+
"qrcode": "^1.5.4",
4950
"react": "workspace:react__19.x@*",
5051
"react-dom": "workspace:react-dom__19.x@*",
5152
"recharts": "^2.15.2",
@@ -65,6 +66,7 @@
6566
"@tanstack/router-plugin": "^1.127.3",
6667
"@testing-library/dom": "^10.4.0",
6768
"@testing-library/react": "16.2.0",
69+
"@types/qrcode": "^1.5.6",
6870
"@vitejs/plugin-react-swc": "^3.9.0",
6971
"happy-dom": "catalog:",
7072
"tailwindcss": "catalog:",

apps/web/src/components/QRCode.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { useEffect, useRef } from 'react';
2+
3+
import { useTheme } from '@douglasneuroinformatics/libui/hooks';
4+
import qrcode from 'qrcode';
5+
6+
export const QRCode = ({ url }: { url: string }) => {
7+
const ref = useRef<HTMLCanvasElement>(null);
8+
9+
const [theme] = useTheme();
10+
11+
useEffect(() => {
12+
qrcode.toCanvas(
13+
ref.current,
14+
url,
15+
{
16+
color: {
17+
dark: theme === 'dark' ? '#f1f5f9' : '#0f172a',
18+
light: '#0000'
19+
},
20+
margin: 2,
21+
scale: 6
22+
},
23+
(error) => {
24+
if (error) {
25+
console.error(error);
26+
}
27+
}
28+
);
29+
}, [theme, url]);
30+
31+
return <canvas className="rounded-md border" ref={ref} />;
32+
};

apps/web/src/routes/_app/datahub/$subjectId/assignments.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import type { UnilingualInstrumentInfo } from '@opendatacapture/schemas/instrume
2121
import { createFileRoute } from '@tanstack/react-router';
2222
import { z } from 'zod/v4';
2323

24+
import { QRCode } from '@/components/QRCode';
2425
import { useAssignmentsQuery } from '@/hooks/useAssignmentsQuery';
2526
import { useCreateAssignment } from '@/hooks/useCreateAssignment';
2627
import { useInstrument } from '@/hooks/useInstrument';
@@ -40,26 +41,25 @@ const AssignmentSlider: React.FC<{
4041
const instrument = useInstrument(assignment?.instrumentId ?? null);
4142

4243
return (
43-
<Sheet open={isOpen} onOpenChange={setIsOpen}>
44+
<Sheet open={Boolean(isOpen && assignment && instrument)} onOpenChange={setIsOpen}>
4445
<Sheet.Content className="flex h-full flex-col">
4546
<Sheet.Header>
4647
<Sheet.Title>{instrument?.details.title}</Sheet.Title>
4748
<Sheet.Description>{t('datahub.assignments.assignmentSliderDesc')}</Sheet.Description>
4849
</Sheet.Header>
4950
<Sheet.Body className="grow">
50-
{instrument && (
51-
<div className="flex flex-col gap-3">
52-
<Label asChild>
53-
<a className="hover:underline" href={assignment!.url} rel="noreferrer" target="_blank">
54-
{t('datahub.assignments.link')}
55-
</a>
56-
</Label>
57-
<div className="flex gap-2">
58-
<Input readOnly className="h-9" id="link" value={assignment!.url} />
59-
<CopyButton size="sm" text={assignment!.url} variant="outline" />
60-
</div>
51+
<div className="flex flex-col gap-3">
52+
<Label asChild>
53+
<a className="hover:underline" href={assignment?.url} rel="noreferrer" target="_blank">
54+
{t('datahub.assignments.link')}
55+
</a>
56+
</Label>
57+
<div className="flex gap-2">
58+
<Input readOnly className="h-9" id="link" value={assignment?.url} />
59+
<CopyButton size="sm" text={assignment?.url ?? ''} variant="outline" />
6160
</div>
62-
)}
61+
<QRCode url={assignment?.url ?? 'javascript:void(0)'} />
62+
</div>
6363
</Sheet.Body>
6464
<Sheet.Footer>
6565
<Button

pnpm-lock.yaml

Lines changed: 111 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)