-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
42b58d6
commit 26370ea
Showing
11 changed files
with
413 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Card, Container, Stack, Typography } from "@mui/material"; | ||
import { Box } from "@mui/system"; | ||
import { Metadata } from "next"; | ||
import React from "react"; | ||
|
||
import PublicBlidSearch from "@/components/search/PublicBlidSearch"; | ||
|
||
export const metadata: Metadata = { | ||
title: "Boksøk", | ||
description: "Sjekk hvem bøker utdelt fra Boklisten tilhører", | ||
}; | ||
|
||
export default function PublicBlidSearchPage() { | ||
return ( | ||
<Card sx={{ paddingBottom: 4 }}> | ||
<Container component="main" maxWidth="xs"> | ||
<Stack alignItems={"center"} mt={4}> | ||
<Typography variant="h1">Boksøk</Typography> | ||
<Box width="100%"> | ||
<PublicBlidSearch /> | ||
</Box> | ||
</Stack> | ||
</Container> | ||
</Card> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Box } from "@mui/material"; | ||
import Typography from "@mui/material/Typography"; | ||
import React, { useEffect } from "react"; | ||
|
||
import { ItemStatus } from "@/components/matches/matches-helper"; | ||
import ProgressBar from "@/components/matches/matchesList/ProgressBar"; | ||
import MatchItemTable from "@/components/matches/MatchItemTable"; | ||
|
||
export default function MatchScannerContent({ | ||
expectedItems, | ||
fulfilledItems, | ||
itemStatuses, | ||
scannerOpen, | ||
handleClose, | ||
}: { | ||
itemStatuses: ItemStatus[]; | ||
expectedItems: string[]; | ||
fulfilledItems: string[]; | ||
scannerOpen: boolean; | ||
handleClose: () => void; | ||
}) { | ||
useEffect(() => { | ||
if (scannerOpen && expectedItems.length === fulfilledItems.length) { | ||
handleClose(); | ||
} | ||
}, [expectedItems.length, fulfilledItems.length, handleClose, scannerOpen]); | ||
return ( | ||
<> | ||
<Box width={0.9}> | ||
<ProgressBar | ||
percentComplete={(fulfilledItems.length * 100) / expectedItems.length} | ||
subtitle={ | ||
<Typography textAlign={"center"}> | ||
{fulfilledItems.length} av {expectedItems.length} bøker mottatt | ||
</Typography> | ||
} | ||
/> | ||
</Box> | ||
<Box | ||
sx={{ | ||
overflowY: "auto", | ||
maxHeight: "30rem", | ||
mt: 2, | ||
}} | ||
> | ||
<MatchItemTable itemStatuses={itemStatuses} isSender={false} /> | ||
</Box> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { IDetectedBarcode, Scanner } from "@yudiel/react-qr-scanner"; | ||
|
||
import { ScannedTextType, TextType } from "@/utils/types"; | ||
|
||
export function determineScannedTextType(scannedText: string): ScannedTextType { | ||
if (/^[\dA-Za-z]{12}$|^\d{8}$/.test(scannedText)) { | ||
return TextType.BLID; | ||
} else if (/^\d{13}$/.test(scannedText)) { | ||
return TextType.ISBN; | ||
} | ||
|
||
return TextType.UNKNOWN; | ||
} | ||
|
||
export default function BlidScanner({ | ||
onResult, | ||
}: { | ||
onResult: (scannedText: string) => Promise<void>; | ||
}) { | ||
const handleCodeDetection = async ( | ||
detectedCodes: IDetectedBarcode[], | ||
): Promise<void> => { | ||
const didFindBlid = detectedCodes.some( | ||
(code) => determineScannedTextType(code.rawValue) === TextType.BLID, | ||
); | ||
const codesToProcess = didFindBlid | ||
? detectedCodes.filter( | ||
(code) => determineScannedTextType(code.rawValue) === TextType.BLID, | ||
) | ||
: detectedCodes; | ||
|
||
for (const code of codesToProcess) { | ||
try { | ||
await onResult(code.rawValue); | ||
} catch (error) { | ||
console.error("Failed to handle scan", error); | ||
} | ||
// Arbitrary delay to somewhat avoid races the backend isn't smart enough to handle | ||
await new Promise((resolve) => { | ||
window.setTimeout(resolve, 250); | ||
}); | ||
} | ||
}; | ||
|
||
return ( | ||
<Scanner | ||
constraints={{ facingMode: "environment" }} | ||
formats={["qr_code", "code_128", "ean_8", "ean_13"]} | ||
components={{ torch: true }} | ||
onScan={handleCodeDetection} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.