fix: routing, removed useEffect

This commit is contained in:
Stixx 2024-09-11 11:59:12 +02:00
parent 75a715d002
commit 8e71592d88
3 changed files with 24 additions and 47 deletions

View File

@ -50,7 +50,6 @@ export const DisplaySigit = ({ meta, parsedMeta, sigitKey }: SigitProps) => {
? appPublicRoutes.verify ? appPublicRoutes.verify
: `${appPrivateRoutes.sign}/${sigitKey}` : `${appPrivateRoutes.sign}/${sigitKey}`
} }
state={{ meta }}
className={styles.insetLink} className={styles.insetLink}
></Link> ></Link>
<p className={`line-clamp-2 ${styles.title}`}>{title}</p> <p className={`line-clamp-2 ${styles.title}`}>{title}</p>

View File

@ -65,6 +65,8 @@ export const SignPage = () => {
const location = useLocation() const location = useLocation()
const params = useParams() const params = useParams()
const usersAppData = useAppSelector((state) => state.userAppData)
/** /**
* Received from `location.state` * Received from `location.state`
* *
@ -72,11 +74,27 @@ export const SignPage = () => {
* arrayBuffer will be received in navigation from create page in offline mode * arrayBuffer will be received in navigation from create page in offline mode
* meta will be received in navigation from create & home page in online mode * meta will be received in navigation from create & home page in online mode
*/ */
const [metaInNavState, setMetaInNavState] = useState<Meta | undefined>() const {
const [decryptedArrayBuffer, setDecryptedArrayBuffer] = useState< meta: metaInNavState,
ArrayBuffer | undefined arrayBuffer: decryptedArrayBuffer,
>() uploadedZip
const [uploadedZip, setUploadedZip] = useState<File | undefined>() } = location.state || {
meta: undefined,
arrayBuffer: undefined,
uploadedZip: undefined
}
if (usersAppData) {
const sigitId = params.id
if (sigitId) {
const sigit = usersAppData.sigits[sigitId]
if (sigit) {
metaInNavState = sigit
}
}
}
const [displayInput, setDisplayInput] = useState(false) const [displayInput, setDisplayInput] = useState(false)
@ -119,41 +137,6 @@ export const SignPage = () => {
const [isMarksCompleted, setIsMarksCompleted] = useState(false) const [isMarksCompleted, setIsMarksCompleted] = useState(false)
const [otherUserMarks, setOtherUserMarks] = useState<Mark[]>([]) const [otherUserMarks, setOtherUserMarks] = useState<Mark[]>([])
const usersAppData = useAppSelector((state) => state.userAppData)
/**
* When location state changes, update the states in the component
* If sigit id is found in the URL PARAM we will set metaInNavState manually
* after we do the fetching based on the ID
*/
useEffect(() => {
if (location.state) {
const { meta, arrayBuffer, uploadedZip } = location.state
setMetaInNavState(meta)
setDecryptedArrayBuffer(arrayBuffer)
setUploadedZip(uploadedZip)
}
}, [location.state])
useEffect(() => {
// If meta in nav state is populated we will not try to fetch sigit details
// from the redux store
if (metaInNavState) return
if (usersAppData) {
const sigitId = params.id
if (sigitId) {
const sigit = usersAppData.sigits[sigitId]
if (sigit) {
setMetaInNavState(sigit)
}
}
}
}, [usersAppData, metaInNavState, params.id])
useEffect(() => { useEffect(() => {
if (signers.length > 0) { if (signers.length > 0) {
// check if all signers have signed then its fully signed // check if all signers have signed then its fully signed

View File

@ -19,7 +19,6 @@ export const appPrivateRoutes = {
homePage: '/', homePage: '/',
create: '/create', create: '/create',
sign: '/sign', sign: '/sign',
signId: '/sign/:id',
settings: '/settings', settings: '/settings',
profileSettings: '/settings/profile/:npub', profileSettings: '/settings/profile/:npub',
cacheSettings: '/settings/cache', cacheSettings: '/settings/cache',
@ -130,11 +129,7 @@ export const privateRoutes = [
element: <CreatePage /> element: <CreatePage />
}, },
{ {
path: appPrivateRoutes.sign, path: `${appPrivateRoutes.sign}/:id?`,
element: <SignPage />
},
{
path: appPrivateRoutes.signId,
element: <SignPage /> element: <SignPage />
}, },
{ {