From 1dcfcb6250075cbafd5cc42b0992d739aedd2b12 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Wed, 11 Sep 2024 07:43:17 +0530 Subject: [PATCH] Alternative & hopefully less hacky approach --- web/apps/photos/src/components/SearchBar.tsx | 88 ++++++++++++++++++-- 1 file changed, 81 insertions(+), 7 deletions(-) diff --git a/web/apps/photos/src/components/SearchBar.tsx b/web/apps/photos/src/components/SearchBar.tsx index 4bbb5f3a43..544b44eedf 100644 --- a/web/apps/photos/src/components/SearchBar.tsx +++ b/web/apps/photos/src/components/SearchBar.tsx @@ -139,7 +139,7 @@ const SearchInput: React.FC = ({ // The currently selected option. const [value, setValue] = useState(); // The contents of the input field associated with the select. - const [query, setQuery] = useState(""); + const [inputValue, setInputValue] = useState(""); // The default options shown in the select menu when nothing has been typed. const [defaultOptions, setDefaultOptions] = useState([]); @@ -155,7 +155,7 @@ const SearchInput: React.FC = ({ const handleChange = (value: SearchOption) => { setValue(value); - setQuery(value?.label); + setInputValue(value?.label); // The Select has a blurInputOnSelect prop, but that makes the input // field lose focus, not the entire menu (e.g. when pressing twice). // @@ -166,7 +166,7 @@ const SearchInput: React.FC = ({ const handleInputChange = (value: string, actionMeta: InputActionMeta) => { if (actionMeta.action === "input-change") { - setQuery(value); + setInputValue(value); } }; @@ -183,7 +183,7 @@ const SearchInput: React.FC = ({ }, 10); setIsOpen(false); setValue(null); - setQuery(""); + setInputValue(""); } }; @@ -219,7 +219,7 @@ const SearchInput: React.FC = ({ case SuggestionType.COLLECTION: search = { collection: selectedOption.value as number }; setValue(null); - setQuery(""); + setInputValue(""); break; case SuggestionType.FILE_NAME: search = { files: selectedOption.value as number[] }; @@ -250,6 +250,8 @@ const SearchInput: React.FC = ({ refreshDefaultOptions(); }; + const handleSelectCGroup = (cgroup: SearchPerson) => {}; + const components = useMemo( () => ({ Option, Control, Menu: CustomMenu, Input: Input }), [], @@ -269,11 +271,16 @@ const SearchInput: React.FC = ({ isMulti={false} isClearable escapeClearsValue - inputValue={query} + inputValue={inputValue} onInputChange={handleInputChange} styles={SelectStyles} defaultOptions={isMLEnabled() ? defaultOptions : []} - noOptionsMessage={() => null} + noOptionsMessage={({ inputValue }) => ( + console.log(inputValue), + !inputValue && ( + + ) + )} /> {isOpen && ( @@ -379,6 +386,73 @@ const iconForOptionType = (type: SuggestionType | undefined) => { } }; +interface EmptyStateProps { + /** Called when the user selects a cgroup shown in the empty state view. */ + onSelectCGroup: (cgroup: SearchPerson) => void; +} + +/** + * The view shown in the menu area when the user has not typed anything in the + * search box. + */ +const EmptyState: React.FC = (props) => { + // Need to cast here, otherwise the react-select types think selectProps can + // also be something that supports multiple selection groups. + // const options = props.selectProps.options as SearchOption[]; + + // const peopleSuggestions = options.filter( + // (o) => o.type === SuggestionType.PERSON, + // ); + // const people = peopleSuggestions.map((o) => o.value as SearchPerson); + + // const indexStatusSuggestion = options.filter( + // (o) => o.type === SuggestionType.INDEX_STATUS, + // )[0] as Suggestion; + + // const indexStatus = indexStatusSuggestion?.value; + // return ( + // + // + // {isMLEnabled() && + // indexStatus && + // (people && people.length > 0 ? ( + // + // {t("people")} + // + // ) : ( + // + // ))} + + // {isMLEnabled() && indexStatus && ( + // + // {indexStatusSuggestion.label} + // + // )} + // {people && people.length > 0 && ( + // + // { + // selectRef.current?.blur(); + // setSelectedValue(peopleSuggestions[index]); + // }} + // /> + // + // )} + // + // {props.children} + // + // ); + + return ( +
+

Hello

+

{(console.log(props), props.toString())}

+
+ ); +}; + const Option: React.FC> = (props) => (