feat: use placeholder data in search results
This commit is contained in:
@@ -45,12 +45,13 @@ export default function CommandPallette({
|
|||||||
const { workspace } = useWorkspace();
|
const { workspace } = useWorkspace();
|
||||||
|
|
||||||
// Debounce to avoid too many reqs
|
// Debounce to avoid too many reqs
|
||||||
const [debouncedQuery] = useDebounce(query, 500);
|
const [debouncedQuery] = useDebounce(query, 300);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: searchResults,
|
data: searchResults,
|
||||||
isLoading,
|
isLoading,
|
||||||
isFetched,
|
isFetched,
|
||||||
|
isPlaceholderData,
|
||||||
} = api.workspace.search.useQuery(
|
} = api.workspace.search.useQuery(
|
||||||
{
|
{
|
||||||
workspacePublicId: workspace.publicId,
|
workspacePublicId: workspace.publicId,
|
||||||
@@ -58,10 +59,16 @@ export default function CommandPallette({
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
enabled: Boolean(workspace.publicId && debouncedQuery.trim().length > 0),
|
enabled: Boolean(workspace.publicId && debouncedQuery.trim().length > 0),
|
||||||
|
placeholderData: (previousData) => previousData,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const results = (searchResults ?? []) as SearchResult[];
|
// Clear results when query is empty, otherwise show search results
|
||||||
|
const results =
|
||||||
|
debouncedQuery.trim().length === 0
|
||||||
|
? []
|
||||||
|
: ((searchResults ?? []) as SearchResult[]);
|
||||||
|
|
||||||
const hasSearched = Boolean(debouncedQuery.trim().length > 0 && isFetched);
|
const hasSearched = Boolean(debouncedQuery.trim().length > 0 && isFetched);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -102,7 +109,9 @@ export default function CommandPallette({
|
|||||||
{results.length > 0 && (
|
{results.length > 0 && (
|
||||||
<ComboboxOptions
|
<ComboboxOptions
|
||||||
static
|
static
|
||||||
className="max-h-72 scroll-py-2 overflow-y-auto py-2"
|
className={`max-h-72 scroll-py-2 overflow-y-auto py-2 ${
|
||||||
|
isPlaceholderData ? "opacity-75" : ""
|
||||||
|
}`}
|
||||||
>
|
>
|
||||||
{results.map((result) => (
|
{results.map((result) => (
|
||||||
<ComboboxOption
|
<ComboboxOption
|
||||||
|
|||||||
Reference in New Issue
Block a user