From 6f7b46a9e3e80ba73030467bfab06eab2e8129c9 Mon Sep 17 00:00:00 2001 From: sickelap Date: Thu, 5 Dec 2024 22:54:55 +0000 Subject: [PATCH] restore site search functionality --- TODO | 1 - src/components/SiteSearch.tsx | 71 +++++++++++++++++++++++++---------- src/service/use-search.ts | 7 ++-- src/ui-constants.ts | 2 +- 4 files changed, 57 insertions(+), 24 deletions(-) diff --git a/TODO b/TODO index 8e5fd280..f65634f6 100644 --- a/TODO +++ b/TODO @@ -13,6 +13,5 @@ - low: dark mode visibility text sidemenu - low: refactor sidebar with NavLink - low: notifications not visible -- optional: refactor site search with combobox - optional: refactor tree with latest mantine tree (and remove existing one) - optional: move color theme switch to top menu for convenience diff --git a/src/components/SiteSearch.tsx b/src/components/SiteSearch.tsx index e6a548e0..fe39815a 100644 --- a/src/components/SiteSearch.tsx +++ b/src/components/SiteSearch.tsx @@ -1,4 +1,4 @@ -import { Combobox, Group, InputBase, Loader, Text, useCombobox } from "@mantine/core"; +import { ActionIcon, Combobox, Group, Image, InputBase, Loader, Popover, Text, useCombobox } from "@mantine/core"; import { useViewportSize } from "@mantine/hooks"; import { IconAlbum, IconMap, IconSearch, IconTag, IconUser, IconX } from "@tabler/icons-react"; import React from "react"; @@ -7,6 +7,7 @@ import { push } from "redux-first-history"; import { SearchOption, SearchOptionType, useSearch } from "../service/use-search"; import { useAppDispatch } from "../store/store"; +import classes from "./SiteSearch.module.css"; const ICON_SIZE = 20; @@ -34,13 +35,14 @@ export function SiteSearch() { const dispatch = useAppDispatch(); const searchWidth = width ? width - width / 1.8 : 200; const [value, setValue] = React.useState(""); + const [personToBeSelected, setPersonToBeSelected] = React.useState(null); function getSearchRightIcon() { if (isLoading) return ; if (value) { return ( event.preventDefault()} onClick={() => { setValue(""); @@ -53,6 +55,10 @@ export function SiteSearch() { return null; } + function showPersonNameToBeSelected(name: string): boolean { + return name === personToBeSelected; + } + function search(query: string) { const item = options.find(i => i.value === query); switch (item?.type) { @@ -77,26 +83,53 @@ export function SiteSearch() { } } - const searchOptions = options.map(item => ( - - - {getIconForItem(item)} - {item.value} - - - )); + function onOptionSubmit(val: string) { + setValue(val); + search(val); + combobox.closeDropdown(); + } + + const searchOptionsDefault = options.filter(option => option.type !== SearchOptionType.PEOPLE); + const searchOptionsPeople = options.filter(option => option.type === SearchOptionType.PEOPLE); + const searchOptions = searchOptionsDefault + .map(item => ( + + + {getIconForItem(item)} + {item.value} + + + )) + .concat([ + + + {searchOptionsPeople.map(person => ( + + + setPersonToBeSelected(person.value)} + onMouseLeave={() => setPersonToBeSelected(null)} + size="xl" + radius="xl" + variant="transparent" + onClick={() => onOptionSubmit(person.value)} + > + + + + + {person.value} + + + ))} + + , + ]); return (
- { - setValue(val); - search(val); - combobox.closeDropdown(); - }} - > + onOptionSubmit(option)}> } diff --git a/src/service/use-search.ts b/src/service/use-search.ts index 912dd3d8..f32e33d7 100644 --- a/src/service/use-search.ts +++ b/src/service/use-search.ts @@ -22,6 +22,7 @@ export type SearchOption = { value: string; type: SearchOptionType; data: string | null; + thumbnail?: string; }; function toExampleOption(item: string): SearchOption { @@ -41,7 +42,7 @@ function toUserAlbumOption(item: any): SearchOption { } function toPersonOption(item: any): SearchOption { - return { value: item.value, type: SearchOptionType.PEOPLE, data: item.key }; + return { value: item.name, type: SearchOptionType.PEOPLE, data: item.id, thumbnail: item.face_url }; } export function useSearch() { @@ -78,8 +79,8 @@ export function useSearch() { .slice(0, 2) .map(toUserAlbumOption), ...people - .filter((item: any) => fuzzyMatch(q, item.value)) - .slice(0, 2) + .filter((item: any) => fuzzyMatch(q, item.name)) + .slice(0, 9) .map(toPersonOption), ]); }, diff --git a/src/ui-constants.ts b/src/ui-constants.ts index 2d38eb0a..26db2b57 100644 --- a/src/ui-constants.ts +++ b/src/ui-constants.ts @@ -1,4 +1,4 @@ -export const TOP_MENU_HEIGHT = 45; // don't change this +export const TOP_MENU_HEIGHT = 55; // don't change this export const LEFT_MENU_WIDTH = 200; // don't change this export const FOOTER_HEIGHT = 50; export const MIN_VIEWPORT_WODTH = 350;