diff --git a/web/src/components/filter/ReviewFilterGroup.tsx b/web/src/components/filter/ReviewFilterGroup.tsx index 004fe5527c..bea816203c 100644 --- a/web/src/components/filter/ReviewFilterGroup.tsx +++ b/web/src/components/filter/ReviewFilterGroup.tsx @@ -14,7 +14,7 @@ import MobileReviewSettingsDrawer, { } from "../overlay/MobileReviewSettingsDrawer"; import useOptimisticState from "@/hooks/use-optimistic-state"; import FilterSwitch from "./FilterSwitch"; -import { FilterList } from "@/types/filter"; +import { FilterList, GeneralFilter } from "@/types/filter"; import CalendarFilterButton from "./CalendarFilterButton"; import { CamerasFilterButton } from "./CamerasFilterButton"; import PlatformAwareDialog from "../overlay/dialog/PlatformAwareDialog"; @@ -214,15 +214,7 @@ export default function ReviewFilterGroup({ showAll={filter?.showAll == true} allZones={filterValues.zones} selectedZones={filter?.zones} - setShowAll={(showAll) => { - onUpdateFilter({ ...filter, showAll }); - }} - updateLabelFilter={(newLabels) => { - onUpdateFilter({ ...filter, labels: newLabels }); - }} - updateZoneFilter={(newZones) => - onUpdateFilter({ ...filter, zones: newZones }) - } + onUpdateFilter={onUpdateFilter} /> )} {isMobile && mobileSettingsFeatures.length > 0 && ( @@ -300,37 +292,40 @@ type GeneralFilterButtonProps = { showAll: boolean; allZones: string[]; selectedZones?: string[]; - setShowAll: (showAll: boolean) => void; - updateLabelFilter: (labels: string[] | undefined) => void; - updateZoneFilter: (zones: string[] | undefined) => void; + filter?: GeneralFilter; + onUpdateFilter: (filter: ReviewFilter) => void; }; + function GeneralFilterButton({ allLabels, selectedLabels, + filter, currentSeverity, showAll, allZones, selectedZones, - setShowAll, - updateLabelFilter, - updateZoneFilter, + onUpdateFilter, }: GeneralFilterButtonProps) { const [open, setOpen] = useState(false); - const [currentLabels, setCurrentLabels] = useState( - selectedLabels, - ); - const [currentZones, setCurrentZones] = useState( - selectedZones, - ); + const [currentFilter, setCurrentFilter] = useState({ + labels: selectedLabels, + zones: selectedZones, + showAll: showAll, + ...filter, + }); - // ui + // Update local state when props change useEffect(() => { - setCurrentLabels(selectedLabels); - setCurrentZones(selectedZones); + setCurrentFilter({ + labels: selectedLabels, + zones: selectedZones, + showAll: showAll, + ...filter, + }); // only refresh when state changes // eslint-disable-next-line react-hooks/exhaustive-deps - }, [selectedLabels, selectedZones]); + }, [selectedLabels, selectedZones, showAll, filter]); const trigger = ( - diff --git a/web/src/components/overlay/MobileReviewSettingsDrawer.tsx b/web/src/components/overlay/MobileReviewSettingsDrawer.tsx index d58d485b93..3eeb639cd1 100644 --- a/web/src/components/overlay/MobileReviewSettingsDrawer.tsx +++ b/web/src/components/overlay/MobileReviewSettingsDrawer.tsx @@ -4,7 +4,7 @@ import { Button } from "../ui/button"; import { FaArrowDown, FaCalendarAlt, FaCog, FaFilter } from "react-icons/fa"; import { TimeRange } from "@/types/timeline"; import { ExportContent, ExportPreviewDialog } from "./ExportDialog"; -import { ExportMode } from "@/types/filter"; +import { ExportMode, GeneralFilter } from "@/types/filter"; import ReviewActivityCalendar from "./ReviewActivityCalendar"; import { SelectSeparator } from "../ui/select"; import { ReviewFilter, ReviewSeverity, ReviewSummary } from "@/types/review"; @@ -114,12 +114,12 @@ export default function MobileReviewSettingsDrawer({ // filters - const [currentLabels, setCurrentLabels] = useState( - filter?.labels, - ); - const [currentZones, setCurrentZones] = useState( - filter?.zones, - ); + const [currentFilter, setCurrentFilter] = useState({ + labels: filter?.labels, + zones: filter?.zones, + showAll: filter?.showAll, + ...filter, + }); if (!isMobile) { return; @@ -260,23 +260,21 @@ export default function MobileReviewSettingsDrawer({ - onUpdateFilter({ ...filter, zones: newZones }) - } - setShowAll={(showAll) => { - onUpdateFilter({ ...filter, showAll }); + onUpdateFilter={setCurrentFilter} + onApply={() => { + if (currentFilter !== filter) { + onUpdateFilter(currentFilter); + } + }} + onReset={() => { + const resetFilter: GeneralFilter = {}; + setCurrentFilter(resetFilter); + onUpdateFilter(resetFilter); }} - setCurrentLabels={setCurrentLabels} - updateLabelFilter={(newLabels) => - onUpdateFilter({ ...filter, labels: newLabels }) - } onClose={() => setDrawerMode("select")} /> diff --git a/web/src/types/filter.ts b/web/src/types/filter.ts index 09ff5b99a6..b7d2223c01 100644 --- a/web/src/types/filter.ts +++ b/web/src/types/filter.ts @@ -10,3 +10,9 @@ export type FilterList = { }; export const LAST_24_HOURS_KEY = "last24Hours"; + +export type GeneralFilter = { + showAll?: boolean; + labels?: string[]; + zones?: string[]; +};