|
@@ -9,26 +9,6 @@ import {ListParams, OriginalListParams} from '@models';
|
|
|
import {useCallback} from 'react';
|
|
|
import {Context} from 'use-context-selector';
|
|
|
|
|
|
-// type UseTableExportEventOptions<T extends ListParams> = {
|
|
|
-// pageContext: ReturnType<typeof createPageContext>;
|
|
|
-// context: Context<TableSearchContext<OriginalListParams<T>>>;
|
|
|
-// fn: (params: T) => Promise<any>;
|
|
|
-// };
|
|
|
-
|
|
|
-// type UseTableExportEventOptionsWithSelector<T extends ListParams, S> = {
|
|
|
-// pageContext: ReturnType<typeof createPageContext>;
|
|
|
-// context: Context<TableSearchContext<S>>;
|
|
|
-// fn: (params: T) => Promise<any>;
|
|
|
-// selector: (state: S) => T;
|
|
|
-// };
|
|
|
-
|
|
|
-// export function useTableExportEvent<T extends ListParams>(
|
|
|
-// options: UseTableExportEventOptions<T>,
|
|
|
-// ): [boolean, () => void];
|
|
|
-// export function useTableExportEvent<T extends ListParams, S extends ListParams>(
|
|
|
-// options: UseTableExportEventOptionsWithSelector<T, S>,
|
|
|
-// ): [boolean, () => void];
|
|
|
-
|
|
|
export function useTableExportEvent<
|
|
|
P extends ListParams,
|
|
|
C extends TableSearchContext<any>,
|
|
@@ -42,7 +22,7 @@ export function useTableExportEvent<
|
|
|
context: Context<C>;
|
|
|
fn: (params: P) => Promise<any>;
|
|
|
parseParams?: (state: C[0]) => OriginalListParams<P>;
|
|
|
-}): [boolean, () => void] {
|
|
|
+}): [boolean, (downloadFileName: string) => () => void] {
|
|
|
const [{page, pageSize}] = usePage(pageContext);
|
|
|
const params = useContextSection(context, function ([state]) {
|
|
|
return parseParams ? parseParams(state) : state;
|
|
@@ -50,12 +30,15 @@ export function useTableExportEvent<
|
|
|
const [isExporting, mutate] = useExportFile(fn);
|
|
|
|
|
|
const onExport = useCallback(
|
|
|
- function () {
|
|
|
- mutate({
|
|
|
- ...params,
|
|
|
- page: String(page),
|
|
|
- limit: String(pageSize),
|
|
|
- } as unknown as P);
|
|
|
+ function (downloadFileName: string) {
|
|
|
+ return function () {
|
|
|
+ mutate({
|
|
|
+ ...params,
|
|
|
+ downloadFileName,
|
|
|
+ page: String(page),
|
|
|
+ limit: String(pageSize),
|
|
|
+ } as unknown as P);
|
|
|
+ };
|
|
|
},
|
|
|
[mutate, page, pageSize, params],
|
|
|
);
|