Skip to content

Commit

Permalink
Searching indicator in autocomplete (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
TyHil authored Nov 15, 2023
1 parent 3d24dbe commit 3f7a02a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions components/common/SearchBar/searchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,19 @@ type SearchProps = {
export const SearchBar = (props: SearchProps) => {
const [open, setOpen] = useState(false);
const [options, setOptions] = useState<readonly SearchQuery[]>([]);
const [loading, setLoading] = useState(false);

const [value, setValue] = useState<SearchQuery | null>(null);
const [inputValue, setInputValue] = useState('');

useEffect(() => {
if (open) {
setLoading(true);
let searchValue = inputValue;
if (searchValue === '') {
if (!props.searchTerms.length) {
setOptions([]);
setLoading(false);
return;
}
searchValue = searchQueryLabel(
Expand All @@ -56,6 +59,7 @@ export const SearchBar = (props: SearchProps) => {
throw new Error(data.message);
}
setOptions(data.data);
setLoading(false);
})
.catch((error) => {
if (error instanceof DOMException) {
Expand All @@ -74,6 +78,7 @@ export const SearchBar = (props: SearchProps) => {
<>
<div className="text-primary w-full max-w-2xl h-fit flex flex-row items-start">
<Autocomplete
loading={loading}
autoHighlight={true}
disabled={props.disabled}
className="w-full h-12 bg-primary-light"
Expand Down
5 changes: 5 additions & 0 deletions components/common/SplashPageSearchBar/splashPageSearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ type SearchProps = {
*/
export const SplashPageSearchBar = (props: SearchProps) => {
const [options, setOptions] = useState<readonly SearchQuery[]>([]);
const [loading, setLoading] = useState(false);

const [inputValue, setInputValue] = useState('');

useEffect(() => {
setLoading(true);
if (inputValue === '') {
setOptions([]);
setLoading(false);
return;
}
const controller = new AbortController();
Expand All @@ -43,6 +46,7 @@ export const SplashPageSearchBar = (props: SearchProps) => {
throw new Error(data.message);
}
setOptions(data.data);
setLoading(false);
})
.catch((error) => {
if (error instanceof DOMException) {
Expand All @@ -60,6 +64,7 @@ export const SplashPageSearchBar = (props: SearchProps) => {
<>
<div className="text-primary m-auto w-11/12 -translate-y-1/4">
<Autocomplete
loading={loading}
autoHighlight={true}
disabled={props.disabled}
className="w-full h-12"
Expand Down

0 comments on commit 3f7a02a

Please sign in to comment.