From 6d975947a9135bb873b7c521234f2fa34baab1f7 Mon Sep 17 00:00:00 2001 From: ARYPROGRAMMER Date: Sun, 22 Dec 2024 00:00:56 +0530 Subject: [PATCH] feat: snippet details added --- convex/snippets.ts | 22 ++++++++++++++++ .../_components/SnippetDetailPageSkeleton.tsx | 9 +++++++ src/app/snippets/[id]/page.tsx | 25 +++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 src/app/snippets/[id]/_components/SnippetDetailPageSkeleton.tsx create mode 100644 src/app/snippets/[id]/page.tsx diff --git a/convex/snippets.ts b/convex/snippets.ts index b48f588..2766272 100644 --- a/convex/snippets.ts +++ b/convex/snippets.ts @@ -70,7 +70,29 @@ export const getSnippetStarCount = query({ } }) +export const getSnippetById = query({ + args: { snippetId: v.id("snippets") }, + handler: async (ctx, args) => { + const snippet = await ctx.db.get(args.snippetId); + if (!snippet) throw new Error("Snippet not found"); + + return snippet; + }, +}); +export const getComments = query({ + args: { snippetId: v.id("snippets") }, + handler: async (ctx, args) => { + const comments = await ctx.db + .query("snippetComments") + .withIndex("by_snippet_id") + .filter((q) => q.eq(q.field("snippetId"), args.snippetId)) + .order("desc") + .collect(); + + return comments; + }, +}); export const deleteSnippet = mutation({ args: { diff --git a/src/app/snippets/[id]/_components/SnippetDetailPageSkeleton.tsx b/src/app/snippets/[id]/_components/SnippetDetailPageSkeleton.tsx new file mode 100644 index 0000000..e223d64 --- /dev/null +++ b/src/app/snippets/[id]/_components/SnippetDetailPageSkeleton.tsx @@ -0,0 +1,9 @@ +import React from 'react' + +function SnippetDetailPageSkeleton() { + return ( +
SnippetDetailPageSkeleton
+ ) +} + +export default SnippetDetailPageSkeleton \ No newline at end of file diff --git a/src/app/snippets/[id]/page.tsx b/src/app/snippets/[id]/page.tsx new file mode 100644 index 0000000..49a3f31 --- /dev/null +++ b/src/app/snippets/[id]/page.tsx @@ -0,0 +1,25 @@ +"use client"; + +import { useQuery } from 'convex/react'; +import { useParams } from 'next/navigation'; +import React from 'react' +import { api } from '../../../../convex/_generated/api'; +import { Id } from '../../../../convex/_generated/dataModel'; +import SnippetDetailPageSkeleton from './_components/SnippetDetailPageSkeleton'; + +function SnippetDetailPage() { + const snippetId = useParams().id; + + const snippet = useQuery(api.snippets.getSnippetById, { snippetId : snippetId as Id<"snippets"> }); + + if (snippet === undefined) { + return ; + } + + + return ( +
SnippetDetailPage
+ ) +} + +export default SnippetDetailPage \ No newline at end of file