This reverts commit db973c61e85347120c46adba6cb33e50d49988ba.
This commit is contained in:
parent
829a65b8cb
commit
ae982e9298
@ -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<T extends any[]>(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(<App />, rootElement);
|
||||
const canvas = document.getElementById("canvas") as HTMLCanvasElement;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -12,9 +12,7 @@ export {
|
||||
loadFromJSON,
|
||||
saveAsJSON,
|
||||
restoreFromLocalStorage,
|
||||
saveToLocalStorage,
|
||||
restoreFromURL,
|
||||
saveToURL
|
||||
saveToLocalStorage
|
||||
} from "./data";
|
||||
export { hasBackground, hasStroke, getElementAtPosition } from "./comparisons";
|
||||
export { createScene } from "./createScene";
|
||||
|
Loading…
x
Reference in New Issue
Block a user