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
|
@ -18,12 +18,10 @@ import { serializeAsJSON } from "./json";
|
|||
|
||||
import { ExportType } from "../scene/types";
|
||||
import { restore } from "./restore";
|
||||
import { restoreFromLocalStorage } from "./localStorage";
|
||||
import { DataState } from "./types";
|
||||
|
||||
export { loadFromBlob } from "./blob";
|
||||
export { saveAsJSON, loadFromJSON } from "./json";
|
||||
export { saveToLocalStorage } from "./localStorage";
|
||||
|
||||
const BACKEND_GET = process.env.REACT_APP_BACKEND_V1_GET_URL;
|
||||
|
||||
|
@ -233,7 +231,7 @@ export const exportToBackend = async (
|
|||
}
|
||||
};
|
||||
|
||||
export const importFromBackend = async (
|
||||
const importFromBackend = async (
|
||||
id: string | null,
|
||||
privateKey?: string | null,
|
||||
) => {
|
||||
|
@ -246,7 +244,7 @@ export const importFromBackend = async (
|
|||
);
|
||||
if (!response.ok) {
|
||||
window.alert(t("alerts.importBackendFailed"));
|
||||
return restore(elements, appState);
|
||||
return { elements, appState };
|
||||
}
|
||||
let data;
|
||||
if (privateKey) {
|
||||
|
@ -277,7 +275,7 @@ export const importFromBackend = async (
|
|||
window.alert(t("alerts.importBackendFailed"));
|
||||
console.error(error);
|
||||
} finally {
|
||||
return restore(elements, appState);
|
||||
return { elements, appState };
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -374,9 +372,13 @@ export const loadScene = async (
|
|||
if (id != null) {
|
||||
// the private key is used to decrypt the content from the server, take
|
||||
// extra care not to leak it
|
||||
data = await importFromBackend(id, privateKey);
|
||||
const { elements, appState } = await importFromBackend(id, privateKey);
|
||||
data = restore(elements, appState);
|
||||
} else {
|
||||
data = initialData || restoreFromLocalStorage();
|
||||
data = restore(
|
||||
initialData?.elements ?? [],
|
||||
initialData?.appState ?? getDefaultAppState(),
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
|
@ -62,7 +62,7 @@ export const saveUsernameToLocalStorage = (username: string) => {
|
|||
}
|
||||
};
|
||||
|
||||
export const restoreUsernameFromLocalStorage = (): string | null => {
|
||||
export const importUsernameFromLocalStorage = (): string | null => {
|
||||
try {
|
||||
const data = localStorage.getItem(LOCAL_STORAGE_KEY_COLLAB);
|
||||
if (data) {
|
||||
|
@ -95,7 +95,7 @@ export const saveToLocalStorage = (
|
|||
}
|
||||
};
|
||||
|
||||
export const restoreFromLocalStorage = () => {
|
||||
export const importFromLocalStorage = () => {
|
||||
let savedElements = null;
|
||||
let savedState = null;
|
||||
|
||||
|
@ -131,5 +131,5 @@ export const restoreFromLocalStorage = () => {
|
|||
// Do nothing because appState is already null
|
||||
}
|
||||
}
|
||||
return restore(elements, appState);
|
||||
return { elements, appState };
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue