Add Sigit ID as a path param #195

Merged
b merged 12 commits from issue-171 into staging 2024-10-07 09:16:30 +00:00
3 changed files with 24 additions and 47 deletions
Showing only changes of commit 8e71592d88 - Show all commits

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
m marked this conversation as resolved Outdated
Outdated
Review

We should just replace the value of metaInNavState without having states.
We can just move it out of the destructuring and modify it if needed? Something like?

  const { arrayBuffer: decryptedArrayBuffer, uploadedZip } = location.state

  let metaInNavState = location.state.meta
  if (usersAppData) {
    const sigitId = params.id

    if (sigitId) {
      metaInNavState = usersAppData.sigits[sigitId]
    }
  }
We should just replace the value of `metaInNavState` without having states. We can just move it out of the destructuring and modify it if needed? Something like? ``` const { arrayBuffer: decryptedArrayBuffer, uploadedZip } = location.state let metaInNavState = location.state.meta if (usersAppData) { const sigitId = params.id if (sigitId) { metaInNavState = usersAppData.sigits[sigitId] } } ```
*/ */
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
m marked this conversation as resolved Outdated
Outdated
Review

sigit id - what is this? should be defined

sigit id - what is this? should be defined
}
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',
m marked this conversation as resolved
Review

Can we use optional segment? Instead of two routes /sign and /sign/:id we can combine it into /sign/:id? .

Can we use optional segment? Instead of two routes `/sign` and `/sign/:id` we can combine it into `/sign/:id?` .
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 />
}, },
{ {