From 37919998dd1b739b8b00f04e70518f9994eecf0d Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Tue, 19 Sep 2023 17:40:18 +0200 Subject: [PATCH] restore progress after reloading the page (F5) --- src/components/dialogs/AlbumViewer.vue | 10 +++++++--- src/components/dialogs/ArtistViewer.vue | 10 +++++++--- src/store/modules/user/actions.js | 21 ++++++++++++--------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/components/dialogs/AlbumViewer.vue b/src/components/dialogs/AlbumViewer.vue index 83f4e08..6c2b88e 100644 --- a/src/components/dialogs/AlbumViewer.vue +++ b/src/components/dialogs/AlbumViewer.vue @@ -216,8 +216,13 @@ export default { this.$store.dispatch("albums/shareDisable", this.selectedAlbum); }, loadUserProgress() { - if (this.selectedTrack.parent._id != this.selectedAlbum._id) - this.$store.dispatch("user/getProgress", this.selectedAlbum); + if (this.selectedTrack.parent._id != this.selectedAlbum._id) { + this.$store + .dispatch("user/getProgress", this.selectedAlbum) + .then(() => { + this.gotoTrack(); + }); + } } }, computed: { @@ -310,7 +315,6 @@ export default { window.addEventListener("keydown", this.keydownListener); } this.loadUserProgress(); - this.gotoTrack(); } else { if (this.$refs.dialogWindow.visible) { this.$refs.dialogWindow.close(); diff --git a/src/components/dialogs/ArtistViewer.vue b/src/components/dialogs/ArtistViewer.vue index 954dc81..027ac55 100644 --- a/src/components/dialogs/ArtistViewer.vue +++ b/src/components/dialogs/ArtistViewer.vue @@ -154,8 +154,13 @@ export default { this.$store.dispatch("artists/uploadNewCover", this.selectedArtist); }, loadUserProgress() { - if (!this.isPlaying || this.selectedTrack.parent.parent._id != this.selectedArtist._id) - this.$store.dispatch("user/getProgress", this.selectedArtist); + if (!this.isPlaying || this.selectedTrack.parent.parent && this.selectedTrack.parent.parent._id != this.selectedArtist._id) { + this.$store.dispatch("user/getProgress", this.selectedArtist).then(() => { + this.gotoTrack(); + }); + } else { + this.gotoTrack(); + } } }, computed: { @@ -231,7 +236,6 @@ export default { window.addEventListener("keydown", this.keydownListener); } this.loadUserProgress(); - this.gotoTrack(); } else { if (this.$refs.dialogWindow.visible) { this.$refs.dialogWindow.close(); diff --git a/src/store/modules/user/actions.js b/src/store/modules/user/actions.js index 4a2acd5..0381491 100644 --- a/src/store/modules/user/actions.js +++ b/src/store/modules/user/actions.js @@ -88,15 +88,18 @@ export default { .post(context.rootGetters.server + "/api/user/progress", item, context.rootGetters.headers); }, getProgress(context, parent) { - if (context.state._id == -1) { - return; - } - - axios - .get(context.rootGetters.server + "/api/user/progress/" + parent._id, context.rootGetters.headers) - .then((res) => { - parent.progress = res.data; - }); + return new Promise((resolve) => { + if (context.state._id == -1) { + resolve(); + } else { + axios + .get(context.rootGetters.server + "/api/user/progress/" + parent._id, context.rootGetters.headers) + .then((res) => { + parent.progress = res.data; + resolve(); + }); + } + }); }, resetProgress(context, parentId) { if (context.state._id == -1) {