fixed some params and ui
This commit is contained in:
1 parent
f00d2abcac
commit
f293806d96
25 files changed
+547
-87
No files matched your search
@@ -25,7 +25,8 @@ export const branchKeys = {
|
||||
|
||||
export function useBranches(params: BranchListParams) {
|
||||
const debouncedSearch = useDebouncedValue(params.search ?? "");
|
||||
const queryParams: BranchListParams = { ...params, search: normalizeSearch(debouncedSearch) };
|
||||
const normalized = normalizeSearch(debouncedSearch);
|
||||
const queryParams: BranchListParams = { ...params, search: normalized || undefined };
|
||||
|
||||
return useQuery({
|
||||
queryKey: branchKeys.list(queryParams),
|
||||
@@ -33,6 +34,28 @@ export function useBranches(params: BranchListParams) {
|
||||
});
|
||||
}
|
||||
|
||||
const BRANCH_PAGE_SIZE = 25;
|
||||
|
||||
/**
|
||||
* Paginated branches for infinite-scroll selects.
|
||||
* `search` is debounced server-side search; each keystroke resets to page 1.
|
||||
*/
|
||||
export function useInfiniteBranches(search = "") {
|
||||
const debouncedSearch = useDebouncedValue(search);
|
||||
const effectiveSearch = normalizeSearch(debouncedSearch) || undefined;
|
||||
|
||||
return useInfiniteQuery({
|
||||
queryKey: [...branchKeys.lists(), "infinite", effectiveSearch],
|
||||
initialPageParam: 1,
|
||||
queryFn: ({ pageParam, signal }) => fetchBranches({ page: pageParam, limit: BRANCH_PAGE_SIZE, search: effectiveSearch }, signal),
|
||||
getNextPageParam: (lastPage, allPages) => {
|
||||
const loaded = allPages.reduce((sum, p) => sum + (p?.branches?.length ?? 0), 0);
|
||||
const count = lastPage?.count ?? 0;
|
||||
return loaded < count ? allPages.length + 1 : undefined;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const PROVINCE_PAGE_SIZE = 25;
|
||||
|
||||
/**
|
||||
@@ -41,7 +64,7 @@ const PROVINCE_PAGE_SIZE = 25;
|
||||
*/
|
||||
export function useInfiniteProvinces(search = "") {
|
||||
const debouncedSearch = useDebouncedValue(search);
|
||||
const effectiveSearch = normalizeSearch(debouncedSearch);
|
||||
const effectiveSearch = normalizeSearch(debouncedSearch) || undefined;
|
||||
|
||||
return useInfiniteQuery({
|
||||
queryKey: [...branchKeys.provinces, "infinite", effectiveSearch],
|
||||
|
||||
Reference in new issue
Block a user