From 740152500e6e49108902380706aecabbdd42f998 Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Thu, 5 Oct 2023 13:31:46 +0200 Subject: [PATCH] load first pages serial instead parallel --- src/store/modules/albums/actions.js | 17 ++++++++++------- src/store/modules/artists/actions.js | 15 +++++++++------ src/store/modules/boxes/actions.js | 15 +++++++++------ src/views/Home.vue | 7 +++++-- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/store/modules/albums/actions.js b/src/store/modules/albums/actions.js index 90bb4f6..83148ed 100644 --- a/src/store/modules/albums/actions.js +++ b/src/store/modules/albums/actions.js @@ -32,12 +32,15 @@ export default { }, loadAlbums(context, force) { - if ((!context.state.eos || force) && !context.state.loading) { - context.state.loading = true; - axios.get(context.rootGetters.server + "/api/albums/page/" + context.state.page++, context.rootGetters.headers).then((res) => { - context.commit("setAlbums", res.data); - }); - } + return new Promise((resolve) => { + if ((!context.state.eos || force) && !context.state.loading) { + context.state.loading = true; + axios.get(context.rootGetters.server + "/api/albums/page/" + context.state.page++, context.rootGetters.headers).then((res) => { + context.commit("setAlbums", res.data); + resolve(res.data); + }); + } + }); }, loadFavourites(context) { axios.get(context.rootGetters.server + "/api/albums/favourites", context.rootGetters.headers).then(res => { @@ -165,7 +168,7 @@ export default { axios.post(context.rootGetters.server + "/api/albums/" + album._id + "/share", {}, context.rootGetters.headers).then(res => { album.share = res.data; resolve(); - context.dispatch("addPoUp", { title: "Share successful", message: "Url was copied into your clipboard", type: "success", icon:"share" }, { root: true }); + context.dispatch("addPoUp", { title: "Share successful", message: "Url was copied into your clipboard", type: "success", icon: "share" }, { root: true }); }); }); }, diff --git a/src/store/modules/artists/actions.js b/src/store/modules/artists/actions.js index 57fcb55..b034987 100644 --- a/src/store/modules/artists/actions.js +++ b/src/store/modules/artists/actions.js @@ -13,12 +13,15 @@ export default { }) }, loadArtists(context, force) { - if ((!context.state.eos || force) && !context.state.loading) { - context.state.loading = true; - axios.get(context.rootGetters.server + "/api/artists/page/" + context.state.page++, context.rootGetters.headers).then((res) => { - context.commit("setArtists", res.data); - }); - } + return new Promise((resolve) => { + if ((!context.state.eos || force) && !context.state.loading) { + context.state.loading = true; + axios.get(context.rootGetters.server + "/api/artists/page/" + context.state.page++, context.rootGetters.headers).then((res) => { + context.commit("setArtists", res.data); + resolve(res.data); + }); + } + }); }, loadArtist(context, id) { context.state.loading = true; diff --git a/src/store/modules/boxes/actions.js b/src/store/modules/boxes/actions.js index dfd777c..a6742cf 100644 --- a/src/store/modules/boxes/actions.js +++ b/src/store/modules/boxes/actions.js @@ -13,12 +13,15 @@ export default { }) }, loadBoxes(context, force) { - if ((!context.state.eos || force) && !context.state.loading) { - context.state.loading = true; - axios.get(context.rootGetters.server + "/api/boxes/page/" + context.state.page++, context.rootGetters.headers).then((res) => { - context.commit("setBoxes", res.data); - }); - } + return new Promise((resolve) => { + if ((!context.state.eos || force) && !context.state.loading) { + context.state.loading = true; + axios.get(context.rootGetters.server + "/api/boxes/page/" + context.state.page++, context.rootGetters.headers).then((res) => { + context.commit("setBoxes", res.data); + resolve(res.data); + }); + } + }); }, loadFavourites(context) { axios.get(context.rootGetters.server + "/api/boxes/favourites", context.rootGetters.headers).then(res => { diff --git a/src/views/Home.vue b/src/views/Home.vue index d1429a8..9602011 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -106,8 +106,11 @@ export default { this.$store.dispatch("videos/loadMostViewed"); if (this.randomCovers.length == 0) { this.$store.dispatch("albums/loadRandomCovers", 60); - this.$store.dispatch("albums/loadAlbums", true); - this.$store.dispatch("artists/loadArtists", true); + this.$store.dispatch("albums/loadAlbums", true).then(() => { + this.$store.dispatch("artists/loadArtists", true).then(() => { + this.$store.dispatch("boxes/loadBoxes", true); + }); + }); } }, loadNextPage() {