From 931b605ba2af9e81f11601e1aef12fea7d9096ba Mon Sep 17 00:00:00 2001 From: Still Date: Thu, 2 Jan 2025 12:55:25 -0500 Subject: [PATCH] allows storing data for later recall --- src/components/QR/QRModal.tsx | 54 +++++++++++++++++++++++++++++------ src/store/store.ts | 34 ++++++++++++++++++++++ 2 files changed, 80 insertions(+), 8 deletions(-) diff --git a/src/components/QR/QRModal.tsx b/src/components/QR/QRModal.tsx index a11603b..2f0546f 100644 --- a/src/components/QR/QRModal.tsx +++ b/src/components/QR/QRModal.tsx @@ -1,7 +1,7 @@ import { Copy, QrCode } from 'lucide-react'; import { QRCodeSVG } from 'qrcode.react'; -import { useMemo } from 'react'; -import { getFieldValue, useQRScoutState } from '../../store/store'; +import { useMemo, useState } from 'react'; +import { getFieldValue, useQRScoutState, clearSaveData, } from '../../store/store'; import { Button } from '../ui/button'; import { Dialog, @@ -9,8 +9,10 @@ import { DialogFooter, DialogTitle, DialogTrigger, + DialogClose } from '../ui/dialog'; import { PreviewText } from './PreviewText'; +import { useSaveState, saveData } from '../../store/store'; export interface QRModalProps { disabled?: boolean; @@ -23,19 +25,42 @@ export function QRModal(props: QRModalProps) { 'matchNumber', )}`.toUpperCase(); - const qrCodeData = useMemo( - () => fieldValues.map(f => f.value).join(','), - [fieldValues], - ); +const [stored, isStored] = useSaveState(state => [state.saveData, state.isSaveData]); + const [index, setCodeIndex] = useState(0); + + const currentFormData = fieldValues.map(f => f.value).join(',') + if (index >= stored.length && index > 0){ + setCodeIndex(0) + } + const qrCodeData = stored[index] return ( + - + + {title} @@ -47,6 +72,19 @@ export function QRModal(props: QRModalProps) { + + +