]> git.localhorst.tv Git - alttp.git/commitdiff
fix some shit
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 21 Feb 2023 23:28:48 +0000 (00:28 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 21 Feb 2023 23:28:48 +0000 (00:28 +0100)
resources/js/components/episodes/Filter.js
resources/js/components/pages/Schedule.js

index 4855a71b5b09156e56e16eb39fd0958b60c3b3cf..b411f82193574c9036b3ff8d22bbe6d4b99a940e 100644 (file)
@@ -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 || [];
index 2e97af9e4437ba6ee49cb5b646a5ff920e482644..06d471fbeca0d3abacdbfb17627f272a121963b4 100644 (file)
@@ -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();