Skip to content

Commit

Permalink
fix: use client component of note home page
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Jan 14, 2024
1 parent 93a4f23 commit fde1bca
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions src/app/(app)/notes/page.tsx
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 />
}

1 comment on commit fde1bca

@vercel
Copy link

@vercel vercel bot commented on fde1bca Jan 14, 2024

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

Please sign in to comment.