-
Notifications
You must be signed in to change notification settings - Fork 11
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
9341a56
commit 243e6a1
Showing
18 changed files
with
314 additions
and
95 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
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,16 @@ | ||
import { useCallback } from 'react'; | ||
import { Button } from 'react-daisyui'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
export default function ConfigScanButton() { | ||
const navigate = useNavigate(); | ||
const scanConfigAndPersist = useCallback(() => { | ||
navigate('/config/scan'); | ||
}, [navigate]); | ||
|
||
return ( | ||
<Button fullWidth onClick={scanConfigAndPersist} color="primary"> | ||
Scan | ||
</Button> | ||
); | ||
} |
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 { Button } from 'react-daisyui'; | ||
import { ArrowLeft, Icon } from 'react-feather'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { ReactNode } from 'react'; | ||
|
||
interface HeaderProps { | ||
title: string; | ||
Icon?: Icon; | ||
onIconClick: () => void; | ||
back: false; | ||
} | ||
|
||
interface BackHeaderProps { | ||
title: string; | ||
back: true; | ||
} | ||
|
||
interface RawTrail { | ||
trailing?: ReactNode; | ||
} | ||
|
||
export function Header({ | ||
trailing, | ||
title, | ||
back, | ||
...rest | ||
}: RawTrail & (HeaderProps | BackHeaderProps)) { | ||
const nav = useNavigate(); | ||
const { Icon, onIconClick } = rest as HeaderProps; | ||
const navBack = () => { | ||
nav('..'); | ||
}; | ||
return ( | ||
<div className={`flex items-center ${back ? '' : 'justify-between'}`}> | ||
{back && ( | ||
<Button color="ghost" onClick={navBack} shape="circle"> | ||
<ArrowLeft /> | ||
</Button> | ||
)} | ||
<h1 className="text-2xl">{title}</h1> | ||
<div className="mx-auto" /> | ||
{!back && Icon && ( | ||
<Button color="ghost" onClick={onIconClick} shape="circle"> | ||
<Icon /> | ||
</Button> | ||
)} | ||
{trailing} | ||
</div> | ||
); | ||
} |
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 was deleted.
Oops, something went wrong.
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,16 @@ | ||
import { useCallback } from 'react'; | ||
import { Button } from 'react-daisyui'; | ||
import { ArrowRight } from 'react-feather'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
export default function ToListScanButton() { | ||
const navigate = useNavigate(); | ||
const toScans = useCallback(() => navigate('/scans'), [navigate]); | ||
|
||
return ( | ||
<Button fullWidth color="primary" onClick={toScans}> | ||
<span>To Scans</span> | ||
<ArrowRight /> | ||
</Button> | ||
); | ||
} |
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
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,85 @@ | ||
import React, { useState } from 'react'; | ||
import { Header } from '../components/header.tsx'; | ||
import { | ||
IDetectedBarcode, | ||
Scanner, | ||
useDevices, | ||
} from '@yudiel/react-qr-scanner'; | ||
import { Button, Dropdown } from 'react-daisyui'; | ||
import { Camera } from 'react-feather'; | ||
import { setUrlConfig, useAppDispatch } from '../store'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
export const Component: React.FC = () => { | ||
const dispatch = useAppDispatch(); | ||
const navigate = useNavigate(); | ||
const devices = useDevices(); | ||
const [deviceId, setDeviceId] = useState( | ||
devices.length > 0 ? devices[0].deviceId : '' | ||
); | ||
const onScan = (detectedCodes: IDetectedBarcode[]) => { | ||
for (const { rawValue, format } of detectedCodes) { | ||
if (format in ['qr_code', 'rm_qr_code', 'micro_qr_code']) { | ||
const config = JSON.parse(rawValue) as Record<string, string>; | ||
dispatch(setUrlConfig(config.url)); | ||
navigate('..'); | ||
} | ||
} | ||
}; | ||
return ( | ||
<div className="flex flex-col"> | ||
<div className="p-4"> | ||
<Header | ||
title="Configs" | ||
back={true} | ||
trailing={ | ||
<Dropdown horizontal="left"> | ||
<Dropdown.Toggle button={false}> | ||
<Button shape="circle"> | ||
<Camera /> | ||
</Button> | ||
</Dropdown.Toggle> | ||
<Dropdown.Menu className="w-72 z-50"> | ||
{devices.map(({ deviceId, label }) => ( | ||
<Dropdown.Item anchor={false} key={deviceId}> | ||
<button onClick={() => setDeviceId(deviceId)}> | ||
<Camera /> | ||
{label} | ||
</button> | ||
</Dropdown.Item> | ||
))} | ||
</Dropdown.Menu> | ||
</Dropdown> | ||
} | ||
/> | ||
</div> | ||
<div className="bg-primary h-[calc(100vh-80px)]"> | ||
<Scanner | ||
components={{ | ||
audio: false, | ||
finder: false, | ||
tracker: (detectedCodes, ctx) => { | ||
for (const detectedCode of detectedCodes) { | ||
const { cornerPoints } = detectedCode; | ||
ctx.strokeStyle = '#f5f'; | ||
ctx.lineWidth = 4; | ||
ctx.beginPath(); | ||
ctx.moveTo(cornerPoints[0].x, cornerPoints[0].y); | ||
ctx.lineTo(cornerPoints[1].x, cornerPoints[1].y); | ||
ctx.lineTo(cornerPoints[2].x, cornerPoints[2].y); | ||
ctx.lineTo(cornerPoints[3].x, cornerPoints[3].y); | ||
ctx.lineTo(cornerPoints[0].x, cornerPoints[0].y); | ||
ctx.stroke(); | ||
} | ||
}, | ||
}} | ||
classNames={{ video: 'object-cover' }} | ||
onScan={onScan} | ||
constraints={{ | ||
deviceId, | ||
}} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.