Skip to content

Commit

Permalink
add getSeason, getEpisode getters, replaced getShowByName with getSho…
Browse files Browse the repository at this point in the history
…wByTitle, added better comments and fixed merging detailed (#4979)
  • Loading branch information
OmgImAlexis authored Aug 28, 2018
1 parent ef7efb3 commit 82366b3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
36 changes: 29 additions & 7 deletions themes-default/slim/src/store/modules/shows.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Vue from 'vue';
import { ADD_SHOW } from '../mutation-types';

const state = {
Expand All @@ -6,19 +7,40 @@ const state = {

const mutations = {
[ADD_SHOW](state, show) {
const { shows } = state;
const showExists = shows.filter(({ id, indexer }) => id[indexer] === show.id[indexer]).length === 1;
if (showExists) {
state.shows[shows.indexOf(showExists)] = show;
} else {
const existingShow = state.shows.find(({ id, indexer }) => Number(show.id[show.indexer]) === Number(id[indexer]));

if (!existingShow) {
console.debug(`Adding ${show.title || show.indexer + String(show.id)} as it wasn't found in the shows array`, show);
state.shows.push(show);
return;
}

// Merge new show object over old one
// this allows detailed queries to update the record
// without the non-detailed removing the extra data
console.debug(`Found ${show.title || show.indexer + String(show.id)} in shows array attempting merge`);
const newShow = {
...existingShow,
...show
};

// Update state
Vue.set(state.shows, state.shows.indexOf(existingShow), newShow);
console.debug(`Merged ${newShow.title || newShow.indexer + String(newShow.id)}`, newShow);
}
};

const getters = {
getShowById: state => ({ id, indexer }) => state.shows.find(show => Number(show.id[indexer]) === Number(id)),
getShowByName: state => title => state.shows.find(show => show.title === title)
getShowByTitle: state => title => state.shows.find(show => show.title === title),
getSeason: state => ({ id, indexer, season }) => {
const show = state.shows.find(show => Number(show.id[indexer]) === Number(id));
return show && show.seasons ? show.seasons[season] : undefined;
},
getEpisode: state => ({ id, indexer, season, episode }) => {
const show = state.shows.find(show => Number(show.id[indexer]) === Number(id));
return show && show.seasons && show.seasons[season] ? show.seasons[season][episode] : undefined;
}
};

const actions = {
Expand All @@ -35,7 +57,7 @@ const actions = {
getShows(context, shows) {
const { commit, dispatch } = context;

// If no shows are provided get all of them
// If no shows are provided get the first 1000
if (!shows) {
const params = {
limit: 1000
Expand Down
2 changes: 1 addition & 1 deletion themes/dark/assets/js/vendors.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion themes/light/assets/js/vendors.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 82366b3

Please sign in to comment.