Sort list by game release date (#122)

This commit is contained in:
Haseeb Elahi 2019-05-24 01:49:09 +05:00 committed by Roman Cervantes
parent 3e3d33efdb
commit 04fc3ea23f
9 changed files with 42 additions and 2 deletions

View file

@ -66,11 +66,12 @@
<button <button
v-for="(icon, sortOrder) in sortOrders" v-for="(icon, sortOrder) in sortOrders"
:key="sortOrder" :key="sortOrder"
class="xsmall primary" class="xxsmall primary"
:class="{ hollow: activeList.sortOrder !== sortOrder }" :class="{ hollow: activeList.sortOrder !== sortOrder }"
@click="setListSort(sortOrder)" @click="setListSort(sortOrder)"
> >
<i :class="icon" /> <i :class="icon" />
<br>
{{ $t(`list.${sortOrder}`) }} {{ $t(`list.${sortOrder}`) }}
</button> </button>
</div> </div>
@ -145,7 +146,8 @@ export default {
sortOrders: { sortOrders: {
sortByName: 'fas fa-sort-alpha-down', sortByName: 'fas fa-sort-alpha-down',
sortByRating: 'fas fa-sort-numeric-up', sortByRating: 'fas fa-sort-numeric-up',
sortByCustom: 'fas fa-sort-custom', sortByReleaseDate: 'fas fa-calendar-alt',
sortByCustom: 'fas fa-sort',
}, },
}; };
}, },
@ -239,6 +241,9 @@ export default {
} else if (sortOrder === 'sortByRating') { } else if (sortOrder === 'sortByRating') {
this.$store.commit('SORT_LIST_BY_RATING', this.activeListIndex); this.$store.commit('SORT_LIST_BY_RATING', this.activeListIndex);
this.$emit('update', 'List sorted by game rating'); this.$emit('update', 'List sorted by game rating');
} else if (sortOrder === 'sortByReleaseDate') {
this.$store.commit('SORT_LIST_BY_RELEASE_DATE', this.activeListIndex);
this.$emit('update', 'List sorted by game rating');
} }
}, },

View file

@ -40,6 +40,7 @@ module.exports = {
add: 'Liste hinzufügen', add: 'Liste hinzufügen',
sortByName: 'Alphabetisch', sortByName: 'Alphabetisch',
sortByRating: 'Spielbewertung', sortByRating: 'Spielbewertung',
sortByReleaseDate: 'Veröffentlichungsdatum',
sortByCustom: 'Brauch', sortByCustom: 'Brauch',
delete: 'Liste löschen', delete: 'Liste löschen',
moveLeft: 'Geh nach links', moveLeft: 'Geh nach links',

View file

@ -39,6 +39,7 @@ module.exports = {
add: 'Add list', add: 'Add list',
sortByName: 'Alphabetically', sortByName: 'Alphabetically',
sortByRating: 'Game rating', sortByRating: 'Game rating',
sortByReleaseDate: 'Release date',
sortByCustom: 'Custom', sortByCustom: 'Custom',
delete: 'Delete list', delete: 'Delete list',
moveLeft: 'Move left', moveLeft: 'Move left',

View file

@ -41,6 +41,7 @@ module.exports = {
sortByName: 'Alfabéticamente', sortByName: 'Alfabéticamente',
sortByRating: 'Calificación del juego', sortByRating: 'Calificación del juego',
sortByCustom: 'Personalizado', sortByCustom: 'Personalizado',
sortByReleaseDate: 'Fecha de lanzamiento',
delete: 'Eliminar lista', delete: 'Eliminar lista',
moveLeft: 'Mover hacia la izquierda', moveLeft: 'Mover hacia la izquierda',
moveRight: 'Mover a la derecha', moveRight: 'Mover a la derecha',

View file

@ -40,6 +40,7 @@ module.exports = {
add: 'Ajouter la liste', add: 'Ajouter la liste',
sortByName: 'Alphabétiquement', sortByName: 'Alphabétiquement',
sortByRating: 'Classement du jeu', sortByRating: 'Classement du jeu',
sortByReleaseDate: 'Date de sortie',
sortByCustom: 'Douane', sortByCustom: 'Douane',
delete: 'Supprimer la liste', delete: 'Supprimer la liste',
moveLeft: 'Se déplacer à gauche', moveLeft: 'Se déplacer à gauche',

View file

@ -40,6 +40,7 @@ module.exports = {
add: 'Aggiungi lista', add: 'Aggiungi lista',
sortByName: 'In ordine alfabetico', sortByName: 'In ordine alfabetico',
sortByRating: 'Valutazione del gioco', sortByRating: 'Valutazione del gioco',
sortByReleaseDate: 'Data di rilascio',
sortByCustom: 'costume', sortByCustom: 'costume',
delete: 'Cancella lista', delete: 'Cancella lista',
moveLeft: 'Muovere a sinistra', moveLeft: 'Muovere a sinistra',

View file

@ -40,6 +40,7 @@ module.exports = {
add: 'Adicionar lista', add: 'Adicionar lista',
sortByName: 'Alfabeticamente', sortByName: 'Alfabeticamente',
sortByRating: 'Classificação do jogo', sortByRating: 'Classificação do jogo',
sortByReleaseDate: 'Data de lançamento',
sortByCustom: 'personalizadas', sortByCustom: 'personalizadas',
delete: 'Excluir lista', delete: 'Excluir lista',
moveLeft: 'Mova à esquerda', moveLeft: 'Mova à esquerda',

View file

@ -117,6 +117,28 @@ export default {
}); });
}, },
SORT_LIST_BY_RELEASE_DATE(state, listIndex) {
const games = state.gameLists[state.platform.code][listIndex].games;
games.sort((a, b) => {
const gameA = state.games[a] && state.games[a].release_dates
&& state.games[a].release_dates.length > 0
? state.games[a].release_dates.find(releaseDate =>
releaseDate.platform === state.platform.id).date : 0;
const gameB = state.games[b] && state.games[b].release_dates
&& state.games[b].release_dates.length > 0
? state.games[b].release_dates.find(releaseDate =>
releaseDate.platform === state.platform.id).date : 0;
if (gameA > gameB) {
return -1;
}
return gameA < gameB ? 1 : 0;
});
},
SORT_LIST_BY_RATING(state, listIndex) { SORT_LIST_BY_RATING(state, listIndex) {
const games = state.gameLists[state.platform.code][listIndex].games; const games = state.gameLists[state.platform.code][listIndex].games;

View file

@ -60,6 +60,13 @@ button, a.link {
font-size: 12px; font-size: 12px;
} }
&.xxsmall {
min-height: $iconSmallSize / 3;
min-width: $iconSmallSize / 3;
padding: $gp / 3;
font-size: 10px;
}
&.small { &.small {
min-height: $iconSmallSize; min-height: $iconSmallSize;
min-width: $iconSmallSize; min-width: $iconSmallSize;