@@ -24,6 +24,8 @@ import { ColorSelector } from "./selectors/color-selector";
2424
2525import { useDebouncedCallback } from "use-debounce" ;
2626
27+ import { useUpdatePage } from "@/hooks/usePages" ;
28+
2729const extensions = [ ...defaultExtensions , slashCommand ] ;
2830
2931interface EditorProp {
@@ -41,30 +43,14 @@ const Editor = ({ pageId, initialValue }: EditorProp) => {
4143 const [ openColor , setOpenColor ] = useState ( false ) ;
4244 const [ openLink , setOpenLink ] = useState ( false ) ;
4345
44- const highlightCodeblocks = ( content : string ) => {
45- const doc = new DOMParser ( ) . parseFromString ( content , "text/html" ) ;
46- doc . querySelectorAll ( "pre code" ) . forEach ( ( el ) => {
47- // @ts -expect-error - highlightElement is not in the types
48- // https://highlightjs.readthedocs.io/en/latest/api.html?highlight=highlightElement#highlightelement
49- hljs . highlightElement ( el ) ;
50- } ) ;
51- return new XMLSerializer ( ) . serializeToString ( doc ) ;
52- } ;
46+ const updatePageMutation = useUpdatePage ( ) ;
5347
5448 const debouncedUpdates = useDebouncedCallback (
5549 async ( editor : EditorInstance ) => {
5650 if ( pageId === undefined ) return ;
5751
5852 const json = editor . getJSON ( ) ;
59- window . localStorage . setItem (
60- "html-content" ,
61- highlightCodeblocks ( editor . getHTML ( ) ) ,
62- ) ;
63- window . localStorage . setItem ( pageId . toString ( ) , JSON . stringify ( json ) ) ;
64- window . localStorage . setItem (
65- "markdown" ,
66- editor . storage . markdown . getMarkdown ( ) ,
67- ) ;
53+ updatePageMutation . mutate ( { id : pageId , pageData : json } ) ;
6854 } ,
6955
7056 500 ,
@@ -75,8 +61,6 @@ const Editor = ({ pageId, initialValue }: EditorProp) => {
7561 if ( content ) setInitialContent ( JSON . parse ( content ) ) ;
7662 } , [ pageId ] ) ;
7763
78- console . log ( initialContent ) ;
79-
8064 return (
8165 < EditorRoot >
8266 < EditorContent
0 commit comments