From 79ced4eca4a41fab465a06f999243b9f228a6b9f Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Fri, 22 Mar 2019 13:20:43 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20=D0=BD?= =?UTF-8?q?=D0=B0=D0=B4=20ServerStorage=20-=20saveRecent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/components/Reader/Reader.vue | 8 +++++++- .../Reader/ServerStorage/ServerStorage.vue | 19 ++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/client/components/Reader/Reader.vue b/client/components/Reader/Reader.vue index a20f8483..ca4c3a7b 100644 --- a/client/components/Reader/Reader.vue +++ b/client/components/Reader/Reader.vue @@ -197,6 +197,12 @@ class Reader extends Vue { } }, 500); + this.debouncedSaveRecent = _.debounce(async() => { + const serverStorage = this.$refs.serverStorage; + while (!serverStorage.inited) await utils.sleep(1000); + await serverStorage.saveRecent(); + }, 1000); + document.addEventListener('fullscreenchange', () => { this.fullScreenActive = (document.fullscreenElement !== null); }); @@ -303,7 +309,7 @@ class Reader extends Vue { await this.loadBook(newBook); } - await serverStorage.saveRecent(); + this.debouncedSaveRecent(); })(); } } diff --git a/client/components/Reader/ServerStorage/ServerStorage.vue b/client/components/Reader/ServerStorage/ServerStorage.vue index f4ea2a3f..7f5ebdc0 100644 --- a/client/components/Reader/ServerStorage/ServerStorage.vue +++ b/client/components/Reader/ServerStorage/ServerStorage.vue @@ -36,6 +36,7 @@ export default @Component({ }) class ServerStorage extends Vue { created() { + this.inited = false; this.commit = this.$store.commit; this.prevServerStorageKey = null; this.$root.$on('generateNewServerStorageKey', () => {this.generateNewServerStorageKey()}); @@ -50,14 +51,18 @@ class ServerStorage extends Vue { } async init() { - if (!this.serverStorageKey) { - //генерируем новый ключ - await this.generateNewServerStorageKey(); - } else { - await this.serverStorageKeyChanged(); + try { + if (!this.serverStorageKey) { + //генерируем новый ключ + await this.generateNewServerStorageKey(); + } else { + await this.serverStorageKeyChanged(); + } + await this.currentProfileChanged(); + await this.loadRecent(); + } finally { + this.inited = true; } - await this.currentProfileChanged(); - await this.loadRecent(); } async generateNewServerStorageKey() {