Fix browser unsaved changes with custom guard

This commit is contained in:
Michael Shamoon
2022-08-06 19:30:39 -07:00
parent cdc7a5842e
commit ea52490f6b
7 changed files with 77 additions and 32 deletions

View File

@@ -206,7 +206,7 @@ export class DocumentDetailComponent
this.store.getValue().title !==
this.documentForm.get('title').value
) {
this.openDocumentService.setDirty(doc.id, true)
this.openDocumentService.setDirty(doc, true)
}
},
})
@@ -228,12 +228,15 @@ export class DocumentDetailComponent
this.store.asObservable()
)
return this.isDirty$.pipe(map((dirty) => ({ doc, dirty })))
return this.isDirty$.pipe(
takeUntil(this.unsubscribeNotifier),
map((dirty) => ({ doc, dirty }))
)
})
)
.subscribe({
next: ({ doc, dirty }) => {
this.openDocumentService.setDirty(doc.id, dirty)
this.openDocumentService.setDirty(doc, dirty)
},
error: (error) => {
this.router.navigate(['404'])
@@ -349,7 +352,7 @@ export class DocumentDetailComponent
Object.assign(this.document, doc)
this.title = doc.title
this.documentForm.patchValue(doc)
this.openDocumentService.setDirty(doc.id, false)
this.openDocumentService.setDirty(doc, false)
},
error: () => {
this.router.navigate(['404'])