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,
|
gameDetailListIndex: null,
|
||||||
gameDetailId: null,
|
gameDetailId: null,
|
||||||
gameTagsId: null,
|
gameTagsId: null,
|
||||||
|
queryLimit: 500,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -132,8 +133,8 @@ export default {
|
||||||
mounted() {
|
mounted() {
|
||||||
this.$store.commit('CLEAR_ACTIVE_LIST_INDEX');
|
this.$store.commit('CLEAR_ACTIVE_LIST_INDEX');
|
||||||
|
|
||||||
if (this.platform || this.$route.name === 'share-list') {
|
if (this.list && this.platform || this.$route.name === 'share-list') {
|
||||||
this.loadGameData();
|
this.load();
|
||||||
this.setPageTitle();
|
this.setPageTitle();
|
||||||
} else {
|
} else {
|
||||||
this.$router.push({ name: 'platforms' });
|
this.$router.push({ name: 'platforms' });
|
||||||
|
@ -213,27 +214,33 @@ export default {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
loadGameData() {
|
load() {
|
||||||
if (this.list) {
|
|
||||||
const flattenedList = this.list.map(({ games }) => games).flat();
|
const flattenedList = this.list.map(({ games }) => games).flat();
|
||||||
const gameList = Array.from(new Set(flattenedList));
|
const dedupedList = Array.from(new Set(flattenedList));
|
||||||
|
|
||||||
if (gameList.length > 0) {
|
return dedupedList.length > this.queryLimit
|
||||||
const chunkedGameList = chunk(gameList, 50);
|
? this.loadGamesInChunks(dedupedList)
|
||||||
|
: this.loadGames(dedupedList);
|
||||||
|
},
|
||||||
|
|
||||||
chunkedGameList.forEach((partialGameList) => {
|
loadGames(gameList) {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
|
|
||||||
this.$store.dispatch('LOAD_GAMES', partialGameList.toString())
|
this.$store.dispatch('LOAD_GAMES', gameList.toString())
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
this.$bus.$emit('TOAST', { message: 'Error loading games', type: 'error' });
|
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