From e800dfe7965fcbb48e9b4446ea6e6845fa84ed13 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Sat, 16 Mar 2019 02:24:07 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D0=BA=D0=B8=D0=B9=20=D1=80?= =?UTF-8?q?=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D0=BD=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/components/Reader/Reader.vue | 2 +- .../Reader/ServerStorage/ServerStorage.vue | 44 +++++++++---------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/client/components/Reader/Reader.vue b/client/components/Reader/Reader.vue index d35cc4eb..a29c66c2 100644 --- a/client/components/Reader/Reader.vue +++ b/client/components/Reader/Reader.vue @@ -205,9 +205,9 @@ class Reader extends Vue { mounted() { (async() => { - this.$refs.serverStorage.init(); await bookManager.init(this.settings); await restoreOldSettings(this.settings, bookManager, this.commit); + await this.$refs.serverStorage.init(); if (this.$root.rootRoute == '/reader') { if (this.routeParamUrl) { diff --git a/client/components/Reader/ServerStorage/ServerStorage.vue b/client/components/Reader/ServerStorage/ServerStorage.vue index 66d2547a..07025236 100644 --- a/client/components/Reader/ServerStorage/ServerStorage.vue +++ b/client/components/Reader/ServerStorage/ServerStorage.vue @@ -90,36 +90,34 @@ class ServerStorage extends Vue { } async saveProfiles() { - if (!this.currentProfile) + if (!this.currentProfile || this.savingProfiles) return; - if (!this.savingProfiles) { - this.savingProfiles = true; + this.savingProfiles = true; - const diff = utils.getObjDiff(this.oldProfiles, this.profiles); - let result = {state: ''}; - let tries = 0; - while (result.state != 'success' && tries < maxSetTries) { - result = await this.storageSet({'profiles': {rev: this.profilesRev + 1, data: this.profiles}}); + const diff = utils.getObjDiff(this.oldProfiles, this.profiles); + let result = {state: ''}; + let tries = 0; + while (result.state != 'success' && tries < maxSetTries) { + result = await this.storageSet({'profiles': {rev: this.profilesRev + 1, data: this.profiles}}); - if (result.state == 'reject') { - await this.loadProfiles(); - const newProfiles = utils.applyObjDiff(this.profiles, diff); - this.commit('reader/setProfiles', newProfiles); - this.commit('reader/setProfilesRev', result.items.profiles.rev); - } - - tries++; + if (result.state == 'reject') { + await this.loadProfiles(); + const newProfiles = utils.applyObjDiff(this.profiles, diff); + this.commit('reader/setProfiles', newProfiles); + this.commit('reader/setProfilesRev', result.items.profiles.rev); } - this.commit('reader/setProfilesRev', this.profilesRev + 1); - - if (tries >= maxSetTries) { - throw new Error('Не удалось отправить данные на сервер'); - } - - this.savingProfiles = false; + tries++; } + + this.commit('reader/setProfilesRev', this.profilesRev + 1); + + if (tries >= maxSetTries) { + throw new Error('Не удалось отправить данные на сервер'); + } + + this.savingProfiles = false; } generateNewServerStorageKey() {