File tree 1 file changed +26
-17
lines changed
1 file changed +26
-17
lines changed Original file line number Diff line number Diff line change 1
- import type { NoteWrappedPayload } from '@mx-space/api- client'
1
+ 'use client'
2
2
3
- import { NotFound404 } from '~/components/common/404'
4
- import { apiClient } from '~/lib/request'
3
+ import { useQuery } from '@tanstack/react-query'
4
+ import { useEffect } from 'react'
5
+ import { useRouter } from 'next/navigation'
5
6
6
- import Redirect from './redirect'
7
+ import { FullPageLoading } from '~/components/ui/loading'
8
+ import { apiClient } from '~/lib/request'
7
9
8
- export default async function Page ( ) {
9
- const data = await fetch ( apiClient . note . proxy . latest . toString ( true ) , {
10
- next : {
11
- revalidate : 60 * 60 ,
12
- tags : [ 'note' ] ,
10
+ export default function Page ( ) {
11
+ const {
12
+ data : nid ,
13
+ isError,
14
+ isLoading,
15
+ } = useQuery ( {
16
+ queryFn : async ( ) => {
17
+ return apiClient . note . getLatest ( )
18
+ } ,
19
+ queryKey : [ 'note-latest' ] ,
20
+ select ( data ) {
21
+ return data . data . nid
13
22
} ,
14
23
} )
15
- . then ( ( res ) => res . json ( ) as Promise < NoteWrappedPayload > )
16
- . catch ( ( ) => {
17
- return null
18
- } )
19
24
20
- if ( ! data || ! data . data ) {
21
- return < NotFound404 />
22
- }
23
- return < Redirect nid = { data . data ?. nid } />
25
+ const router = useRouter ( )
26
+ useEffect ( ( ) => {
27
+ if ( ! nid ) return
28
+
29
+ router . replace ( `/notes/${ nid } ` )
30
+ } , [ nid , router ] )
31
+
32
+ return < FullPageLoading />
24
33
}
You can’t perform that action at this time.
0 commit comments