diff --git a/.eslintrc.json b/.eslintrc.json index db32bb9..0eaa879 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -4,7 +4,7 @@ "import/no-relative-parent-imports": [ "error", { - "ignore": ["@/app", "@/components", "@/lib"] + "ignore": ["@/app", "@/components", "@/lib", "@/fuse", "@/types"] } ] } diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..d067910 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "typescript.tsdk": "node_modules/typescript/lib", + "typescript.enablePromptUseWorkspaceTsdk": true +} \ No newline at end of file diff --git a/app/(stories)/item/[id]/page.tsx b/app/(stories)/item/[id]/page.tsx index ed584b3..3d9f396 100644 --- a/app/(stories)/item/[id]/page.tsx +++ b/app/(stories)/item/[id]/page.tsx @@ -8,6 +8,8 @@ import { Suspense } from "react"; import { Comments } from "@/components/comments"; import { ReplyForm } from "./reply-form"; import Link from "next/link"; +import { graphql } from "@/fuse"; +import { execute } from "@/fuse/server"; export const metadata = { openGraph: { @@ -23,30 +25,22 @@ export const metadata = { }, }; -const getStory = async function getStory(idParam: string) { - const id = `story_${idParam}`; - return ( - await db - .select({ - id: storiesTable.id, - title: storiesTable.title, - domain: storiesTable.domain, - url: storiesTable.url, - username: storiesTable.username, - points: storiesTable.points, - submitted_by: usersTable.username, - comments_count: storiesTable.comments_count, - created_at: storiesTable.created_at, - }) - .from(storiesTable) - .where(sql`${storiesTable.id} = ${id}`) - .limit(1) - .leftJoin( - usersTable, - sql`${usersTable.id} = ${storiesTable.submitted_by}` - ) - )[0]; -}; +const GET_STORY_QUERY = graphql(` + query getStory($id: ID!) { + story(id: $id) { + id + title + url + domain + points + comments_count + created_at + submitter { + username + } + } + } +`) /** * This code was generated by v0 by Vercel. @@ -61,13 +55,17 @@ export default async function ItemPage({ const rid = headers().get("x-vercel-id") ?? nanoid(); console.time(`fetch story ${idParam} (req: ${rid})`); - const story = await getStory(idParam); + + const { data, errors } = await execute({ query: GET_STORY_QUERY, variables: { id: idParam } }) + console.timeEnd(`fetch story ${idParam} (req: ${rid})`); - if (!story) { + if (!data?.story) { notFound(); } + const { story } = data; + const now = Date.now(); return (
{story.points} point{story.points > 1 ? "s" : ""} by{" "}
- {story.submitted_by ?? story.username}{" "}
-
{story.points} point{story.points > 1 ? "s" : ""} by{" "}
- {story.submitted_by ?? story.username}{" "}
-