2016-11-23 11:59:22 +01:00
|
|
|
import http from 'axios';
|
2016-10-10 10:57:39 +02:00
|
|
|
|
2017-08-05 18:40:36 +02:00
|
|
|
export function loadItems({state, commit}, response) {
|
2016-10-10 10:57:39 +02:00
|
|
|
commit('SET_LOADING', true);
|
2017-08-05 18:40:36 +02:00
|
|
|
http(`${config.api}/items/${response.name}/${state.userFilter}/${state.userSortDirection}`).then(value => {
|
2016-10-10 10:57:39 +02:00
|
|
|
const {data, next_page_url} = value.data;
|
|
|
|
|
|
|
|
commit('SET_ITEMS', data);
|
|
|
|
commit('SET_PAGINATOR', next_page_url);
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
commit('SET_LOADING', false);
|
|
|
|
}, 500);
|
|
|
|
}, error => {
|
2017-08-05 18:40:36 +02:00
|
|
|
if(error.status === 404) {
|
2016-10-10 10:57:39 +02:00
|
|
|
window.location.href = config.url;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function loadMoreItems({commit}, next_page_url) {
|
|
|
|
commit('SET_CLICKED_LOADING', true);
|
2016-11-23 11:59:22 +01:00
|
|
|
http(next_page_url).then(value => {
|
2016-10-10 10:57:39 +02:00
|
|
|
const {data, next_page_url} = value.data;
|
|
|
|
|
|
|
|
commit('SET_PAGINATOR', next_page_url);
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
commit('PUSH_TO_ITEMS', data);
|
|
|
|
commit('SET_CLICKED_LOADING', false);
|
|
|
|
}, 500);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setSearchTitle({commit}, title) {
|
|
|
|
commit('SET_SEARCH_TITLE', title);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setColorScheme({commit}, color) {
|
2017-04-11 08:45:08 +02:00
|
|
|
document.body.classList.remove('dark', 'light');
|
|
|
|
|
2016-10-10 10:57:39 +02:00
|
|
|
localStorage.setItem('color', color);
|
2017-04-11 08:45:08 +02:00
|
|
|
document.body.classList.add(color);
|
|
|
|
|
2016-10-10 10:57:39 +02:00
|
|
|
commit('SET_COLOR_SCHEME', color);
|
2016-11-28 08:50:09 +01:00
|
|
|
}
|
|
|
|
|
2017-04-11 15:46:19 +02:00
|
|
|
export function setPageTitle({}, title = null) {
|
|
|
|
if( ! title) {
|
|
|
|
document.title = 'Flox';
|
|
|
|
} else {
|
|
|
|
document.title = `${title} - Flox`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-28 08:50:09 +01:00
|
|
|
export function fetchEpisodes({commit}, data) {
|
2016-11-28 11:51:48 +01:00
|
|
|
commit('SET_LOADING_MODAL_DATA', true);
|
2016-11-28 08:50:09 +01:00
|
|
|
http(`${config.api}/episodes/${data.tmdb_id}`).then(response => {
|
2017-02-21 21:20:42 +01:00
|
|
|
const nextEpisode = response.data.next_episode;
|
|
|
|
|
2016-11-28 08:50:09 +01:00
|
|
|
commit('SET_MODAL_DATA', {
|
|
|
|
title: data.title,
|
2016-12-12 09:18:13 +01:00
|
|
|
episodes: response.data.episodes,
|
|
|
|
spoiler: response.data.spoiler
|
2016-11-28 08:50:09 +01:00
|
|
|
});
|
2016-11-28 11:51:48 +01:00
|
|
|
|
2017-02-21 21:20:42 +01:00
|
|
|
commit('SET_LOADING_MODAL_DATA', false);
|
|
|
|
|
|
|
|
if(nextEpisode) {
|
|
|
|
commit('SET_SEASON_ACTIVE_MODAL', nextEpisode.season_number);
|
|
|
|
|
|
|
|
// Scroll to next episode
|
|
|
|
setTimeout(() => {
|
|
|
|
const container = document.querySelector('.modal-content');
|
|
|
|
const episode = document.querySelector(`[data-episode='${nextEpisode.episode_number}']`);
|
|
|
|
|
|
|
|
container.scrollTop = episode.offsetTop - episode.offsetHeight;
|
|
|
|
}, 10);
|
|
|
|
}
|
2016-11-28 08:50:09 +01:00
|
|
|
});
|
2016-10-10 10:57:39 +02:00
|
|
|
}
|