File tree Expand file tree Collapse file tree 3 files changed +56
-0
lines changed Expand file tree Collapse file tree 3 files changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -70,7 +70,29 @@ export const getSnippetStarCount = query({
70
70
}
71
71
} )
72
72
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
+ } ) ;
73
82
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
+ } ) ;
74
96
75
97
export const deleteSnippet = mutation ( {
76
98
args : {
Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+
3
+ function SnippetDetailPageSkeleton ( ) {
4
+ return (
5
+ < div > SnippetDetailPageSkeleton</ div >
6
+ )
7
+ }
8
+
9
+ export default SnippetDetailPageSkeleton
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments