From 1c3e2c169be529f2c67050061814c0350199e0d6 Mon Sep 17 00:00:00 2001 From: TZGyn Date: Thu, 10 Aug 2023 22:26:28 +0800 Subject: [PATCH] Update bookmarks to be fetched on render --- .env.example | 1 - app/api/bookmark/route.ts | 2 -- app/dashboard/page.tsx | 19 +++++++------------ components/bookmarkCard.tsx | 9 +-------- 4 files changed, 8 insertions(+), 23 deletions(-) diff --git a/.env.example b/.env.example index 3c65834..bf57cdb 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1 @@ -NEXT_APP_URL=https://next-dashboard.tzgyn.com DATABASE_URL=postgres://postgres:password@127.0.0.1:5432/next-dashboard diff --git a/app/api/bookmark/route.ts b/app/api/bookmark/route.ts index 7de3850..a614468 100644 --- a/app/api/bookmark/route.ts +++ b/app/api/bookmark/route.ts @@ -2,8 +2,6 @@ import { bookmarkSchema } from '@/types' import { NextRequest, NextResponse } from 'next/server' import { db, bookmark } from '@/lib/schema' -export const dynamic = 'force-dynamic' - export const GET = async () => { const bookmarks = await db.select().from(bookmark) diff --git a/app/dashboard/page.tsx b/app/dashboard/page.tsx index 6f5e1fd..e4cc869 100644 --- a/app/dashboard/page.tsx +++ b/app/dashboard/page.tsx @@ -1,24 +1,19 @@ import { BookmarkCard } from '@/components/bookmarkCard' import { bookmarkSchema } from '@/types' +import { db, bookmark } from '@/lib/schema' -const getData = async () => { - const res = await fetch(process.env.NEXT_APP_URL + '/api/bookmark', { - method: 'GET', - cache: 'no-store', - }) - const data = await res.json() - - return bookmarkSchema.array().parse(data) -} +export const dynamic = 'force-dynamic' +export const fetchCache = 'force-no-store' export default async function DashboardPage() { - const data = await getData() + const data = await db.select().from(bookmark) + const bookmarks = bookmarkSchema.array().parse(data) return (
- {data.map((data, index) => ( + {bookmarks.map((data, index) => ( ))} diff --git a/components/bookmarkCard.tsx b/components/bookmarkCard.tsx index 539d18f..6d8b9f3 100644 --- a/components/bookmarkCard.tsx +++ b/components/bookmarkCard.tsx @@ -7,18 +7,11 @@ import { Image } from '@nextui-org/image' import { type Bookmark } from '@/types' -export const BookmarkCard = ({ - index, - data, -}: { - index: number - data: Bookmark -}) => { +export const BookmarkCard = ({ data }: { data: Bookmark }) => { return ( <> open(data.url, '_blank')}>