filtered platforms getter

This commit is contained in:
Gamebrary 2020-08-24 21:21:56 -07:00
parent e6892b70f9
commit a84be79a9a

View file

@ -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],