Skip to content

Commit db0817a

Browse files
authored
feat: add qr code scanner (#386)
1 parent b8590ba commit db0817a

12 files changed

Lines changed: 10180 additions & 5428 deletions

File tree

.github/workflows/PR-CI.yaml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ jobs:
2424
name: Run Prettier Check
2525
runs-on: ubuntu-latest
2626
steps:
27-
- uses: actions/checkout@v3
27+
- name: Checkout
28+
uses: actions/checkout@v4
2829
with:
2930
fetch-depth: 0
30-
- uses: pnpm/action-setup@v2
31-
with:
32-
version: 8
33-
- uses: actions/setup-node@v3
31+
ref: ${{ github.head_ref }}
32+
persist-credentials: false
33+
34+
- name: Prettify code
35+
uses: creyD/prettier_action@v4.6
3436
with:
35-
node-version: 20
36-
- run: pnpm install prettier
37-
- run: pnpm run format:check
37+
dry: true
38+
prettier_options: --check .
39+
github_token: ${{ secrets.GITHUB_TOKEN }}

next-env.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
33
/// <reference types="next/navigation-types/compat/navigation" />
4-
/// <reference path="./.next/types/routes.d.ts" />
54

65
// NOTE: This file should not be edited
76
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"@uppy/progress-bar": "^4.2.1",
4949
"@uppy/react": "^4.4.0",
5050
"@uppy/xhr-upload": "^4.3.3",
51+
"@yudiel/react-qr-scanner": "^2.4.1",
5152
"bootstrap": "^5.3.7",
5253
"bootstrap-icons": "^1.13.1",
5354
"class-variance-authority": "^0.7.1",

pnpm-lock.yaml

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

pnpm-workspace.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
onlyBuiltDependencies:
2+
- sharp
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-- DropTable
2+
DROP TABLE IF EXISTS "EventLog";
3+
4+
-- CreateTable
5+
CREATE TABLE "EventLog" (
6+
"id" STRING NOT NULL,
7+
"userId" STRING NOT NULL,
8+
"timestamp" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
9+
"station" STRING NOT NULL,
10+
"type" STRING NOT NULL,
11+
12+
CONSTRAINT "EventLog_pkey" PRIMARY KEY ("id")
13+
);
14+
15+
-- AddForeignKey
16+
ALTER TABLE "EventLog" ADD CONSTRAINT "EventLog_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

prisma/schema.prisma

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ model EventLog {
8585
userId String
8686
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
8787
timestamp DateTime @default(now())
88-
event String
88+
station String
89+
type String
8990
}
9091

9192
model VerificationToken {

src/hooks/useOfflineQueue.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { useCallback, useEffect, useState } from "react";
2+
3+
const QUEUE_KEY = "offlineQueue";
4+
5+
/**
6+
* Custom hook to manage an offline queue in localStorage
7+
* Handles adding, removing, and retrieving queued items (id + task)
8+
*/
9+
export const useOfflineQueue = <T extends { id: string }>(key = QUEUE_KEY) => {
10+
const [queuedItems, setQueuedItems] = useState<T[]>([]);
11+
12+
// Load queued items from localStorage on mount
13+
useEffect(() => {
14+
try {
15+
const existing = localStorage.getItem(key);
16+
const items: T[] = existing ? JSON.parse(existing) : [];
17+
setQueuedItems(items);
18+
} catch {
19+
setQueuedItems([]);
20+
}
21+
}, [key]);
22+
23+
const addToQueue = useCallback(
24+
(item: T) => {
25+
setQueuedItems((prev) => {
26+
if (prev.some((existing) => existing.id === item.id)) {
27+
return prev;
28+
}
29+
const updated = [...prev, item];
30+
try {
31+
localStorage.setItem(key, JSON.stringify(updated));
32+
} catch {}
33+
return updated;
34+
});
35+
},
36+
[key],
37+
);
38+
39+
const removeFromQueue = useCallback(
40+
(id: string) => {
41+
setQueuedItems((prev) => {
42+
const updated = prev.filter((item) => item.id !== id);
43+
if (updated.length === prev.length) {
44+
return prev;
45+
}
46+
try {
47+
localStorage.setItem(key, JSON.stringify(updated));
48+
} catch {}
49+
return updated;
50+
});
51+
},
52+
[key],
53+
);
54+
55+
return {
56+
queuedItems,
57+
addToQueue,
58+
removeFromQueue,
59+
};
60+
};

0 commit comments

Comments
 (0)