0
0
Fork 0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-05-02 15:30:06 +00:00

Reviewed and refactored additional editor draft save warnings

- Added testing to cover warning cases.
- Refactored logic to be simpler and move much of the business out of
  the controller.
- Added new message that's more suitable to the case this was handling.
- For detecting an outdated draft, checked the draft created_at time
  instead of updated_at to better fit the scenario being checked.
- Updated some method types to align with those potentially being used
  in the logic of the code.
- Added a cache of shown messages on the front-end to prevent them
  re-showing on every save during the session, even if dismissed.
This commit is contained in:
Dan Brown 2021-10-04 20:26:55 +01:00
parent 756b55bbff
commit f99af807d0
No known key found for this signature in database
GPG key ID: 46D9F943C24A2EF9
6 changed files with 96 additions and 39 deletions
resources/js/components

View file

@ -40,6 +40,7 @@ class PageEditor {
frequency: 30000,
last: 0,
};
this.shownWarningsCache = new Set();
if (this.pageId !== 0 && this.draftsEnabled) {
window.setTimeout(() => {
@ -119,8 +120,9 @@ class PageEditor {
}
this.draftNotifyChange(`${resp.data.message} ${Dates.utcTimeStampToLocalTime(resp.data.timestamp)}`);
this.autoSave.last = Date.now();
if (resp.data.warning.length > 0) {
if (resp.data.warning && !this.shownWarningsCache.has(resp.data.warning)) {
window.$events.emit('warning', resp.data.warning);
this.shownWarningsCache.add(resp.data.warning);
}
} catch (err) {
// Save the editor content in LocalStorage as a last resort, just in case.