Warn on invalid JSON file (#1159)
* add error dialog * show error modal on file dnd * add locales * Update src/locales/en.json Co-Authored-By: Lipis <lipiridis@gmail.com> * Update src/data/blob.ts * Update src/data/blob.ts * fix titles, update snapshots * make modal smaller * fix dnd wrong file type * reset errorMessage Co-authored-by: Faustino Kialungila <faustino.kialungila@gmail.com> Co-authored-by: Lipis <lipiridis@gmail.com>
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import { getDefaultAppState } from "../appState";
|
||||
import { DataState } from "./types";
|
||||
import { restore } from "./restore";
|
||||
import { t } from "../i18n";
|
||||
|
||||
export async function loadFromBlob(blob: any) {
|
||||
const updateAppState = (contents: string) => {
|
||||
@ -10,7 +11,7 @@ export async function loadFromBlob(blob: any) {
|
||||
try {
|
||||
const data = JSON.parse(contents);
|
||||
if (data.type !== "excalidraw") {
|
||||
throw new Error("Cannot load invalid json");
|
||||
throw new Error(t("alerts.couldNotLoadInvalidFile"));
|
||||
}
|
||||
elements = data.elements || [];
|
||||
appState = { ...defaultAppState, ...data.appState };
|
||||
@ -39,7 +40,7 @@ export async function loadFromBlob(blob: any) {
|
||||
}
|
||||
const { elements, appState } = updateAppState(contents);
|
||||
if (!elements.length) {
|
||||
return Promise.reject("Cannot load invalid json");
|
||||
return Promise.reject(t("alerts.couldNotLoadInvalidFile"));
|
||||
}
|
||||
return new Promise<DataState>((resolve) => {
|
||||
resolve(restore(elements, appState, { scrollToContent: true }));
|
||||
|
Reference in New Issue
Block a user