From ae982e929882bfbd98e52adbab0079c7b8b6a3ec Mon Sep 17 00:00:00 2001 From: Timur Khazamov Date: Tue, 7 Jan 2020 20:18:20 +0500 Subject: [PATCH] Revert "Save scene in URL (#220)" (#234) This reverts commit db973c61e85347120c46adba6cb33e50d49988ba. --- src/index.tsx | 20 ++------------------ src/scene/data.ts | 19 ------------------- src/scene/index.ts | 4 +--- 3 files changed, 3 insertions(+), 40 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 45905f0a..2642b929 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -18,8 +18,6 @@ import { exportAsPNG, restoreFromLocalStorage, saveToLocalStorage, - restoreFromURL, - saveToURL, hasBackground, hasStroke, getElementAtPosition, @@ -122,8 +120,7 @@ class App extends React.Component<{}, AppState> { document.addEventListener("keydown", this.onKeyDown, false); window.addEventListener("resize", this.onResize, false); - const savedState = - restoreFromURL(elements) || restoreFromLocalStorage(elements); + const savedState = restoreFromLocalStorage(elements); if (savedState) { this.setState(savedState); } @@ -951,11 +948,6 @@ class App extends React.Component<{}, AppState> { })); }; - private saveDebounced = debounce(() => { - saveToLocalStorage(elements, this.state); - saveToURL(elements, this.state); - }, 300); - private addElementsFromPaste = (paste: string, x?: number, y?: number) => { let parsedElements; try { @@ -995,7 +987,7 @@ class App extends React.Component<{}, AppState> { scrollY: this.state.scrollY, viewBackgroundColor: this.state.viewBackgroundColor }); - this.saveDebounced(); + saveToLocalStorage(elements, this.state); if (history.isRecording()) { history.pushEntry(history.generateCurrentEntry(elements)); history.clearRedoStack(); @@ -1004,14 +996,6 @@ class App extends React.Component<{}, AppState> { } } -function debounce(fn: (...args: T) => void, timeout: number) { - let handle = 0; - return (...args: T) => { - clearTimeout(handle); - handle = window.setTimeout(() => fn(...args), timeout); - }; -} - const rootElement = document.getElementById("root"); ReactDOM.render(, rootElement); const canvas = document.getElementById("canvas") as HTMLCanvasElement; diff --git a/src/scene/data.ts b/src/scene/data.ts index 716f6fdc..892efef5 100644 --- a/src/scene/data.ts +++ b/src/scene/data.ts @@ -174,22 +174,3 @@ export function saveToLocalStorage( localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(elements)); localStorage.setItem(LOCAL_STORAGE_KEY_STATE, JSON.stringify(state)); } - -export function restoreFromURL(elements: ExcalidrawElement[]) { - try { - const [savedElements, savedState] = document.location.hash - .slice(1) - .split(":") - .map(atob); - return restore(elements, savedElements, savedState); - } catch (ex) { - return null; - } -} - -export function saveToURL(elements: ExcalidrawElement[], state: AppState) { - const hash = [JSON.stringify(elements), JSON.stringify(state)] - .map(btoa) - .join(":"); - document.location.replace("#" + hash); -} diff --git a/src/scene/index.ts b/src/scene/index.ts index 21cbdd70..71e78d69 100644 --- a/src/scene/index.ts +++ b/src/scene/index.ts @@ -12,9 +12,7 @@ export { loadFromJSON, saveAsJSON, restoreFromLocalStorage, - saveToLocalStorage, - restoreFromURL, - saveToURL + saveToLocalStorage } from "./data"; export { hasBackground, hasStroke, getElementAtPosition } from "./comparisons"; export { createScene } from "./createScene";