-
-
Notifications
You must be signed in to change notification settings - Fork 772
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use client component of note home page
Signed-off-by: Innei <i@innei.in>
- Loading branch information
Showing
1 changed file
with
26 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,33 @@ | ||
import type { NoteWrappedPayload } from '@mx-space/api-client' | ||
'use client' | ||
|
||
import { NotFound404 } from '~/components/common/404' | ||
import { apiClient } from '~/lib/request' | ||
import { useQuery } from '@tanstack/react-query' | ||
import { useEffect } from 'react' | ||
import { useRouter } from 'next/navigation' | ||
|
||
import Redirect from './redirect' | ||
import { FullPageLoading } from '~/components/ui/loading' | ||
import { apiClient } from '~/lib/request' | ||
|
||
export default async function Page() { | ||
const data = await fetch(apiClient.note.proxy.latest.toString(true), { | ||
next: { | ||
revalidate: 60 * 60, | ||
tags: ['note'], | ||
export default function Page() { | ||
const { | ||
data: nid, | ||
isError, | ||
isLoading, | ||
} = useQuery({ | ||
queryFn: async () => { | ||
return apiClient.note.getLatest() | ||
}, | ||
queryKey: ['note-latest'], | ||
select(data) { | ||
return data.data.nid | ||
}, | ||
}) | ||
.then((res) => res.json() as Promise<NoteWrappedPayload>) | ||
.catch(() => { | ||
return null | ||
}) | ||
|
||
if (!data || !data.data) { | ||
return <NotFound404 /> | ||
} | ||
return <Redirect nid={data.data?.nid} /> | ||
const router = useRouter() | ||
useEffect(() => { | ||
if (!nid) return | ||
|
||
router.replace(`/notes/${nid}`) | ||
}, [nid, router]) | ||
|
||
return <FullPageLoading /> | ||
} |
fde1bca
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
shiro – ./
shiro-innei.vercel.app
springtide.vercel.app
shiro-git-main-innei.vercel.app
innei.in