X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;ds=sidebyside;f=resources%2Fjs%2Fcomponents%2Fpages%2FSchedule.js;h=10b4b4977efc925ab286326075f0739bc73731c3;hb=16bf08bb5cd6118704346f642a491d37c998ef54;hp=2e97af9e4437ba6ee49cb5b646a5ff920e482644;hpb=1555e7984ae682c7c7cddb5026275317742eaef3;p=alttp.git
diff --git a/resources/js/components/pages/Schedule.js b/resources/js/components/pages/Schedule.js
index 2e97af9..10b4b49 100644
--- a/resources/js/components/pages/Schedule.js
+++ b/resources/js/components/pages/Schedule.js
@@ -1,20 +1,27 @@
import axios from 'axios';
import moment from 'moment';
+import PropTypes from 'prop-types';
import React from 'react';
-import { Container } from 'react-bootstrap';
+import { Alert, Container } from 'react-bootstrap';
import { Helmet } from 'react-helmet';
import { useTranslation } from 'react-i18next';
+import toastr from 'toastr';
import CanonicalLinks from '../common/CanonicalLinks';
import ErrorBoundary from '../common/ErrorBoundary';
import Filter from '../episodes/Filter';
import List from '../episodes/List';
+import RestreamDialog from '../episodes/RestreamDialog';
+import { withUser } from '../../helpers/UserContext';
-const Schedule = () => {
- const [ahead, setAhead] = React.useState(6);
- const [behind, setBehind] = React.useState(0);
+const Schedule = ({ user }) => {
+ const [ahead] = React.useState(14);
+ const [behind] = React.useState(0);
const [episodes, setEpisodes] = React.useState([]);
const [filter, setFilter] = React.useState({});
+ const [restreamChannel, setRestreamChannel] = React.useState(null);
+ const [restreamEpisode, setRestreamEpisode] = React.useState(null);
+ const [showRestreamDialog, setShowRestreamDialog] = React.useState(false);
const { t } = useTranslation();
@@ -30,7 +37,7 @@ const Schedule = () => {
const updateFilter = React.useCallback(newFilter => {
localStorage.setItem('episodes.filter.schedule', JSON.stringify(newFilter));
setFilter(newFilter);
- }, [setFilter]);
+ }, []);
const fetchEpisodes = React.useCallback((controller, ahead, behind, filter) => {
axios.get(`/api/episodes`, {
@@ -47,7 +54,64 @@ const Schedule = () => {
console.error(e);
}
});
- }, [setEpisodes]);
+ }, []);
+
+ const onAddRestream = React.useCallback(episode => {
+ setRestreamEpisode(episode);
+ setShowRestreamDialog(true);
+ }, []);
+
+ const onAddRestreamSubmit = React.useCallback(async values => {
+ try {
+ const response = await axios.post(
+ `/api/episodes/${values.episode_id}/add-restream`, values);
+ const newEpisode = response.data;
+ setEpisodes(episodes => episodes.map(episode =>
+ episode.id === newEpisode.id ? {
+ ...episode,
+ ...newEpisode,
+ } : episode
+ ));
+ toastr.success(t('episodes.restreamDialog.addSuccess'));
+ } catch (e) {
+ toastr.error(t('episodes.restreamDialog.addError'));
+ throw e;
+ }
+ setRestreamEpisode(null);
+ setShowRestreamDialog(false);
+ }, []);
+
+ const onRemoveRestream = React.useCallback(async (episode, channel) => {
+ try {
+ const response = await axios.post(
+ `/api/episodes/${episode.id}/remove-restream`, { channel_id: channel.id });
+ const newEpisode = response.data;
+ setEpisodes(episodes => episodes.map(episode =>
+ episode.id === newEpisode.id ? {
+ ...episode,
+ ...newEpisode,
+ } : episode
+ ));
+ toastr.success(t('episodes.restreamDialog.removeSuccess'));
+ setRestreamChannel(null);
+ setRestreamEpisode(null);
+ setShowRestreamDialog(false);
+ } catch (e) {
+ toastr.error(t('episodes.restreamDialog.removeError'));
+ }
+ }, []);
+
+ const onEditRestream = React.useCallback((episode, channel) => {
+ setRestreamChannel(channel);
+ setRestreamEpisode(episode);
+ setShowRestreamDialog(true);
+ }, []);
+
+ const onHideRestreamDialog = React.useCallback(() => {
+ setShowRestreamDialog(false);
+ setRestreamChannel(null);
+ setRestreamEpisode(null);
+ }, []);
React.useEffect(() => {
const controller = new AbortController();
@@ -67,12 +131,39 @@ const Schedule = () => {