mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 06:23:06 +08:00
05b3c65b0f
* feat: notifications * feat: watchers * improvements * handle page move for watchers * make watchers non-blocking * more
57 lines
1.5 KiB
TypeScript
57 lines
1.5 KiB
TypeScript
import { useQuery, UseQueryResult } from "@tanstack/react-query";
|
|
import {
|
|
searchAttachments,
|
|
searchPage,
|
|
searchShare,
|
|
searchSuggestions,
|
|
} from '@/features/search/services/search-service';
|
|
import {
|
|
IAttachmentSearch,
|
|
IPageSearch,
|
|
IPageSearchParams,
|
|
ISuggestionResult,
|
|
SearchSuggestionParams,
|
|
} from '@/features/search/types/search.types';
|
|
|
|
export function usePageSearchQuery(
|
|
params: IPageSearchParams,
|
|
): UseQueryResult<IPageSearch[], Error> {
|
|
return useQuery({
|
|
queryKey: ["page-search", params],
|
|
queryFn: () => searchPage(params),
|
|
enabled: !!params.query,
|
|
});
|
|
}
|
|
|
|
export function useSearchSuggestionsQuery(
|
|
params: SearchSuggestionParams & { preload?: boolean },
|
|
): UseQueryResult<ISuggestionResult, Error> {
|
|
const { preload, ...queryParams } = params;
|
|
return useQuery({
|
|
queryKey: ["search-suggestion", params.query],
|
|
staleTime: 60 * 1000, // 1min
|
|
queryFn: () => searchSuggestions(queryParams),
|
|
enabled: preload || !!params.query,
|
|
});
|
|
}
|
|
|
|
export function useShareSearchQuery(
|
|
params: IPageSearchParams,
|
|
): UseQueryResult<IPageSearch[], Error> {
|
|
return useQuery({
|
|
queryKey: ["share-search", params],
|
|
queryFn: () => searchShare(params),
|
|
enabled: !!params.query,
|
|
});
|
|
}
|
|
|
|
export function useAttachmentSearchQuery(
|
|
params: IPageSearchParams,
|
|
): UseQueryResult<IAttachmentSearch[], Error> {
|
|
return useQuery({
|
|
queryKey: ["attachment-search", params],
|
|
queryFn: () => searchAttachments(params),
|
|
enabled: !!params.query,
|
|
});
|
|
}
|