From a84be79a9adfdf4f791b3a71ba9f14d33cccc537 Mon Sep 17 00:00:00 2001 From: Gamebrary Date: Mon, 24 Aug 2020 21:21:56 -0700 Subject: [PATCH] filtered platforms getter --- src/store/getters.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/store/getters.js b/src/store/getters.js index 6db301d7..730a507e 100755 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -1,4 +1,6 @@ +import { PLATFORM_FILTER_FIELDS } from '@/constants'; import platforms from '@/platforms'; +import orderby from 'lodash.orderby'; export default { gamePlatforms: (state) => { @@ -9,6 +11,29 @@ export default { return platforms.filter(({ id }) => id !== state.platform.id && gamePlatforms.includes(id)); }, + filteredPlatforms: (state) => { + const filterField = state.settings.platformsFilterField || null; + const sortField = state.settings.platformsSortField || 'generation'; + + let filteredPlatforms = []; + + if (filterField === 'popular') { + filteredPlatforms = state.platforms.filter(({ popular }) => popular); + } else { + filteredPlatforms = filterField && PLATFORM_FILTER_FIELDS.includes(filterField) + ? state.platforms.filter(({ category }) => category === filterField) + : state.platforms; + } + + const sortedPlatforms = orderby(filteredPlatforms, sortField); + + const reverseOrder = ['releaseYear', 'generation'].includes(sortField); + + return reverseOrder + ? sortedPlatforms.reverse() + : sortedPlatforms; + }, + // eslint-disable-next-line activeList: ({ gameLists, platform, activeListIndex }) => gameLists[platform.code][activeListIndex],