Skip to content

Commit

Permalink
Do not show the "no results" info when placeholder data is empty
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 10, 2024
1 parent 2501419 commit c35608e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions frontend/src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ export function Search({
}: SearchProps) {
const [query, setQuery] = useState("");
const debouncedQuery = useDebouncedValue(query, 250);
const { data, isFetching } = useQuery(getSearchQuery(debouncedQuery));
const { data, isFetching, isPending, isPlaceholderData } = useQuery(
getSearchQuery(debouncedQuery),
);

const inputRef = useRef<HTMLInputElement | null>(null);
const navigate = useNavigate();
Expand Down Expand Up @@ -184,6 +186,13 @@ export function Search({
};
}, []);

const shouldShowNoResultsInfo =
filtered.length === 0 &&
query &&
!isFetching &&
!isPending &&
!isPlaceholderData;

return (
<Combobox
onChange={(v: SearchResult) => {
Expand Down Expand Up @@ -231,7 +240,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)] 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)] empty:hidden dark:divide-gray-900 dark:bg-gray-800"
>
{filtered.map((item) => (
<div key={item.type}>
Expand Down Expand Up @@ -259,7 +268,7 @@ export function Search({
))}
</div>
))}
{filtered.length === 0 && !isFetching && query && (
{shouldShowNoResultsInfo && (
<Paragraph className="px-4 py-2 text-sm">
No results found
</Paragraph>
Expand Down

0 comments on commit c35608e

Please sign in to comment.