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 ( +