1
1
"use client" ;
2
2
3
- import { useQuery } from "convex/react" ;
3
+ import dynamic from "next/dynamic" ;
4
+ import { useMemo } from "react" ;
5
+ import { useMutation , useQuery } from "convex/react" ;
4
6
5
7
import { Cover } from "@/components/cover" ;
6
8
import { Id } from "@/convex/_generated/dataModel" ;
7
9
import { api } from "@/convex/_generated/api" ;
8
10
import { Toolbar } from "@/components/toolbar" ;
11
+ import { Skeleton } from "@/components/ui/skeleton" ;
9
12
10
13
interface DocumentIdPageProps {
11
14
params : {
@@ -17,12 +20,34 @@ interface DocumentIdPageProps {
17
20
* @description page to render for url `/documents/${documentId}`
18
21
*/
19
22
const DocumentIdPage = ( { params } : DocumentIdPageProps ) => {
23
+ const Editor = useMemo (
24
+ ( ) => dynamic ( ( ) => import ( "@/components/editor" ) , { ssr : false } ) ,
25
+ [ ]
26
+ ) ;
27
+
20
28
const document = useQuery ( api . documents . getDocumentById , {
21
29
documentId : params . documentId ,
22
30
} ) ;
23
31
32
+ const update = useMutation ( api . documents . updateDocuments ) ;
33
+
34
+ const handleUpdate = ( content : string ) => {
35
+ update ( { id : params . documentId , content } ) ;
36
+ } ;
24
37
if ( document === undefined ) {
25
- return < div > loading</ div > ;
38
+ return (
39
+ < div >
40
+ < Cover . Skeleton />
41
+ < div className = "md:max-w-3xl lg:max-w-4xl mx-auto mt-10" >
42
+ < div className = "space-y-4 pl-8 pt-4" >
43
+ < Skeleton className = "h-14 w-[50%]" />
44
+ < Skeleton className = "h-4 w-[80%]" />
45
+ < Skeleton className = "h-4 w-[40%]" />
46
+ < Skeleton className = "h-4 w-[60%]" />
47
+ </ div >
48
+ </ div >
49
+ </ div >
50
+ ) ;
26
51
}
27
52
28
53
if ( document === null ) {
@@ -35,6 +60,7 @@ const DocumentIdPage = ({ params }: DocumentIdPageProps) => {
35
60
< Cover url = { document . coverImage } />
36
61
< div className = "md:max-w-3xl lg:max-w-4xl mx-auto" >
37
62
< Toolbar initialData = { document } />
63
+ < Editor onChange = { handleUpdate } initialContent = { document . content } />
38
64
</ div >
39
65
</ div >
40
66
</ >
0 commit comments