}).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);
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 || [];
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`, {
console.error(e);
}
});
- }, [setEpisodes]);
+ }, []);
React.useEffect(() => {
const controller = new AbortController();