Skip to content

Commit

Permalink
Fix live filtering on presets (#1098)
Browse files Browse the repository at this point in the history
* Fix live filtering on presets

* I should sleep...
  • Loading branch information
harshithmohan authored Oct 10, 2024
1 parent 9c9e89b commit 1898c34
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
35 changes: 25 additions & 10 deletions src/components/Dialogs/FilterPresetsModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useEffect, useMemo, useRef, useState } from 'react';
import { useDispatch } from 'react-redux';
import { Link } from 'react-router-dom';
import { mdiLoading, mdiMagnify } from '@mdi/js';
import { Icon } from '@mdi/react';
Expand All @@ -9,6 +10,8 @@ import { useDebounceValue } from 'usehooks-ts';
import Input from '@/components/Input/Input';
import ModalPanel from '@/components/Panels/ModalPanel';
import { useFiltersQuery, useSubFiltersQuery } from '@/core/react-query/filter/queries';
import { resetActiveFilter } from '@/core/slices/collection';
import useEventCallback from '@/hooks/useEventCallback';

import type { CollectionFilterType } from '@/core/types/api/collection';

Expand All @@ -32,16 +35,28 @@ const TabButton = (
);
};

const Item = ({ item, onClose }: { item: CollectionFilterType, onClose: () => void }) => (
<div
// TODO: Disable selecting empty filter presets for now. Remove the disable condition once editing presets is possible
className={cx('flex justify-between pb-1 pr-4 font-semibold', item.Size === 0 && 'pointer-events-none opacity-65')}
key={item.IDs.ID}
>
<Link to={`/webui/collection/filter/${item.IDs.ID}`} onClick={onClose}>{item.Name}</Link>
<span className="text-panel-text-important">{item.Size}</span>
</div>
);
const Item = ({ item, onClose }: { item: CollectionFilterType, onClose: () => void }) => {
const dispatch = useDispatch();

const handleClose = useEventCallback(() => {
dispatch(resetActiveFilter());
onClose();
});

return (
<div
// TODO: Disable selecting empty filter presets for now. Remove the disable condition once editing presets is possible
className={cx(
'flex justify-between pb-1 pr-4 font-semibold',
item.Size === 0 && 'pointer-events-none opacity-65',
)}
key={item.IDs.ID}
>
<Link to={`/webui/collection/filter/${item.IDs.ID}`} onClick={handleClose}>{item.Name}</Link>
<span className="text-panel-text-important">{item.Size}</span>
</div>
);
};

const SidePanel = (
props: { activeFilter: number, activeTab: string, filterId: number, onClose: () => void, title: string },
Expand Down
9 changes: 4 additions & 5 deletions src/pages/collection/Collection.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useMemo, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { useParams } from 'react-router';
import { useLocation, useNavigate, useSearchParams } from 'react-router-dom';
import { useNavigate, useSearchParams } from 'react-router-dom';
import cx from 'classnames';
import { cloneDeep, toNumber } from 'lodash';
import { useDebounceValue, useToggle } from 'usehooks-ts';
Expand Down Expand Up @@ -88,7 +88,6 @@ function Collection() {

const dispatch = useDispatch();
const navigate = useNavigate();
const location = useLocation();

const [searchParams, setSearchParams] = useSearchParams();
const groupSearch = useMemo(() => searchParams.get('q') ?? '', [searchParams]);
Expand All @@ -105,7 +104,7 @@ function Collection() {

const activeFilterFromStore = useSelector((state: RootState) => state.collection.activeFilter) as FilterCondition;
const activeFilter = useMemo(() => {
if (filterId !== 'live') return undefined;
if (!filterId) return undefined;
return activeFilterFromStore;
}, [activeFilterFromStore, filterId]);
const filterQuery = useFilterQuery(toNumber(filterId!), !!filterId && filterId !== 'live');
Expand All @@ -121,15 +120,15 @@ function Collection() {
const [timelineSeries, setTimelineSeries] = useState<SeriesType[]>([]);

const handleFilterSidebarToggle = useEventCallback(() => {
if (!showFilterSidebar && location.pathname !== '/webui/collection/filter/live') {
if (!showFilterSidebar && !filterId) {
dispatch(resetFilter());
navigate('/webui/collection/filter/live');
}
toggleFilterSidebar();
});

useEffect(() => {
if (filterId !== 'live' && showFilterSidebar) toggleFilterSidebar();
if (!filterId && showFilterSidebar) toggleFilterSidebar();
}, [filterId, showFilterSidebar, toggleFilterSidebar]);

const { mutate: patchSettings } = usePatchSettingsMutation();
Expand Down

0 comments on commit 1898c34

Please sign in to comment.