mirror of https://github.com/Kylart/KawAnime.git
Fixed seasons init and refresh
This commit is contained in:
parent
070b2f2918
commit
c7770ecab0
|
@ -8,7 +8,7 @@
|
|||
<v-col md3 xs12 class="season-container">
|
||||
<v-select
|
||||
v-bind:items="seasonChoices"
|
||||
v-model="currentSeason"
|
||||
v-model="$store.state.season"
|
||||
label="Season"
|
||||
dark
|
||||
item-text="name"
|
||||
|
@ -18,7 +18,7 @@
|
|||
<v-text-field name="input-year"
|
||||
type="number" min="2010"
|
||||
label="Year"
|
||||
v-model="currentYear"
|
||||
v-model="$store.state.year"
|
||||
dark>
|
||||
</v-text-field>
|
||||
</v-col>
|
||||
|
@ -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)
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in New Issue