Remove previously loaded scenes (#734)
As mentioned in #724, the current implementation is suboptimal. Let's remove it until we come back with a better design. Fixes #724
This commit is contained in:
parent
8d64ec8153
commit
935a7f58a7
@ -1,33 +0,0 @@
|
|||||||
import React from "react";
|
|
||||||
import { PreviousScene } from "../scene/types";
|
|
||||||
import { t } from "../i18n";
|
|
||||||
|
|
||||||
interface StoredScenesListProps {
|
|
||||||
scenes: PreviousScene[];
|
|
||||||
currentId?: string;
|
|
||||||
onChange: (selectedId: string, k?: string) => {};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function StoredScenesList({
|
|
||||||
scenes,
|
|
||||||
currentId,
|
|
||||||
onChange,
|
|
||||||
}: StoredScenesListProps) {
|
|
||||||
return (
|
|
||||||
<select
|
|
||||||
className="stored-ids-select"
|
|
||||||
onChange={({ currentTarget }) => {
|
|
||||||
const scene = scenes[(currentTarget.value as unknown) as number];
|
|
||||||
onChange(scene.id, scene.k);
|
|
||||||
}}
|
|
||||||
value={currentId}
|
|
||||||
title={t("buttons.previouslyLoadedScenes")}
|
|
||||||
>
|
|
||||||
{scenes.map((scene, i) => (
|
|
||||||
<option key={i} value={i}>
|
|
||||||
id={scene.id}
|
|
||||||
</option>
|
|
||||||
))}
|
|
||||||
</select>
|
|
||||||
);
|
|
||||||
}
|
|
@ -31,7 +31,6 @@ import {
|
|||||||
hasStroke,
|
hasStroke,
|
||||||
hasText,
|
hasText,
|
||||||
exportCanvas,
|
exportCanvas,
|
||||||
loadedScenes,
|
|
||||||
loadScene,
|
loadScene,
|
||||||
calculateScrollCenter,
|
calculateScrollCenter,
|
||||||
loadFromBlob,
|
loadFromBlob,
|
||||||
@ -96,7 +95,6 @@ import { ExportDialog } from "./components/ExportDialog";
|
|||||||
import { LanguageList } from "./components/LanguageList";
|
import { LanguageList } from "./components/LanguageList";
|
||||||
import { Point } from "roughjs/bin/geometry";
|
import { Point } from "roughjs/bin/geometry";
|
||||||
import { t, languages, setLanguage, getLanguage } from "./i18n";
|
import { t, languages, setLanguage, getLanguage } from "./i18n";
|
||||||
import { StoredScenesList } from "./components/StoredScenesList";
|
|
||||||
import { HintViewer } from "./components/HintViewer";
|
import { HintViewer } from "./components/HintViewer";
|
||||||
|
|
||||||
import { copyToAppClipboard, getClipboardContent } from "./clipboard";
|
import { copyToAppClipboard, getClipboardContent } from "./clipboard";
|
||||||
@ -318,22 +316,6 @@ const LayerUI = React.memo(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderIdsDropdown() {
|
|
||||||
const scenes = loadedScenes();
|
|
||||||
if (scenes.length === 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<StoredScenesList
|
|
||||||
scenes={scenes}
|
|
||||||
currentId={appState.selectedId}
|
|
||||||
onChange={async (id, k) =>
|
|
||||||
actionManager.updater(await loadScene(id, k))
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<FixedSideContainer side="top">
|
<FixedSideContainer side="top">
|
||||||
@ -400,7 +382,6 @@ const LayerUI = React.memo(
|
|||||||
languages={languages}
|
languages={languages}
|
||||||
currentLanguage={language}
|
currentLanguage={language}
|
||||||
/>
|
/>
|
||||||
{renderIdsDropdown()}
|
|
||||||
{appState.scrolledOutside && (
|
{appState.scrolledOutside && (
|
||||||
<button
|
<button
|
||||||
className="scroll-back-to-content"
|
className="scroll-back-to-content"
|
||||||
|
@ -52,7 +52,6 @@
|
|||||||
"getShareableLink": "Get shareable link",
|
"getShareableLink": "Get shareable link",
|
||||||
"close": "Close",
|
"close": "Close",
|
||||||
"selectLanguage": "Select Language",
|
"selectLanguage": "Select Language",
|
||||||
"previouslyLoadedScenes": "Previously loaded scenes",
|
|
||||||
"scrollBackToContent": "Scroll back to content"
|
"scrollBackToContent": "Scroll back to content"
|
||||||
},
|
},
|
||||||
"alerts": {
|
"alerts": {
|
||||||
|
@ -52,8 +52,7 @@
|
|||||||
"getShareableLink": "Obtener enlace para compartir",
|
"getShareableLink": "Obtener enlace para compartir",
|
||||||
"showExportDialog": "Mostrar diálogo para exportar",
|
"showExportDialog": "Mostrar diálogo para exportar",
|
||||||
"close": "Cerrar",
|
"close": "Cerrar",
|
||||||
"selectLanguage": "Seleccionar idioma",
|
"selectLanguage": "Seleccionar idioma"
|
||||||
"previouslyLoadedScenes": "Escenas previamente cargadas"
|
|
||||||
},
|
},
|
||||||
"alerts": {
|
"alerts": {
|
||||||
"clearReset": "Esto limpiará todo el lienzo. Estás seguro?",
|
"clearReset": "Esto limpiará todo el lienzo. Estás seguro?",
|
||||||
|
@ -46,7 +46,6 @@
|
|||||||
"save": "Sauvegarder",
|
"save": "Sauvegarder",
|
||||||
"load": "Ouvrir",
|
"load": "Ouvrir",
|
||||||
"getShareableLink": "Obtenir un lien de partage",
|
"getShareableLink": "Obtenir un lien de partage",
|
||||||
"previouslyLoadedScenes": "Scènes précédemment chargées",
|
|
||||||
"scrollBackToContent": "Revenir au contenu"
|
"scrollBackToContent": "Revenir au contenu"
|
||||||
},
|
},
|
||||||
"alerts": {
|
"alerts": {
|
||||||
|
@ -52,7 +52,6 @@
|
|||||||
"getShareableLink": "Få delingslenke",
|
"getShareableLink": "Få delingslenke",
|
||||||
"close": "Lukk",
|
"close": "Lukk",
|
||||||
"selectLanguage": "Velg språk",
|
"selectLanguage": "Velg språk",
|
||||||
"previouslyLoadedScenes": "Tidligere åpnete scener",
|
|
||||||
"scrollBackToContent": "Skroll tilbake til innhold"
|
"scrollBackToContent": "Skroll tilbake til innhold"
|
||||||
},
|
},
|
||||||
"alerts": {
|
"alerts": {
|
||||||
|
@ -52,7 +52,6 @@
|
|||||||
"getShareableLink": "Udostępnij",
|
"getShareableLink": "Udostępnij",
|
||||||
"close": "Zamknij",
|
"close": "Zamknij",
|
||||||
"selectLanguage": "Wybierz język",
|
"selectLanguage": "Wybierz język",
|
||||||
"previouslyLoadedScenes": "Ostatnie dokumenty",
|
|
||||||
"scrollBackToContent": "Wróć do obszaru roboczego"
|
"scrollBackToContent": "Wróć do obszaru roboczego"
|
||||||
},
|
},
|
||||||
"alerts": {
|
"alerts": {
|
||||||
|
@ -46,7 +46,6 @@
|
|||||||
"save": "Guardar",
|
"save": "Guardar",
|
||||||
"load": "Carregar",
|
"load": "Carregar",
|
||||||
"getShareableLink": "Obter um link de partilha",
|
"getShareableLink": "Obter um link de partilha",
|
||||||
"previouslyLoadedScenes": "Cenas carregadas anteriormente",
|
|
||||||
"scrollBackToContent": "Voltar ao conteúdo"
|
"scrollBackToContent": "Voltar ao conteúdo"
|
||||||
},
|
},
|
||||||
"alerts": {
|
"alerts": {
|
||||||
|
@ -51,8 +51,7 @@
|
|||||||
"load": "Загрузить",
|
"load": "Загрузить",
|
||||||
"getShareableLink": "Получить доступ по ссылке",
|
"getShareableLink": "Получить доступ по ссылке",
|
||||||
"close": "Закрыть",
|
"close": "Закрыть",
|
||||||
"selectLanguage": "Выбрать язык",
|
"selectLanguage": "Выбрать язык"
|
||||||
"previouslyLoadedScenes": "Ранее загруженные сцены"
|
|
||||||
},
|
},
|
||||||
"alerts": {
|
"alerts": {
|
||||||
"clearReset": "Это очистит весь холст. Вы уверены?",
|
"clearReset": "Это очистит весь холст. Вы уверены?",
|
||||||
|
@ -7,7 +7,7 @@ import {
|
|||||||
} from "../appState";
|
} from "../appState";
|
||||||
|
|
||||||
import { AppState } from "../types";
|
import { AppState } from "../types";
|
||||||
import { ExportType, PreviousScene } from "./types";
|
import { ExportType } from "./types";
|
||||||
import { exportToCanvas, exportToSvg } from "./export";
|
import { exportToCanvas, exportToSvg } from "./export";
|
||||||
import nanoid from "nanoid";
|
import nanoid from "nanoid";
|
||||||
import { fileOpen, fileSave } from "browser-nativefs";
|
import { fileOpen, fileSave } from "browser-nativefs";
|
||||||
@ -18,7 +18,6 @@ import { t } from "../i18n";
|
|||||||
import { copyCanvasToClipboardAsPng } from "../clipboard";
|
import { copyCanvasToClipboardAsPng } from "../clipboard";
|
||||||
|
|
||||||
const LOCAL_STORAGE_KEY = "excalidraw";
|
const LOCAL_STORAGE_KEY = "excalidraw";
|
||||||
const LOCAL_STORAGE_SCENE_PREVIOUS_KEY = "excalidraw-previos-scenes";
|
|
||||||
const LOCAL_STORAGE_KEY_STATE = "excalidraw-state";
|
const LOCAL_STORAGE_KEY_STATE = "excalidraw-state";
|
||||||
const BACKEND_GET = "https://json.excalidraw.com/api/v1/";
|
const BACKEND_GET = "https://json.excalidraw.com/api/v1/";
|
||||||
|
|
||||||
@ -434,47 +433,6 @@ export function saveToLocalStorage(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the list of ids in Local Storage
|
|
||||||
* @returns array
|
|
||||||
*/
|
|
||||||
export function loadedScenes(): PreviousScene[] {
|
|
||||||
const storedPreviousScenes = localStorage.getItem(
|
|
||||||
LOCAL_STORAGE_SCENE_PREVIOUS_KEY,
|
|
||||||
);
|
|
||||||
if (storedPreviousScenes) {
|
|
||||||
try {
|
|
||||||
return JSON.parse(storedPreviousScenes);
|
|
||||||
} catch (e) {
|
|
||||||
console.error("Could not parse previously stored ids");
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Append id to the list of Previous Scenes in Local Storage if not there yet
|
|
||||||
* @param id string
|
|
||||||
*/
|
|
||||||
export function addToLoadedScenes(id: string, k: string | undefined): void {
|
|
||||||
const scenes = [...loadedScenes()];
|
|
||||||
const newScene = scenes.every(scene => scene.id !== id);
|
|
||||||
|
|
||||||
if (newScene) {
|
|
||||||
scenes.push({
|
|
||||||
timestamp: Date.now(),
|
|
||||||
id,
|
|
||||||
k,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
localStorage.setItem(
|
|
||||||
LOCAL_STORAGE_SCENE_PREVIOUS_KEY,
|
|
||||||
JSON.stringify(scenes),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function loadScene(id: string | null, k?: string) {
|
export async function loadScene(id: string | null, k?: string) {
|
||||||
let data;
|
let data;
|
||||||
let selectedId;
|
let selectedId;
|
||||||
@ -482,7 +440,6 @@ export async function loadScene(id: string | null, k?: string) {
|
|||||||
// k is the private key used to decrypt the content from the server, take
|
// k is the private key used to decrypt the content from the server, take
|
||||||
// extra care not to leak it
|
// extra care not to leak it
|
||||||
data = await importFromBackend(id, k);
|
data = await importFromBackend(id, k);
|
||||||
addToLoadedScenes(id, k);
|
|
||||||
selectedId = id;
|
selectedId = id;
|
||||||
window.history.replaceState({}, "Excalidraw", window.location.origin);
|
window.history.replaceState({}, "Excalidraw", window.location.origin);
|
||||||
} else {
|
} else {
|
||||||
|
@ -16,8 +16,6 @@ export {
|
|||||||
saveToLocalStorage,
|
saveToLocalStorage,
|
||||||
exportToBackend,
|
exportToBackend,
|
||||||
importFromBackend,
|
importFromBackend,
|
||||||
addToLoadedScenes,
|
|
||||||
loadedScenes,
|
|
||||||
loadScene,
|
loadScene,
|
||||||
calculateScrollCenter,
|
calculateScrollCenter,
|
||||||
} from "./data";
|
} from "./data";
|
||||||
|
@ -16,10 +16,4 @@ export interface Scene {
|
|||||||
elements: ExcalidrawTextElement[];
|
elements: ExcalidrawTextElement[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PreviousScene {
|
|
||||||
id: string;
|
|
||||||
k?: string;
|
|
||||||
timestamp: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type ExportType = "png" | "clipboard" | "backend" | "svg";
|
export type ExportType = "png" | "clipboard" | "backend" | "svg";
|
||||||
|
@ -238,15 +238,6 @@ button,
|
|||||||
bottom: 0;
|
bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.stored-ids-select {
|
|
||||||
@extend .dropdown-select;
|
|
||||||
padding: 0 0.5em 0 1.7em;
|
|
||||||
bottom: 0;
|
|
||||||
left: 0;
|
|
||||||
background-position: left 0.7em top 50%, 0 0;
|
|
||||||
margin-left: 0.5em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.visually-hidden {
|
.visually-hidden {
|
||||||
position: absolute !important;
|
position: absolute !important;
|
||||||
height: 1px;
|
height: 1px;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user