Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/graph-builder/graph-core/4-undo-redo.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ class GraphUndoRedo extends GraphComponent {
),
});
this.curActionIndex += 1;

if (this.actionArr.length > 100) {
const drop = this.actionArr.length - 100;
this.actionArr.splice(0, drop);
this.curActionIndex -= drop;
}

this.informUI();
}

Expand Down
8 changes: 6 additions & 2 deletions src/graph-builder/graph-core/5-load-save.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ class GraphLoadSave extends GraphUndoRedo {
}

static stringifyAction({ actionName, parameters }) {
return { actionName, parameters: window.btoa(JSON.stringify(parameters)) };
return { actionName, parameters: JSON.stringify(parameters) };
}

static parseAction({ actionName, parameters }) {
return { actionName, parameters: JSON.parse(window.atob(parameters)) };
try {
return { actionName, parameters: JSON.parse(parameters) };
} catch {
return { actionName, parameters: JSON.parse(window.atob(parameters)) };
}
}

jsonifyGraph() {
Expand Down
14 changes: 11 additions & 3 deletions src/graph-builder/local-storage-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ const localStorageGet = (key) => {
const localStorageSet = (key, value) => {
try {
window.localStorage.setItem(key, value);
return true;
} catch (e) {
toast.error(e.message);
return false;
}
};

Expand Down Expand Up @@ -53,12 +55,18 @@ const localStorageManager = {
get(id) {
const raw = localStorageGet(id);
if (raw === null) return null;
return JSON.parse(window.atob(raw));
try {
return JSON.parse(raw);
} catch {
return JSON.parse(window.atob(raw));
}
},
save(id, graphContent) {
this.addGraph(id);
const serializedJson = JSON.stringify(graphContent);
localStorageSet(id, window.btoa(serializedJson));
if (!localStorageSet(id, JSON.stringify(graphContent))) {
const stripped = { ...graphContent, actionHistory: [] };
localStorageSet(id, JSON.stringify(stripped));
}
},
remove(id) {
if (this.allgs.delete(id)) this.saveAllgs();
Expand Down