Skip to content

Commit

Permalink
Improve search UX
Browse files Browse the repository at this point in the history
Signed-off-by: Damian Stasik <920747+damianstasik@users.noreply.github.com>
  • Loading branch information
damianstasik committed Sep 3, 2024
1 parent ca1b59c commit 709a029
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions frontend/src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { SearchProviderResult } from "./ProviderResult";
import { SearchOtherResult } from "./OtherResult";
import { definitions } from "@/api";
import clsx from "clsx";
import { Paragraph } from "../Paragraph";

function getSearchResultType(value: string) {
switch (value) {
Expand Down Expand Up @@ -118,7 +119,7 @@ export function Search({
}: SearchProps) {
const [query, setQuery] = useState("");
const deferredQuery = useDeferredValue(query);
const { data, isLoading } = useQuery(getSearchQuery(deferredQuery));
const { data, isFetching } = useQuery(getSearchQuery(deferredQuery));

const inputRef = useRef<HTMLInputElement | null>(null);
const navigate = useNavigate();
Expand Down Expand Up @@ -184,7 +185,6 @@ export function Search({

return (
<Combobox
onClose={() => setQuery("")}
onChange={(v: SearchResult) => {
if (!v) {
return;
Expand All @@ -207,9 +207,7 @@ export function Search({
/>
<ComboboxInput
ref={inputRef}
displayValue={(result: SearchResult) =>
(result || {}).displayTitle || ""
}
value={query}
onChange={(event) => onChange(event.target.value)}
placeholder={placeholder}
className={clsx(
Expand All @@ -218,7 +216,7 @@ export function Search({
)}
/>

{isLoading && (
{isFetching && (
<Icon
path={spinner}
className={clsx(
Expand All @@ -232,7 +230,7 @@ export function Search({

<ComboboxOptions
anchor="bottom start"
className="z-10 max-h-96 w-[var(--input-width)] divide-y divide-gray-300 bg-gray-200 [--anchor-max-height:theme(height.96)] [--anchor-padding:theme(padding.4)] empty:hidden dark:divide-gray-900 dark:bg-gray-800"
className="z-10 max-h-96 w-[var(--input-width)] divide-y divide-gray-300 bg-gray-200 [--anchor-max-height:theme(height.96)] [--anchor-padding:theme(padding.4)] dark:divide-gray-900 dark:bg-gray-800"
>
{filtered.map((item) => (
<div key={item.type}>
Expand Down Expand Up @@ -260,6 +258,11 @@ export function Search({
))}
</div>
))}
{filtered.length === 0 && !isFetching && query && (
<Paragraph className="px-4 py-2 text-sm">
No results found
</Paragraph>
)}
</ComboboxOptions>
</div>
</Combobox>
Expand Down

0 comments on commit 709a029

Please sign in to comment.