diff --git a/pages/seasons.vue b/pages/seasons.vue index 055ea10..10d18ce 100644 --- a/pages/seasons.vue +++ b/pages/seasons.vue @@ -8,7 +8,7 @@ @@ -165,9 +165,7 @@ {name: 'Spring', value: 'spring'}, {name: 'Summer', value: 'summer'}, {name: 'Fall', value: 'fall'} - ], - currentSeason: this.getCurrentSeason().season, - currentYear: 1900 + (new Date()).getYear() + ] } }, computed: { @@ -214,14 +212,6 @@ : 'episode' }, refreshSeason () { - const year = this.currentYear - const season = this.currentSeason.value - - this.$store.commit('setCurrentSeason', { - year: year, - season: season - }) - this.$store.dispatch('refreshSeasons') }, openModal (title, text) { @@ -232,25 +222,6 @@ this.modal = true }, - getCurrentSeason () { - const date = new Date() - - // Get current year - const year = 1900 + date.getYear() - - // Get current month - const month = 1 + date.getMonth() // I am a weak person that like 1-indexed things - - if (month > 0 && month < 4) { - return {season: 'winter', year: year} - } else if (month > 3 && month < 7) { - return {season: 'spring', year: year} - } else if (month > 6 && month < 10) { - return {season: 'summer', year: year} - } else if (month > 9 && month < 13) { - return {season: 'fall', year: year} - } - }, showChoices (name) { this.choiceTitle = name this.$store.commit('setAddToChoice', true) diff --git a/store/index.js b/store/index.js index ef05cfe..eb2daf5 100644 --- a/store/index.js +++ b/store/index.js @@ -216,19 +216,6 @@ const store = new Vuex.Store({ } }, actions: { - nuxtServerInit ({commit}) { - const now = new Date() - const year = now.getFullYear() - const month = now.getMonth() - let season - - if (month > 0 && month < 4) season = 'winter' - else if (month > 3 && month < 7) season = 'spring' - else if (month > 6 && month < 10) season = 'summer' - else if (month > 9 && month < 13) season = 'fall' - - commit('setCurrentSeason', {year, season}) - }, async init ({commit, dispatch}) { if (!started) { started = true @@ -313,9 +300,22 @@ const store = new Vuex.Store({ } } }, - async seasonsInit ({state, commit}) { + async seasonsInit ({commit}) { console.log('[INIT] Seasons') - const {data} = await axios.get(`seasons.json?year=${state.year}&season=${state.season}`) + + const now = new Date() + const year = now.getFullYear() + const month = now.getMonth() + 1 + let season + + if (month > 0 && month < 4) season = 'winter' + else if (month > 3 && month < 7) season = 'spring' + else if (month > 6 && month < 10) season = 'summer' + else if (month > 9 && month < 13) season = 'fall' + + commit('setCurrentSeason', {year, season}) + + const {data} = await axios.get(`seasons.json?year=${year}&season=${season}`) commit('setSeasons', data) }, @@ -402,7 +402,7 @@ const store = new Vuex.Store({ log(`Refreshing Seasons...`) const year = state.year - const season = state.season + const season = state.season.value || state.season if (year >= 2010 && (year <= (new Date()).getYear() + 1901)) { commit('emptySeasons')