mirror of
https://github.com/romancm/gamebrary
synced 2024-11-24 12:13:08 +00:00
Increase games request limit to 500, refactored load methods
This commit is contained in:
parent
9791f603cf
commit
41a878d5fe
1 changed files with 27 additions and 20 deletions
|
@ -115,6 +115,7 @@ export default {
|
|||
gameDetailListIndex: null,
|
||||
gameDetailId: null,
|
||||
gameTagsId: null,
|
||||
queryLimit: 500,
|
||||
};
|
||||
},
|
||||
|
||||
|
@ -132,8 +133,8 @@ export default {
|
|||
mounted() {
|
||||
this.$store.commit('CLEAR_ACTIVE_LIST_INDEX');
|
||||
|
||||
if (this.platform || this.$route.name === 'share-list') {
|
||||
this.loadGameData();
|
||||
if (this.list && this.platform || this.$route.name === 'share-list') {
|
||||
this.load();
|
||||
this.setPageTitle();
|
||||
} else {
|
||||
this.$router.push({ name: 'platforms' });
|
||||
|
@ -213,27 +214,33 @@ export default {
|
|||
});
|
||||
},
|
||||
|
||||
loadGameData() {
|
||||
if (this.list) {
|
||||
const flattenedList = this.list.map(({ games }) => games).flat();
|
||||
const gameList = Array.from(new Set(flattenedList));
|
||||
load() {
|
||||
const flattenedList = this.list.map(({ games }) => games).flat();
|
||||
const dedupedList = Array.from(new Set(flattenedList));
|
||||
|
||||
if (gameList.length > 0) {
|
||||
const chunkedGameList = chunk(gameList, 50);
|
||||
return dedupedList.length > this.queryLimit
|
||||
? this.loadGamesInChunks(dedupedList)
|
||||
: this.loadGames(dedupedList);
|
||||
},
|
||||
|
||||
chunkedGameList.forEach((partialGameList) => {
|
||||
this.loading = true;
|
||||
loadGames(gameList) {
|
||||
this.loading = true;
|
||||
|
||||
this.$store.dispatch('LOAD_GAMES', partialGameList.toString())
|
||||
.then(() => {
|
||||
this.loading = false;
|
||||
})
|
||||
.catch(() => {
|
||||
this.$bus.$emit('TOAST', { message: 'Error loading games', type: 'error' });
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
this.$store.dispatch('LOAD_GAMES', gameList.toString())
|
||||
.then(() => {
|
||||
this.loading = false;
|
||||
})
|
||||
.catch(() => {
|
||||
this.$bus.$emit('TOAST', { message: 'Error loading games', type: 'error' });
|
||||
});
|
||||
},
|
||||
|
||||
loadGamesInChunks(gameList) {
|
||||
const chunkedGameList = chunk(gameList, this.queryLimit);
|
||||
|
||||
chunkedGameList.forEach((gameListChunk) => {
|
||||
this.loadGames(gameListChunk);
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue