Update Saved pages

This commit is contained in:
Jason Wall 2020-08-05 18:36:45 -04:00
parent fb269968ad
commit b020f09fd4
2 changed files with 37 additions and 0 deletions

View File

@ -64,6 +64,10 @@ export class AppComponent extends SubscriberComponent implements AfterViewInit {
this.dialog.open(PageEditModalComponent);
}
updatePage() {
this.appService.updatePage();
}
createNote() {
this.dialog.open(NoteEditModalComponent);
}

View File

@ -317,6 +317,39 @@ export class AppService extends createStateService(reducer, initialState) {
);
}
updatePage() {
const state = this.getState();
const savedPages = [
...state.savedPages.filter((o) => o.id === state.currentPage.id),
{
id: state.currentPage.id,
title: state.currentPage.title,
queries: [...state.cards],
},
];
this.localStorageService.set('savedPages', savedPages).subscribe(
// success
() => {
this.dispatch({
type: 'UPDATE_SAVED_PAGES',
savedPages,
});
},
// error
() => {
this.dispatch({
type: 'UPDATE_ERROR',
error: {
// tslint:disable-next-line: quotemark
msg: "Something went wrong and the page wasn't saved. :(",
},
});
}
);
}
//#endregion
//#region Display Settings