From 2ce03c0ae590e89348b69f621083c8ba7ab198d1 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Mon, 9 Sep 2024 15:59:44 -0600 Subject: [PATCH] Adjust search options --- .../components/filter/SearchFilterGroup.tsx | 129 +++++++----------- web/src/pages/Search.tsx | 1 + web/src/views/search/SearchView.tsx | 2 + 3 files changed, 53 insertions(+), 79 deletions(-) diff --git a/web/src/components/filter/SearchFilterGroup.tsx b/web/src/components/filter/SearchFilterGroup.tsx index 9a606d7fb..5904ff07e 100644 --- a/web/src/components/filter/SearchFilterGroup.tsx +++ b/web/src/components/filter/SearchFilterGroup.tsx @@ -6,25 +6,24 @@ import { useCallback, useMemo, useState } from "react"; import { DropdownMenuSeparator } from "../ui/dropdown-menu"; import { getEndOfDayTimestamp } from "@/utils/dateUtil"; import { FaFilter } from "react-icons/fa"; -import { isDesktop, isMobile } from "react-device-detect"; +import { isMobile } from "react-device-detect"; import { Drawer, DrawerContent, DrawerTrigger } from "../ui/drawer"; import { Switch } from "../ui/switch"; import { Label } from "../ui/label"; -import MobileReviewSettingsDrawer, { - DrawerFeatures, -} from "../overlay/MobileReviewSettingsDrawer"; import FilterSwitch from "./FilterSwitch"; import { FilterList } from "@/types/filter"; import { CalendarRangeFilterButton } from "./CalendarFilterButton"; import { CamerasFilterButton } from "./CamerasFilterButton"; import { SearchFilter, SearchSource } from "@/types/search"; import { DateRange } from "react-day-picker"; +import { cn } from "@/lib/utils"; const SEARCH_FILTERS = ["cameras", "date", "general"] as const; type SearchFilters = (typeof SEARCH_FILTERS)[number]; const DEFAULT_REVIEW_FILTERS: SearchFilters[] = ["cameras", "date", "general"]; type SearchFilterGroupProps = { + className: string; filters?: SearchFilters[]; filter?: SearchFilter; filterList?: FilterList; @@ -32,6 +31,7 @@ type SearchFilterGroupProps = { }; export default function SearchFilterGroup({ + className, filters = DEFAULT_REVIEW_FILTERS, filter, filterList, @@ -120,20 +120,6 @@ export default function SearchFilterGroup({ ); }, [config]); - const mobileSettingsFeatures = useMemo(() => { - const features: DrawerFeatures[] = []; - - if (filters.includes("date")) { - features.push("calendar"); - } - - if (filters.includes("general")) { - features.push("filter"); - } - - return features; - }, [filters]); - // handle updating filters const onUpdateSelectedRange = useCallback( @@ -149,13 +135,8 @@ export default function SearchFilterGroup({ [filter, onUpdateFilter], ); - const showAllFilters = useMemo( - () => isDesktop || !config?.semantic_search?.enabled, - [config], - ); - return ( -
+
{filters.includes("cameras") && ( )} - {showAllFilters && filters.includes("date") && ( + {filters.includes("date") && ( )} - {showAllFilters && filters.includes("general") && ( + {filters.includes("general") && ( )} - {!showAllFilters && mobileSettingsFeatures.length > 0 && ( - {}} - setRange={() => {}} - /> - )}
); } @@ -360,52 +325,58 @@ export function GeneralFilterContent({ updateSearchSourceFilter, onClose, }: GeneralFilterContentProps) { + const { data: config } = useSWR("config", { + revalidateOnFocus: false, + }); + return ( <>
-
- { - const updatedSources = currentSearchSources - ? [...currentSearchSources] - : []; + {config?.semantic_search?.enabled && ( +
+ { + const updatedSources = currentSearchSources + ? [...currentSearchSources] + : []; - if (isChecked) { - updatedSources.push("thumbnail"); - setCurrentSearchSources(updatedSources); - } else { - if (updatedSources.length > 1) { - const index = updatedSources.indexOf("thumbnail"); - if (index !== -1) updatedSources.splice(index, 1); + if (isChecked) { + updatedSources.push("thumbnail"); setCurrentSearchSources(updatedSources); + } else { + if (updatedSources.length > 1) { + const index = updatedSources.indexOf("thumbnail"); + if (index !== -1) updatedSources.splice(index, 1); + setCurrentSearchSources(updatedSources); + } } - } - }} - /> - { - const updatedSources = currentSearchSources - ? [...currentSearchSources] - : []; + }} + /> + { + const updatedSources = currentSearchSources + ? [...currentSearchSources] + : []; - if (isChecked) { - updatedSources.push("description"); - setCurrentSearchSources(updatedSources); - } else { - if (updatedSources.length > 1) { - const index = updatedSources.indexOf("description"); - if (index !== -1) updatedSources.splice(index, 1); + if (isChecked) { + updatedSources.push("description"); setCurrentSearchSources(updatedSources); + } else { + if (updatedSources.length > 1) { + const index = updatedSources.indexOf("description"); + if (index !== -1) updatedSources.splice(index, 1); + setCurrentSearchSources(updatedSources); + } } - } - }} - /> - -
+ }} + /> + +
+ )}