Skip to content

Commit 9583f84

Browse files
authored
Fix notebook with null createdAt (#157)
1 parent 88e0e26 commit 9583f84

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

app/api.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ export function getNotebooks() {
4242
if (!files) return [];
4343
const notebooks = JSON.parse(files).sort((a, b) => new Date(b.updated) - new Date(a.updated));
4444
// Remove fallback runtime when we have breaking changes.
45-
return notebooks.map((notebook) => ({...notebook, runtime: DEFAULT_RUNTIME}));
45+
return notebooks.map((notebook) => {
46+
const newNotebook = {...notebook, runtime: DEFAULT_RUNTIME};
47+
// Add fallback created timestamp.
48+
if (!newNotebook.created) newNotebook.created = new Date().toISOString();
49+
return newNotebook;
50+
});
4651
}
4752

4853
export function clearNotebooksFromLocalStorage() {
@@ -72,6 +77,10 @@ export function addNotebook(notebook) {
7277
export function saveNotebook(notebook) {
7378
const notebooks = getNotebooks();
7479
const updatedNotebook = {...notebook, updated: new Date().toISOString()};
80+
// Prevent creating a new notebook if the created timestamp is not set.
81+
if (!updatedNotebook.created) {
82+
updatedNotebook.created = new Date().toISOString();
83+
}
7584
const newNotebooks = notebooks.map((f) => (f.id === notebook.id ? updatedNotebook : f));
7685
saveNotebooks(newNotebooks);
7786
}

0 commit comments

Comments
 (0)