From 04fc3ea23f267baba4fdaf23809a9f837496562d Mon Sep 17 00:00:00 2001 From: Haseeb Elahi Date: Fri, 24 May 2019 01:49:09 +0500 Subject: [PATCH] Sort list by game release date (#122) --- src/components/Lists/ListSettings.vue | 9 +++++++-- src/i18n/de.js | 1 + src/i18n/en.js | 1 + src/i18n/es.js | 1 + src/i18n/fr.js | 1 + src/i18n/it.js | 1 + src/i18n/pt.js | 1 + src/store/mutations.js | 22 ++++++++++++++++++++++ src/styles/_buttons.scss | 7 +++++++ 9 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/components/Lists/ListSettings.vue b/src/components/Lists/ListSettings.vue index 56ac2a51..03e93b25 100644 --- a/src/components/Lists/ListSettings.vue +++ b/src/components/Lists/ListSettings.vue @@ -66,11 +66,12 @@ @@ -145,7 +146,8 @@ export default { sortOrders: { sortByName: 'fas fa-sort-alpha-down', 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') { this.$store.commit('SORT_LIST_BY_RATING', this.activeListIndex); 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'); } }, diff --git a/src/i18n/de.js b/src/i18n/de.js index 5dac53eb..50f60100 100644 --- a/src/i18n/de.js +++ b/src/i18n/de.js @@ -40,6 +40,7 @@ module.exports = { add: 'Liste hinzufügen', sortByName: 'Alphabetisch', sortByRating: 'Spielbewertung', + sortByReleaseDate: 'Veröffentlichungsdatum', sortByCustom: 'Brauch', delete: 'Liste löschen', moveLeft: 'Geh nach links', diff --git a/src/i18n/en.js b/src/i18n/en.js index bc7fb0a3..95a33e79 100644 --- a/src/i18n/en.js +++ b/src/i18n/en.js @@ -39,6 +39,7 @@ module.exports = { add: 'Add list', sortByName: 'Alphabetically', sortByRating: 'Game rating', + sortByReleaseDate: 'Release date', sortByCustom: 'Custom', delete: 'Delete list', moveLeft: 'Move left', diff --git a/src/i18n/es.js b/src/i18n/es.js index b5ea8bed..0379f29f 100644 --- a/src/i18n/es.js +++ b/src/i18n/es.js @@ -41,6 +41,7 @@ module.exports = { sortByName: 'Alfabéticamente', sortByRating: 'Calificación del juego', sortByCustom: 'Personalizado', + sortByReleaseDate: 'Fecha de lanzamiento', delete: 'Eliminar lista', moveLeft: 'Mover hacia la izquierda', moveRight: 'Mover a la derecha', diff --git a/src/i18n/fr.js b/src/i18n/fr.js index 00b16a34..8588407e 100644 --- a/src/i18n/fr.js +++ b/src/i18n/fr.js @@ -40,6 +40,7 @@ module.exports = { add: 'Ajouter la liste', sortByName: 'Alphabétiquement', sortByRating: 'Classement du jeu', + sortByReleaseDate: 'Date de sortie', sortByCustom: 'Douane', delete: 'Supprimer la liste', moveLeft: 'Se déplacer à gauche', diff --git a/src/i18n/it.js b/src/i18n/it.js index b365a3c9..08cca4fe 100644 --- a/src/i18n/it.js +++ b/src/i18n/it.js @@ -40,6 +40,7 @@ module.exports = { add: 'Aggiungi lista', sortByName: 'In ordine alfabetico', sortByRating: 'Valutazione del gioco', + sortByReleaseDate: 'Data di rilascio', sortByCustom: 'costume', delete: 'Cancella lista', moveLeft: 'Muovere a sinistra', diff --git a/src/i18n/pt.js b/src/i18n/pt.js index dbf25ee3..7f75ce26 100644 --- a/src/i18n/pt.js +++ b/src/i18n/pt.js @@ -40,6 +40,7 @@ module.exports = { add: 'Adicionar lista', sortByName: 'Alfabeticamente', sortByRating: 'Classificação do jogo', + sortByReleaseDate: 'Data de lançamento', sortByCustom: 'personalizadas', delete: 'Excluir lista', moveLeft: 'Mova à esquerda', diff --git a/src/store/mutations.js b/src/store/mutations.js index 13169112..19460632 100755 --- a/src/store/mutations.js +++ b/src/store/mutations.js @@ -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) { const games = state.gameLists[state.platform.code][listIndex].games; diff --git a/src/styles/_buttons.scss b/src/styles/_buttons.scss index f3e31f36..b61f1d24 100644 --- a/src/styles/_buttons.scss +++ b/src/styles/_buttons.scss @@ -60,6 +60,13 @@ button, a.link { font-size: 12px; } + &.xxsmall { + min-height: $iconSmallSize / 3; + min-width: $iconSmallSize / 3; + padding: $gp / 3; + font-size: 10px; + } + &.small { min-height: $iconSmallSize; min-width: $iconSmallSize;