Skip to content

Commit 4877877

Browse files
Merge pull request #17 from ARYPROGRAMMER/develop/home
feat: snippet details added
2 parents 9542f58 + 6d97594 commit 4877877

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

convex/snippets.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,29 @@ export const getSnippetStarCount = query({
7070
}
7171
})
7272

73+
export const getSnippetById = query({
74+
args: { snippetId: v.id("snippets") },
75+
handler: async (ctx, args) => {
76+
const snippet = await ctx.db.get(args.snippetId);
77+
if (!snippet) throw new Error("Snippet not found");
78+
79+
return snippet;
80+
},
81+
});
7382

83+
export const getComments = query({
84+
args: { snippetId: v.id("snippets") },
85+
handler: async (ctx, args) => {
86+
const comments = await ctx.db
87+
.query("snippetComments")
88+
.withIndex("by_snippet_id")
89+
.filter((q) => q.eq(q.field("snippetId"), args.snippetId))
90+
.order("desc")
91+
.collect();
92+
93+
return comments;
94+
},
95+
});
7496

7597
export const deleteSnippet = mutation({
7698
args: {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react'
2+
3+
function SnippetDetailPageSkeleton() {
4+
return (
5+
<div>SnippetDetailPageSkeleton</div>
6+
)
7+
}
8+
9+
export default SnippetDetailPageSkeleton

src/app/snippets/[id]/page.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"use client";
2+
3+
import { useQuery } from 'convex/react';
4+
import { useParams } from 'next/navigation';
5+
import React from 'react'
6+
import { api } from '../../../../convex/_generated/api';
7+
import { Id } from '../../../../convex/_generated/dataModel';
8+
import SnippetDetailPageSkeleton from './_components/SnippetDetailPageSkeleton';
9+
10+
function SnippetDetailPage() {
11+
const snippetId = useParams().id;
12+
13+
const snippet = useQuery(api.snippets.getSnippetById, { snippetId : snippetId as Id<"snippets"> });
14+
15+
if (snippet === undefined) {
16+
return <SnippetDetailPageSkeleton />;
17+
}
18+
19+
20+
return (
21+
<div>SnippetDetailPage</div>
22+
)
23+
}
24+
25+
export default SnippetDetailPage

0 commit comments

Comments
 (0)