Update bookmarks to be fetched on render

master
TZGyn 2 years ago
parent 9e17924867
commit 1c3e2c169b
Signed by: TZGyn
GPG Key ID: 122EAF77AE81FD4A

@ -1,2 +1 @@
NEXT_APP_URL=https://next-dashboard.tzgyn.com
DATABASE_URL=postgres://postgres:password@127.0.0.1:5432/next-dashboard DATABASE_URL=postgres://postgres:password@127.0.0.1:5432/next-dashboard

@ -2,8 +2,6 @@ import { bookmarkSchema } from '@/types'
import { NextRequest, NextResponse } from 'next/server' import { NextRequest, NextResponse } from 'next/server'
import { db, bookmark } from '@/lib/schema' import { db, bookmark } from '@/lib/schema'
export const dynamic = 'force-dynamic'
export const GET = async () => { export const GET = async () => {
const bookmarks = await db.select().from(bookmark) const bookmarks = await db.select().from(bookmark)

@ -1,24 +1,19 @@
import { BookmarkCard } from '@/components/bookmarkCard' import { BookmarkCard } from '@/components/bookmarkCard'
import { bookmarkSchema } from '@/types' import { bookmarkSchema } from '@/types'
import { db, bookmark } from '@/lib/schema'
const getData = async () => { export const dynamic = 'force-dynamic'
const res = await fetch(process.env.NEXT_APP_URL + '/api/bookmark', { export const fetchCache = 'force-no-store'
method: 'GET',
cache: 'no-store',
})
const data = await res.json()
return bookmarkSchema.array().parse(data)
}
export default async function DashboardPage() { export default async function DashboardPage() {
const data = await getData() const data = await db.select().from(bookmark)
const bookmarks = bookmarkSchema.array().parse(data)
return ( return (
<div className='mt-4 flex w-full max-w-4xl flex-row flex-wrap justify-center gap-6'> <div className='mt-4 flex w-full max-w-4xl flex-row flex-wrap justify-center gap-6'>
{data.map((data, index) => ( {bookmarks.map((data, index) => (
<BookmarkCard <BookmarkCard
index={index} key={index}
data={data} data={data}
/> />
))} ))}

@ -7,18 +7,11 @@ import { Image } from '@nextui-org/image'
import { type Bookmark } from '@/types' import { type Bookmark } from '@/types'
export const BookmarkCard = ({ export const BookmarkCard = ({ data }: { data: Bookmark }) => {
index,
data,
}: {
index: number
data: Bookmark
}) => {
return ( return (
<> <>
<Card <Card
className='w-96' className='w-96'
key={index}
isPressable isPressable
onPress={() => open(data.url, '_blank')}> onPress={() => open(data.url, '_blank')}>
<CardHeader className='flex gap-3'> <CardHeader className='flex gap-3'>

Loading…
Cancel
Save