Skip to content

Commit

Permalink
Search locations in the location picker not only on the basis of pref…
Browse files Browse the repository at this point in the history
…ixes (#371)

* Added :contains to the name parameter in the FHIR Location API

* Fixed the loading issue
  • Loading branch information
vasharma05 authored Mar 29, 2022
1 parent 7b0212e commit 31197d8
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 188 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useMemo } from "react";
import { useMemo } from "react";
import {
openmrsFetch,
fhirBaseUrl,
Expand Down Expand Up @@ -49,13 +49,13 @@ export function useLoginLocations(
}

if (typeof searchQuery === "string" && searchQuery != "") {
url += `&name=${searchQuery}`;
url += `&name:contains=${searchQuery}`;
}

return url;
};

const { data, isValidating, size, setSize, error } = useSwrInfinite<
const { data, isValidating, setSize, error } = useSwrInfinite<
FetchResponse<LocationResponse>,
Error
>(getUrl, openmrsFetch);
Expand All @@ -68,10 +68,6 @@ export function useLoginLocations(
});
}

useEffect(() => {
setSize(1);
}, [searchQuery, setSize]);

const memoizedLocationData = useMemo(() => {
return {
locationData: data
Expand All @@ -87,7 +83,7 @@ export function useLoginLocations(
loadingNewData: isValidating,
setPage: setSize,
};
}, [data, isValidating, setSize]);
}, [data, error, isValidating, setSize, searchQuery]);

return memoizedLocationData;
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ const LocationPicker: React.FC<LocationPickerProps> = ({
const search = debounce((location: string) => {
setActiveLocation("");
setSearchTerm(location);
setPage(1);
}, searchTimeout);

const handleSubmit = (evt: React.FormEvent<HTMLFormElement>) => {
Expand Down
Loading

0 comments on commit 31197d8

Please sign in to comment.