mirror of
https://github.com/Xevion/the-office.git
synced 2025-12-17 10:13:30 -06:00
fix Vuex store data being re-fetched with check, fix .loaded assignment (undefined vs null moment), remove SeasonList popover.show idiocy, Episode.vue comments
This commit is contained in:
@@ -71,13 +71,14 @@ export default {
|
|||||||
Skeleton,
|
Skeleton,
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
// When page loads directly on this Episode initially, fetch data
|
||||||
this.fetch();
|
this.fetch();
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
|
// When route changes, fetch data for current Episode route
|
||||||
$route() {
|
$route() {
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
this.fetch();
|
this.fetch();
|
||||||
// this.$store.dispatch(types.FETCH_EPISODE, {season: this.params.season, episode: this.params.episode})
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -102,8 +103,8 @@ export default {
|
|||||||
computed: {
|
computed: {
|
||||||
episode() {
|
episode() {
|
||||||
return this.$store.getters.getEpisode(this.params.season, this.params.episode)
|
return this.$store.getters.getEpisode(this.params.season, this.params.episode)
|
||||||
// return this.$store.state.quoteData[this.params.season - 1].episodes[this.params.episode - 1];
|
|
||||||
},
|
},
|
||||||
|
// Shorthand - literally useless, why does everything to have such long prefixes in dot notation
|
||||||
params() {
|
params() {
|
||||||
return this.$route.params
|
return this.$route.params
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
:id="`s-${season.season_id}-ep-${episode.episode_id}`">
|
:id="`s-${season.season_id}-ep-${episode.episode_id}`">
|
||||||
Episode {{ episode.episode_id }} - "{{ episode.title }}"
|
Episode {{ episode.episode_id }} - "{{ episode.title }}"
|
||||||
</b-list-group-item>
|
</b-list-group-item>
|
||||||
<b-popover show="true" :key="`bpop-${episode.episode_id}`" triggers="hover"
|
<b-popover :key="`bpop-${episode.episode_id}`" triggers="hover"
|
||||||
placement="right" delay="25" :target="`s-${season.season_id}-ep-${episode.episode_id}`">
|
placement="right" delay="25" :target="`s-${season.season_id}-ep-${episode.episode_id}`">
|
||||||
<template v-slot:title>
|
<template v-slot:title>
|
||||||
{{ episode.title }}
|
{{ episode.title }}
|
||||||
|
|||||||
@@ -30,7 +30,9 @@ export default new Vuex.Store({
|
|||||||
const s = payload.season - 1;
|
const s = payload.season - 1;
|
||||||
const e = payload.episode - 1;
|
const e = payload.episode - 1;
|
||||||
state.quoteData[s].episodes[e] = Object.assign(state.quoteData[s].episodes[e], payload.episodeData);
|
state.quoteData[s].episodes[e] = Object.assign(state.quoteData[s].episodes[e], payload.episodeData);
|
||||||
if (payload.episodeData.scenes !== null)
|
|
||||||
|
// If the episodeData has scenes, it means that this is a full episode data merge - mark it as 'loaded'
|
||||||
|
if (payload.episodeData.scenes !== undefined)
|
||||||
state.quoteData[s].episodes[e].loaded = true;
|
state.quoteData[s].episodes[e].loaded = true;
|
||||||
},
|
},
|
||||||
[types.SET_PRELOADED](state, status) {
|
[types.SET_PRELOADED](state, status) {
|
||||||
@@ -39,13 +41,19 @@ export default new Vuex.Store({
|
|||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
// Perform async API call to fetch specific Episode data
|
// Perform async API call to fetch specific Episode data
|
||||||
[types.FETCH_EPISODE]({commit}, payload) {
|
[types.FETCH_EPISODE](context, payload) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
// Don't re-fetch API data if it's already loaded
|
||||||
|
if(context.getters.isFetched(payload.season, payload.episode)) {
|
||||||
|
resolve()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const path = `${process.env.VUE_APP_API_URL}/api/episode/${payload.season}/${payload.episode}/`;
|
const path = `${process.env.VUE_APP_API_URL}/api/episode/${payload.season}/${payload.episode}/`;
|
||||||
axios.get(path)
|
axios.get(path)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
// Push episode data
|
// Push episode data
|
||||||
commit(types.MERGE_EPISODE, {
|
context.commit(types.MERGE_EPISODE, {
|
||||||
season: payload.season,
|
season: payload.season,
|
||||||
episode: payload.episode,
|
episode: payload.episode,
|
||||||
episodeData: res.data
|
episodeData: res.data
|
||||||
@@ -86,7 +94,7 @@ export default new Vuex.Store({
|
|||||||
// Check whether a episode has been fetched yet
|
// Check whether a episode has been fetched yet
|
||||||
isFetched: (state) => (season, episode) => {
|
isFetched: (state) => (season, episode) => {
|
||||||
const ep = state.quoteData[season - 1].episodes[episode - 1];
|
const ep = state.quoteData[season - 1].episodes[episode - 1];
|
||||||
return ep !== null && ep.loaded;
|
return ep.loaded;
|
||||||
},
|
},
|
||||||
// Get the number of episodes present for a given season
|
// Get the number of episodes present for a given season
|
||||||
getEpisodeCount: (state) => (season) => {
|
getEpisodeCount: (state) => (season) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user