From: Daniel Karbach Date: Tue, 21 Feb 2023 23:28:48 +0000 (+0100) Subject: fix some shit X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=c8bcea2a3093707b14fd655f3b284b2d245b483f;p=alttp.git fix some shit --- diff --git a/resources/js/components/episodes/Filter.js b/resources/js/components/episodes/Filter.js index 4855a71..b411f82 100644 --- a/resources/js/components/episodes/Filter.js +++ b/resources/js/components/episodes/Filter.js @@ -18,13 +18,6 @@ const Filter = ({ filter, setFilter }) => { }).then(response => { const newEvents = response.data || []; setEvents(newEvents); - setFilter(filter => { - const eventFilter = filter.event || []; - return { - ...filter, - event: eventFilter.filter(newEvents.find(id => newEvents.includes(id))), - }; - }); }).catch(e => { if (!axios.isCancel(e)) { console.error(e); @@ -33,23 +26,22 @@ const Filter = ({ filter, setFilter }) => { return () => { controller.abort(); }; - }, [setEvents, setFilter]); + }, []); const toggleEvent = React.useCallback(event => { - setFilter(filter => { - const eventFilter = filter.event || []; - if (!eventFilter.includes(event.id)) { - return { - ...filter, - event: [...eventFilter, event.id], - }; - } - return { + const eventFilter = filter.event || []; + if (eventFilter.includes(event.id)) { + setFilter({ ...filter, - event: eventFilter.filter(id => id !== event.id), - }; - }); - }, [setFilter]); + event: eventFilter.filter(id => id !== event.id && events.find(e => e.id === id)), + }); + } else { + setFilter({ + ...filter, + event: [...eventFilter, event.id], + }); + } + }, [events, filter, setFilter]); const isEventSelected = React.useCallback(event => { const eventFilter = filter.event || []; diff --git a/resources/js/components/pages/Schedule.js b/resources/js/components/pages/Schedule.js index 2e97af9..06d471f 100644 --- a/resources/js/components/pages/Schedule.js +++ b/resources/js/components/pages/Schedule.js @@ -30,7 +30,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 +47,7 @@ const Schedule = () => { console.error(e); } }); - }, [setEpisodes]); + }, []); React.useEffect(() => { const controller = new AbortController();