Skip to content

Commit bd69126

Browse files
committed
Switch indexedDb document serialized struct from camelCase to snake_case
1 parent da45ab2 commit bd69126

5 files changed

Lines changed: 24 additions & 15 deletions

File tree

desktop/wrapper/src/intercept_frontend_message.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ pub(super) fn intercept_frontend_message(dispatcher: &mut DesktopWrapperMessageD
7171
dispatcher.respond(DesktopFrontendMessage::PersistenceWriteDocument {
7272
id: document_id,
7373
document: Document {
74+
content: document,
7475
name: details.name,
7576
path: details.path,
76-
content: document,
7777
is_saved: details.is_saved,
7878
},
7979
});

editor/src/messages/frontend/utility_types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ pub struct OpenDocument {
1515
pub struct DocumentDetails {
1616
pub name: String,
1717
pub path: Option<PathBuf>,
18-
#[serde(rename = "isSaved")]
18+
#[serde(alias = "isSaved")]
1919
pub is_saved: bool,
20-
#[serde(rename = "isAutoSaved")]
20+
#[serde(alias = "isAutoSaved")]
2121
pub is_auto_saved: bool,
2222
}
2323

frontend/src/components/window/PanelSubdivision.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
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";
78
import type { EditorWrapper, OpenDocument, PanelGroupState, PanelLayoutSubdivision } from "/wrapper/pkg/graphite_wasm_wrapper";
89
910
const MIN_PANEL_SIZE = 100;
@@ -33,7 +34,7 @@
3334
$: resolvedSizes = subdivision && "Split" in subdivision ? subdivision.Split.children.map((child, index) => sizeOverrides[index] ?? child.size) : [];
3435
$: documentTabLabels = $portfolio.documents.map((doc: OpenDocument) => {
3536
const name = doc.details.name;
36-
const unsaved = !doc.details.isSaved;
37+
const unsaved = !savedStatus(doc.details).isSaved;
3738
if (!editor.inDevelopmentMode()) return { name, unsaved };
3839
3940
const tooltipDescription = `Document ID: ${doc.id}`;

frontend/src/utility-functions/input.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ 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";
89
import { operatingSystem } from "/src/utility-functions/platform";
910
import type { EditorWrapper } from "/wrapper/pkg/graphite_wasm_wrapper";
1011

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

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

252253
// Skip the message if the editor crashed, since work is already lost
253254
if (await editor.hasCrashed()) return;
254255

255256
// Skip the message during development, since it's annoying when testing
256257
if (await editor.inDevelopmentMode()) return;
257258

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

frontend/src/utility-functions/persistence.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { get } from "svelte/store";
22
import type { PortfolioStore } from "/src/stores/portfolio";
33
import type { MessageBody } from "/src/subscriptions-router";
4-
import type { EditorWrapper } from "/wrapper/pkg/graphite_wasm_wrapper";
4+
import type { DocumentDetails, EditorWrapper } from "/wrapper/pkg/graphite_wasm_wrapper";
55

66
const PERSISTENCE_DB = "graphite";
77
const PERSISTENCE_STORE = "store";
@@ -72,13 +72,13 @@ export async function loadFirstDocument(editor: EditorWrapper) {
7272

7373
if (currentDocumentId !== undefined && String(currentDocumentId) in previouslySavedDocuments) {
7474
const doc = previouslySavedDocuments[String(currentDocumentId)];
75-
editor.openAutoSavedDocument(doc.documentId, doc.details.name, doc.details.isSaved, doc.document, false);
75+
editor.openAutoSavedDocument(doc.documentId, doc.details.name, savedStatus(doc.details).isSaved, doc.document, false);
7676
editor.selectDocument(currentDocumentId);
7777
} else {
7878
const len = orderedSavedDocuments.length;
7979
if (len > 0) {
8080
const doc = orderedSavedDocuments[len - 1];
81-
editor.openAutoSavedDocument(doc.documentId, doc.details.name, doc.details.isSaved, doc.document, false);
81+
editor.openAutoSavedDocument(doc.documentId, doc.details.name, savedStatus(doc.details).isSaved, doc.document, false);
8282
editor.selectDocument(doc.documentId);
8383
}
8484
}
@@ -108,13 +108,11 @@ export async function loadRestDocuments(editor: EditorWrapper) {
108108
if (currentIndex !== -1 && currentDocumentId !== undefined) {
109109
for (let i = currentIndex - 1; i >= 0; i--) {
110110
const { documentId, document, details } = orderedSavedDocuments[i];
111-
const { name, isSaved } = details;
112-
editor.openAutoSavedDocument(documentId, name, isSaved, document, true);
111+
editor.openAutoSavedDocument(documentId, details.name, savedStatus(details).isSaved, document, true);
113112
}
114113
for (let i = currentIndex + 1; i < orderedSavedDocuments.length; i++) {
115114
const { documentId, document, details } = orderedSavedDocuments[i];
116-
const { name, isSaved } = details;
117-
editor.openAutoSavedDocument(documentId, name, isSaved, document, false);
115+
editor.openAutoSavedDocument(documentId, details.name, savedStatus(details).isSaved, document, false);
118116
}
119117

120118
editor.selectDocument(currentDocumentId);
@@ -125,8 +123,7 @@ export async function loadRestDocuments(editor: EditorWrapper) {
125123

126124
for (let i = length - 2; i >= 0; i--) {
127125
const { documentId, document, details } = orderedSavedDocuments[i];
128-
const { name, isSaved } = details;
129-
editor.openAutoSavedDocument(documentId, name, isSaved, document, true);
126+
editor.openAutoSavedDocument(documentId, details.name, savedStatus(details).isSaved, document, true);
130127
}
131128

132129
if (length > 0) editor.selectDocument(orderedSavedDocuments[length - 1].documentId);
@@ -236,3 +233,13 @@ async function databaseUpdate<T>(key: string, updater: (existing: T | undefined)
236233
transaction.onerror = () => reject(transaction.error);
237234
});
238235
}
236+
237+
// TODO: Eventually remove this document upgrade code
238+
export function savedStatus(details: DocumentDetails): { isSaved: boolean; isAutoSaved: boolean } {
239+
const unknownDetails: unknown = details;
240+
if (typeof unknownDetails === "object" && unknownDetails !== null && "isSaved" in unknownDetails && "isAutoSaved" in unknownDetails) {
241+
return { isSaved: Boolean(unknownDetails.isSaved), isAutoSaved: Boolean(unknownDetails.isAutoSaved) };
242+
}
243+
244+
return { isSaved: details.is_saved, isAutoSaved: details.is_auto_saved };
245+
}

0 commit comments

Comments
 (0)