filters on AI search

This commit is contained in:
Salihu
2026-08-18 23:53:12 +01:00
parent ca3c9dcfd7
commit 480117b43f
4 changed files with 29 additions and 7 deletions
@@ -91,6 +91,7 @@ export function LabelFilterMenu({
return ( return (
<Menu.Item <Menu.Item
key={label.id} key={label.id}
type="button"
component={CheckboxMenuItem} component={CheckboxMenuItem}
aria-checked={isChecked} aria-checked={isChecked}
onClick={() => toggleLabel(label.id)} onClick={() => toggleLabel(label.id)}
@@ -124,8 +124,17 @@ export function SearchSpotlightFilters({
color="blue" color="blue"
labelPosition="left" labelPosition="left"
styles={{ styles={{
root: { display: "flex", alignItems: "center" }, root: {
label: { paddingRight: "8px", fontSize: "13px", fontWeight: 500 }, display: "flex",
alignItems: "center",
flexShrink: 0,
},
label: {
whiteSpace: "nowrap",
paddingRight: "8px",
fontSize: "13px",
fontWeight: 500,
},
}} }}
/> />
</div> </div>
@@ -1,6 +1,6 @@
import { Spotlight } from "@mantine/spotlight"; import { Spotlight } from "@mantine/spotlight";
import { IconSearch, IconSparkles } from "@tabler/icons-react"; import { IconSearch, IconSparkles } from "@tabler/icons-react";
import { Group, Button, VisuallyHidden } from "@mantine/core"; import { Group, Button, VisuallyHidden, Text } from "@mantine/core";
import React, { useState, useMemo, useEffect, useCallback } from "react"; import React, { useState, useMemo, useEffect, useCallback } from "react";
import { useDebouncedValue } from "@mantine/hooks"; import { useDebouncedValue } from "@mantine/hooks";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
@@ -56,7 +56,10 @@ export function SearchSpotlight({ spaceId }: SearchSpotlightProps) {
return params; return params;
}, [debouncedSearchQuery, filters]); }, [debouncedSearchQuery, filters]);
const { data: searchResults, isLoading } = useUnifiedSearch( const {
data: searchResults,
isFetching,
} = useUnifiedSearch(
searchParams, searchParams,
!isAiMode // Disable regular search when in AI mode !isAiMode // Disable regular search when in AI mode
); );
@@ -177,7 +180,7 @@ export function SearchSpotlight({ spaceId }: SearchSpotlightProps) {
? query.length > 0 && !isAiLoading && !aiSearchResult ? query.length > 0 && !isAiLoading && !aiSearchResult
? t("No answer available") ? t("No answer available")
: "" : ""
: query.length > 0 && !isLoading : query.length > 0 && !isFetching
? resultItems.length === 0 ? resultItems.length === 0
? t("No results found") ? t("No results found")
: t("{{count}} results found", { count: resultItems.length }) : t("{{count}} results found", { count: resultItems.length })
@@ -208,11 +211,19 @@ export function SearchSpotlight({ spaceId }: SearchSpotlightProps) {
<Spotlight.Empty>{t("Start typing to search...")}</Spotlight.Empty> <Spotlight.Empty>{t("Start typing to search...")}</Spotlight.Empty>
)} )}
{query.length > 0 && !isLoading && resultItems.length === 0 && ( {query.length > 0 && !isFetching && resultItems.length === 0 && (
<Spotlight.Empty>{t("No results found...")}</Spotlight.Empty> <Spotlight.Empty>{t("No results found...")}</Spotlight.Empty>
)} )}
{resultItems.length > 0 && <>{resultItems}</>} {resultItems.length > 0 && <>{resultItems}</>}
{query.length > 0 && isFetching && (
<Spotlight.Empty>
<Text size="sm" style={{ marginTop: 10 }}>
{t("Searching...")}
</Text>
</Spotlight.Empty>
)}
</> </>
)} )}
</Spotlight.ActionsList> </Spotlight.ActionsList>
@@ -1,4 +1,4 @@
import { useQuery, UseQueryResult } from "@tanstack/react-query"; import { keepPreviousData, useQuery, UseQueryResult } from "@tanstack/react-query";
import { import {
searchPage, searchPage,
searchAttachments, searchAttachments,
@@ -40,5 +40,6 @@ export function useUnifiedSearch(
} }
}, },
enabled: !!params.query && enabled, enabled: !!params.query && enabled,
placeholderData: params.query.length > 0 ? keepPreviousData: undefined
}); });
} }