mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Pass Additional props remove localstorage related code for storing data and username from App.tsx to index.tsx (#2057)
Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
parent
0e0a695e81
commit
4718c31da5
6 changed files with 102 additions and 54 deletions
|
@ -44,7 +44,6 @@ import {
|
|||
} from "../scene";
|
||||
import {
|
||||
decryptAESGEM,
|
||||
saveToLocalStorage,
|
||||
loadScene,
|
||||
loadFromBlob,
|
||||
SOCKET_SERVER,
|
||||
|
@ -146,11 +145,7 @@ import {
|
|||
isBindableElement,
|
||||
} from "../element/typeChecks";
|
||||
import { actionFinalize, actionDeleteSelected } from "../actions";
|
||||
import {
|
||||
restoreUsernameFromLocalStorage,
|
||||
saveUsernameToLocalStorage,
|
||||
loadLibrary,
|
||||
} from "../data/localStorage";
|
||||
import { loadLibrary } from "../data/localStorage";
|
||||
|
||||
import throttle from "lodash.throttle";
|
||||
import { LinearElementEditor } from "../element/linearElementEditor";
|
||||
|
@ -310,6 +305,7 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
|||
offsetLeft,
|
||||
} = this.state;
|
||||
|
||||
const { onUsernameChange } = this.props;
|
||||
const canvasScale = window.devicePixelRatio;
|
||||
|
||||
const canvasWidth = canvasDOMWidth * canvasScale;
|
||||
|
@ -335,13 +331,8 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
|||
onRoomCreate={this.openPortal}
|
||||
onRoomDestroy={this.closePortal}
|
||||
onUsernameChange={(username) => {
|
||||
if (this.props.onUsernameChange) {
|
||||
this.props.onUsernameChange(username);
|
||||
}
|
||||
saveUsernameToLocalStorage(username);
|
||||
this.setState({
|
||||
username,
|
||||
});
|
||||
onUsernameChange && onUsernameChange(username);
|
||||
this.setState({ username });
|
||||
}}
|
||||
onLockToggle={this.toggleLock}
|
||||
onInsertShape={(elements) =>
|
||||
|
@ -434,8 +425,6 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
|||
private onBlur = withBatchedUpdates(() => {
|
||||
isHoldingSpace = false;
|
||||
this.setState({ isBindingEnabled: true });
|
||||
this.saveDebounced();
|
||||
this.saveDebounced.flush();
|
||||
});
|
||||
|
||||
private onUnload = () => {
|
||||
|
@ -510,7 +499,7 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
|||
let isCollaborationScene = !!getCollaborationLinkData(window.location.href);
|
||||
const isExternalScene = !!(id || jsonMatch || isCollaborationScene);
|
||||
|
||||
if (isExternalScene && !this.props.initialData) {
|
||||
if (isExternalScene) {
|
||||
if (
|
||||
this.shouldForceLoadScene(scene) ||
|
||||
window.confirm(t("alerts.loadSceneOverridePrompt"))
|
||||
|
@ -840,7 +829,6 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
|||
if (this.state.scrolledOutside !== scrolledOutside) {
|
||||
this.setState({ scrolledOutside: scrolledOutside });
|
||||
}
|
||||
this.saveDebounced();
|
||||
|
||||
if (
|
||||
getDrawingVersion(this.scene.getElementsIncludingDeleted()) >
|
||||
|
@ -1433,16 +1421,6 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
|||
},
|
||||
);
|
||||
|
||||
restoreUserName() {
|
||||
const username = restoreUsernameFromLocalStorage();
|
||||
|
||||
if (username !== null) {
|
||||
this.setState({
|
||||
username,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Input handling
|
||||
|
||||
private onKeyDown = withBatchedUpdates((event: KeyboardEvent) => {
|
||||
|
@ -3679,10 +3657,6 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
|||
this.setState({ shouldCacheIgnoreZoom: false });
|
||||
}, 300);
|
||||
|
||||
private saveDebounced = debounce(() => {
|
||||
saveToLocalStorage(this.scene.getElementsIncludingDeleted(), this.state);
|
||||
}, 300);
|
||||
|
||||
private getCanvasOffsets() {
|
||||
if (this.excalidrawRef?.current) {
|
||||
const parentElement = this.excalidrawRef.current.parentElement;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue