Skip to content

Commit d5c01da

Browse files
committed
Refactor and migrate old indexedDb format to the same shape as desktop persistence
1 parent c7d4bac commit d5c01da

4 files changed

Lines changed: 263 additions & 110 deletions

File tree

editor/src/messages/frontend/utility_types.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@ pub struct DocumentDetails {
2121
pub is_auto_saved: bool,
2222
}
2323

24+
#[cfg_attr(feature = "wasm", derive(tsify::Tsify), tsify(large_number_types_as_bigints))]
25+
#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
26+
pub struct PersistedDocumentInfo {
27+
pub id: DocumentId,
28+
pub name: String,
29+
pub is_saved: bool,
30+
}
31+
32+
#[cfg_attr(feature = "wasm", derive(tsify::Tsify), tsify(large_number_types_as_bigints))]
33+
#[derive(Clone, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
34+
pub struct PersistedState {
35+
pub documents: Vec<PersistedDocumentInfo>,
36+
pub current_document: Option<DocumentId>,
37+
}
38+
2439
#[cfg_attr(feature = "wasm", derive(tsify::Tsify))]
2540
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
2641
pub enum MouseCursorIcon {

frontend/src/components/window/PanelSubdivision.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import LayoutRow from "/src/components/layout/LayoutRow.svelte";
55
import Panel from "/src/components/window/Panel.svelte";
66
import type { PortfolioStore } from "/src/stores/portfolio";
7-
import { savedStatus } from "/src/utility-functions/persistence";
87
import type { EditorWrapper, OpenDocument, PanelGroupState, PanelLayoutSubdivision } from "/wrapper/pkg/graphite_wasm_wrapper";
98
109
const MIN_PANEL_SIZE = 100;
@@ -34,7 +33,7 @@
3433
$: resolvedSizes = subdivision && "Split" in subdivision ? subdivision.Split.children.map((child, index) => sizeOverrides[index] ?? child.size) : [];
3534
$: documentTabLabels = $portfolio.documents.map((doc: OpenDocument) => {
3635
const name = doc.details.name;
37-
const unsaved = !savedStatus(doc.details).isSaved;
36+
const unsaved = !doc.details.is_saved;
3837
if (!editor.inDevelopmentMode()) return { name, unsaved };
3938
4039
const tooltipDescription = `Document ID: ${doc.id}`;

frontend/src/utility-functions/input.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { toggleFullscreen } from "/src/stores/fullscreen";
55
import type { PortfolioStore } from "/src/stores/portfolio";
66
import { pasteFile } from "/src/utility-functions/files";
77
import { makeKeyboardModifiersBitfield, textInputCleanup, getLocalizedScanCode } from "/src/utility-functions/keyboard-entry";
8-
import { savedStatus } from "/src/utility-functions/persistence";
98
import { operatingSystem } from "/src/utility-functions/platform";
109
import type { EditorWrapper } from "/wrapper/pkg/graphite_wasm_wrapper";
1110

@@ -248,15 +247,15 @@ export function onModifyInputField(e: CustomEvent) {
248247

249248
export async function onBeforeUnload(e: BeforeUnloadEvent, editor: EditorWrapper, portfolioStore: PortfolioStore) {
250249
const activeDocument = get(portfolioStore).documents[get(portfolioStore).activeDocumentIndex];
251-
if (activeDocument && !savedStatus(activeDocument.details).isAutoSaved) editor.triggerAutoSave(activeDocument.id);
250+
if (activeDocument && !activeDocument.details.is_auto_saved) editor.triggerAutoSave(activeDocument.id);
252251

253252
// Skip the message if the editor crashed, since work is already lost
254253
if (await editor.hasCrashed()) return;
255254

256255
// Skip the message during development, since it's annoying when testing
257256
if (await editor.inDevelopmentMode()) return;
258257

259-
const allDocumentsSaved = get(portfolioStore).documents.reduce((acc, doc) => acc && savedStatus(doc.details).isSaved, true);
258+
const allDocumentsSaved = get(portfolioStore).documents.reduce((acc, doc) => acc && doc.details.is_saved, true);
260259
if (!allDocumentsSaved) {
261260
e.returnValue = "Unsaved work will be lost if the web browser tab is closed. Close anyway?";
262261
e.preventDefault();

0 commit comments

Comments
 (0)