Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions convex/snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react'

function SnippetDetailPageSkeleton() {
return (
<div>SnippetDetailPageSkeleton</div>
)
}

export default SnippetDetailPageSkeleton
25 changes: 25 additions & 0 deletions src/app/snippets/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -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 <SnippetDetailPageSkeleton />;
}


return (
<div>SnippetDetailPage</div>
)
}

export default SnippetDetailPage
Loading