Notebook Snapshot menu is only updating section and page names for the editor's view #3982 (#4002)

* if default section/page is missing then clear default notebook and hide option from dropdown.

* handle edge case when section is null/undefined.

* refactored notebook localstorage data + fixed some edge cases when default section/page gets deleted.

Co-authored-by: Shefali Joshi <simplyrender@gmail.com>
This commit is contained in:
Nikhil
2021-08-12 13:29:01 -07:00
committed by GitHub
parent 9f4190f781
commit 359e7377ac
12 changed files with 291 additions and 211 deletions

View File

@ -9,24 +9,24 @@ const TIME_BOUNDS = {
};
export function addEntryIntoPage(notebookStorage, entries, entry) {
const defaultSection = notebookStorage.section;
const defaultPage = notebookStorage.page;
if (!defaultSection || !defaultPage) {
const defaultSectionId = notebookStorage.defaultSectionId;
const defaultPageId = notebookStorage.defaultPageId;
if (!defaultSectionId || !defaultPageId) {
return;
}
const newEntries = JSON.parse(JSON.stringify(entries));
let section = newEntries[defaultSection.id];
let section = newEntries[defaultSectionId];
if (!section) {
newEntries[defaultSection.id] = {};
newEntries[defaultSectionId] = {};
}
let page = newEntries[defaultSection.id][defaultPage.id];
let page = newEntries[defaultSectionId][defaultPageId];
if (!page) {
newEntries[defaultSection.id][defaultPage.id] = [];
newEntries[defaultSectionId][defaultPageId] = [];
}
newEntries[defaultSection.id][defaultPage.id].push(entry);
newEntries[defaultSectionId][defaultPageId].push(entry);
return newEntries;
}