Skip to content

Commit

Permalink
Allow updates to search that returns empty results (#1120)
Browse files Browse the repository at this point in the history
If user submits a search that returns no results, he should be able to submit a new search query
by entering it into the editable input field.
  • Loading branch information
azangru authored Apr 24, 2024
1 parent 6759fa9 commit 7f1debf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import React, { useState, useEffect, useDeferredValue } from 'react';
import { useSearchParams } from 'react-router-dom';

import { useAppSelector } from 'src/store';

Expand All @@ -37,19 +38,21 @@ import type { SpeciesSearchMatch } from 'src/content/app/species-selector/types/
import styles from './GenomeSelectorBySearchQuery.module.css';

type Props = {
query: string;
onSpeciesAdd: (genomes: SpeciesSearchMatch[]) => void;
onClose: () => void;
};

const GenomeSelectorBySearchQuery = (props: Props) => {
const { query, onClose } = props;
const { onClose } = props;
const [filterQuery, setFilterQuery] = useState('');
const [canSubmitSearch, setCanSubmitSearch] = useState(false);
const committedSpecies = useAppSelector(getCommittedSpecies);
const [searchParams, setSearchParams] = useSearchParams();
const [searchTrigger, result] = useLazyGetSpeciesSearchResultsQuery();
const { currentData, isLoading } = result;

const query = searchParams.get('query') as string;

const {
genomes,
stagedGenomes,
Expand All @@ -68,7 +71,7 @@ const GenomeSelectorBySearchQuery = (props: Props) => {

useEffect(() => {
searchTrigger({ query });
}, []);
}, [query]);

const onSearchInput = () => {
if (!canSubmitSearch) {
Expand All @@ -80,8 +83,10 @@ const GenomeSelectorBySearchQuery = (props: Props) => {
props.onSpeciesAdd(stagedGenomes);
};

const onSearchSubmit = () => {
searchTrigger({ query });
const onSearchSubmit = (query: string) => {
const newSearchParams = new URLSearchParams();
newSearchParams.set('query', query);
setSearchParams(newSearchParams, { replace: true });
setCanSubmitSearch(false);
};

Expand Down Expand Up @@ -123,7 +128,7 @@ type TopSectionProps = {
searchResults?: SpeciesSearchResponse;
canAddGenomes: boolean;
canSubmitSearch: boolean;
onSearchSubmit: () => void;
onSearchSubmit: (query: string) => void;
onSearchInput: () => void;
onGenomesAdd: () => void;
onFilterChange: (filter: string) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ const Content = (props: { onClose: () => void }) => {

return searchParams.has('query') ? (
<GenomeSelectorBySearchQuery
query={searchParams.get('query') as string}
onSpeciesAdd={onSpeciesAdd}
onClose={props.onClose}
/>
Expand Down

0 comments on commit 7f1debf

Please sign in to comment.