Fix gallery 3

This commit is contained in:
Manav Rathi
2024-09-12 13:45:31 +05:30
parent 5aa9671037
commit 2cd2aee11c
2 changed files with 17 additions and 15 deletions

View File

@@ -980,16 +980,18 @@ export default function Gallery() {
});
};
const updateSearch: UpdateSearch = (newSearch, summary) => {
if (newSearch?.collection) {
setActiveCollectionID(newSearch?.collection);
const handleSelectSearchOption = (
searchOption: SearchOption | undefined,
) => {
if (searchOption?.suggestion.type == "collection") {
setIsInSearchMode(false);
setSelectedSearchOption(undefined);
setActiveCollectionID(searchOption.suggestion.collectionID);
} else {
setSearchQuery(newSearch);
setIsInSearchMode(!!newSearch);
setSetSearchResultSummary(summary);
setIsInSearchMode(!!searchOption);
setSelectedSearchOption(searchOption);
}
setIsClipSearchResult(!!newSearch?.clip);
setIsClipSearchResult(searchOption?.suggestion.type == "clip");
};
const openUploader = (intent?: UploadTypeSelectorIntent) => {
@@ -1098,7 +1100,7 @@ export default function Gallery() {
openUploader={openUploader}
isInSearchMode={isInSearchMode}
setIsInSearchMode={setIsInSearchMode}
updateSearch={updateSearch}
onSelectSearchOption={handleSelectSearchOption}
/>
)}
</NavbarBase>

View File

@@ -61,7 +61,7 @@ export interface SearchBarProps {
/**
* Set or clear the selected {@link SearchOption}.
*/
setSelectedSearchOption: (o: SearchOption | undefined) => void;
onSelectSearchOption: (o: SearchOption | undefined) => void;
}
/**
@@ -82,7 +82,7 @@ export interface SearchBarProps {
export const SearchBar: React.FC<SearchBarProps> = ({
setIsInSearchMode,
isInSearchMode,
setSelectedSearchOption,
onSelectSearchOption,
}) => {
const isMobileWidth = useIsMobileWidth();
@@ -93,7 +93,7 @@ export const SearchBar: React.FC<SearchBarProps> = ({
{isMobileWidth && !isInSearchMode ? (
<MobileSearchArea onSearch={showSearchInput} />
) : (
<SearchInput {...{ isInSearchMode, setSelectedSearchOption }} />
<SearchInput {...{ isInSearchMode, onSelectSearchOption }} />
)}
</Box>
);
@@ -114,7 +114,7 @@ const MobileSearchArea: React.FC<MobileSearchAreaProps> = ({ onSearch }) => (
const SearchInput: React.FC<Omit<SearchBarProps, "setIsInSearchMode">> = ({
isInSearchMode,
setSelectedSearchOption,
onSelectSearchOption,
}) => {
// A ref to the top level Select.
const selectRef = useRef<SelectInstance<SearchOption> | null>(null);
@@ -132,7 +132,7 @@ const SearchInput: React.FC<Omit<SearchBarProps, "setIsInSearchMode">> = ({
setValue(value ?? undefined);
setInputValue(value?.suggestion.label ?? "");
// TODO-Cluster:
if (value) setSelectedSearchOption(value);
if (value) onSelectSearchOption(value);
// The Select has a blurInputOnSelect prop, but that makes the input
// field lose focus, not the entire menu (e.g. when pressing twice).
@@ -150,14 +150,14 @@ const SearchInput: React.FC<Omit<SearchBarProps, "setIsInSearchMode">> = ({
const resetSearch = () => {
setValue(undefined);
setInputValue("");
setSelectedSearchOption(undefined);
onSelectSearchOption(undefined);
};
const handleSelectCGroup = (value: SearchOption) => {
// Dismiss the search menu.
selectRef.current?.blur();
setValue(value);
setSelectedSearchOption(undefined);
onSelectSearchOption(undefined);
};
const handleFocus = () => {