Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
LiveDuo committed Nov 8, 2023
1 parent 82599b7 commit 4edef6a
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/client/vanilla/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,33 +136,34 @@ function Editor({ standaloneServer = false }) {

const loadPage = async () => {
const baseUrl = getBaseUrl(standaloneServer)
const url2 = `${baseUrl}/api/builder/handle?type=data&path=${location.pathname}`
const data = await fetch(url2).then((r) => r.text())
canvasRef.current!.innerHTML = data
const url = `${baseUrl}/api/builder/handle?type=data&path=${location.pathname}`
const data = await fetch(url).then((r) => r.text())
return data
}

const savePage = async () => {
const savePage = async (html: string) => {
console.log('dom changed')

const baseUrl = getBaseUrl(standaloneServer)
const url = `${baseUrl}/api/builder/handle?type=data&path=${location.pathname}`

await fetch(url, { method: 'post', body: canvasRef.current!.innerHTML })
await fetch(url, { method: 'post', body: html })
}

const onDomChange = () => {
const config = { attributes: true, childList: true, subtree: true }
const observer = new MutationObserver(
debounce(() => {
savePage()
const html = canvasRef.current!.innerHTML
savePage(html)
}),
)
observer.observe(canvasRef.current!, config)
return observer
}

useEffect(() => {
loadPage()
loadPage().then((html) => (canvasRef.current!.innerHTML = html))
loadTheme(themeIndex)

const observer = onDomChange()
Expand Down

0 comments on commit 4edef6a

Please sign in to comment.