Increase games request limit to 500, refactored load methods

This commit is contained in:
Roman Cervantes 2019-09-03 16:03:20 -07:00
parent 9791f603cf
commit 41a878d5fe

View file

@ -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);
}); });
}
}
}, },
}, },
}; };