Skip to content

Commit 40fa00f

Browse files
committed
fix: note set current id in error page if 403
Signed-off-by: Innei <[email protected]>
1 parent 119620d commit 40fa00f

File tree

4 files changed

+34
-12
lines changed

4 files changed

+34
-12
lines changed

src/app/notes/error.tsx

+11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
'use client'
22

33
import { useEffect } from 'react'
4+
import { useParams } from 'next/navigation'
45

56
import { captureException } from '@sentry/nextjs'
67

78
import { NotFound404 } from '~/components/common/404'
89
import { NotePasswordForm } from '~/components/widgets/note/NotePasswordForm'
910
import { isRequestError, pickStatusCode } from '~/lib/is-error'
11+
import { setCurrentNoteId } from '~/providers/note/CurrentNoteIdProvider'
1012

1113
import { Paper } from './Paper'
1214

@@ -26,6 +28,7 @@ export default ({ error, reset }: { error: Error; reset: () => void }) => {
2628
return (
2729
<Paper>
2830
<NotePasswordForm />
31+
<NoteSetCurrnetId />
2932
</Paper>
3033
)
3134
}
@@ -60,3 +63,11 @@ export default ({ error, reset }: { error: Error; reset: () => void }) => {
6063
</Paper>
6164
)
6265
}
66+
67+
const NoteSetCurrnetId = () => {
68+
const { id } = useParams()
69+
useEffect(() => {
70+
setCurrentNoteId(id)
71+
}, [id])
72+
return null
73+
}

src/components/ui/transition/typings.ts

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import type {
55
} from 'framer-motion'
66

77
export interface BaseTransitionProps extends HTMLMotionProps<'div'> {
8-
in?: boolean
9-
onExited?: () => void
108
duration?: number
119
onEntered?: () => void
1210
appear?: boolean

src/components/widgets/note/NoteTimeline.tsx

+15-9
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ const NoteTimelineImpl = () => {
3737
created: note.created,
3838
}
3939
})
40+
const noteNid = useCurrentNoteId()
41+
42+
console.log(noteNid, 'noteNid')
4043
const noteId = note?.id
4144

4245
const { data: timelineData } = useQuery(
@@ -52,7 +55,9 @@ const NoteTimelineImpl = () => {
5255
},
5356
)
5457

55-
if (!noteId) return null
58+
if (!timelineData) {
59+
return null
60+
}
5661

5762
const initialData = note
5863
? [
@@ -69,7 +74,7 @@ const NoteTimelineImpl = () => {
6974
<AnimatePresence>
7075
<motion.ul className="space-y-1" animate={animateUl}>
7176
{(timelineData || initialData)?.map((item) => {
72-
const isCurrent = item.nid === note.nid
77+
const isCurrent = item.nid === parseInt(noteNid || '0')
7378
return (
7479
<MemoedItem
7580
key={item.id}
@@ -116,13 +121,14 @@ const MemoedItem = memo<{
116121
animate={animateLi}
117122
exit={initialLi}
118123
>
119-
<LeftToRightTransitionView
120-
in={active}
121-
as="span"
122-
className="inline-flex items-center"
123-
>
124-
<i className="icon-[material-symbols--arrow-circle-right-outline-rounded] duration-200" />
125-
</LeftToRightTransitionView>
124+
{active && (
125+
<LeftToRightTransitionView
126+
as="span"
127+
className="inline-flex items-center"
128+
>
129+
<i className="icon-[material-symbols--arrow-circle-right-outline-rounded] duration-200" />
130+
</LeftToRightTransitionView>
131+
)}
126132
<Link
127133
onClick={springScrollToTop}
128134
prefetch={false}

src/providers/note/CurrentNoteIdProvider.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,11 @@ const useCurrentNoteId = () => {
2929
return useAtomValue(currentNoteIdAtom)
3030
}
3131

32-
export { useCurrentNoteId, CurrentNoteIdProvider }
32+
/**
33+
* Only used in error page to set current note id
34+
*/
35+
const setCurrentNoteId = (noteId: string) => {
36+
jotaiStore.set(currentNoteIdAtom, noteId)
37+
}
38+
39+
export { useCurrentNoteId, CurrentNoteIdProvider, setCurrentNoteId }

0 commit comments

Comments
 (0)