performance
This commit is contained in:
parent
b8723bc952
commit
3cae2eca2c
4 changed files with 32 additions and 23 deletions
48
src/App.tsx
48
src/App.tsx
|
|
@ -1,5 +1,6 @@
|
|||
import { useState, useEffect } from "react";
|
||||
import { useState, useEffect, useCallback } from "react";
|
||||
import { encode, decode } from "base65536";
|
||||
import debounce from "lodash.debounce";
|
||||
import pako from "pako";
|
||||
|
||||
import "@blocknote/core/fonts/inter.css";
|
||||
|
|
@ -47,30 +48,33 @@ export default function App() {
|
|||
loadContentFromURL();
|
||||
}, [editor]);
|
||||
|
||||
const handleChange = async () => {
|
||||
if (!editor) return;
|
||||
// useCallback을 사용해 debounce 유지
|
||||
const debouncedHandleChange = useCallback(
|
||||
debounce(async () => {
|
||||
if (!editor) return;
|
||||
|
||||
const newContentMarkdown = await editor.blocksToMarkdownLossy(
|
||||
editor.topLevelBlocks
|
||||
);
|
||||
setContentForURL(newContentMarkdown);
|
||||
const newContentMarkdown = await editor.blocksToMarkdownLossy(
|
||||
editor.topLevelBlocks
|
||||
);
|
||||
setContentForURL(newContentMarkdown);
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
let encodedString: string;
|
||||
const encoder = new TextEncoder();
|
||||
let encodedString: string;
|
||||
|
||||
if (newContentMarkdown.length >= 40) {
|
||||
const encodedBytes = encoder.encode(newContentMarkdown);
|
||||
const compressed = pako.gzip(encodedBytes);
|
||||
encodedString = encode(compressed); // 압축 + 인코딩
|
||||
} else {
|
||||
const plainBytes = encoder.encode(newContentMarkdown);
|
||||
encodedString = encode(plainBytes); // 압축 없이 인코딩
|
||||
}
|
||||
if (newContentMarkdown.length >= 40) {
|
||||
const encodedBytes = encoder.encode(newContentMarkdown);
|
||||
const compressed = pako.gzip(encodedBytes);
|
||||
encodedString = encode(compressed);
|
||||
} else {
|
||||
const plainBytes = encoder.encode(newContentMarkdown);
|
||||
encodedString = encode(plainBytes);
|
||||
}
|
||||
|
||||
const newUrl = `${window.location.pathname}?c=${encodedString}`;
|
||||
window.history.replaceState({}, "", newUrl);
|
||||
}, 250), [editor] // 500ms 대기
|
||||
);
|
||||
|
||||
const newUrl = `${window.location.pathname}?c=${encodedString}`;
|
||||
window.history.replaceState({}, "", newUrl);
|
||||
window.dispatchEvent(new Event("url-changed"));
|
||||
};
|
||||
|
||||
return (
|
||||
<main className="flex flex-col w-full h-screen">
|
||||
|
|
@ -86,7 +90,7 @@ export default function App() {
|
|||
<div id="editor-container" className="w-full p-4 h-full max-h-screen">
|
||||
<BlockNoteView
|
||||
editor={editor}
|
||||
onChange={handleChange}
|
||||
onChange={debouncedHandleChange}
|
||||
className="w-full h-full"
|
||||
/>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -45,10 +45,11 @@ export default function CopyLink() {
|
|||
return (
|
||||
<Dialog>
|
||||
<DialogTrigger asChild>
|
||||
<Button variant="outline" size="icon">
|
||||
<Button variant="outline" size="icon" onClick={updateLink}>
|
||||
<Share2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Share link</DialogTitle>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue