mirror of
https://github.com/romancm/gamebrary
synced 2024-11-24 20:23:06 +00:00
filtered platforms getter
This commit is contained in:
parent
e6892b70f9
commit
a84be79a9a
1 changed files with 25 additions and 0 deletions
|
@ -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],
|
||||
|
||||
|
|
Loading…
Reference in a new issue