Procházet zdrojové kódy

chore: 二级菜单移除onClose props

xyh před 2 roky
rodič
revize
c866ecbe57

+ 1 - 0
packages/app/src/hooks/index.ts

@@ -6,3 +6,4 @@ export * from './useOptions';
 export * from './useDataInfo';
 export {useQueryList as useQueryTableList} from './useQueryList';
 export * from './usePutData';
+export * from './useRangeDate';

+ 7 - 0
packages/app/src/hooks/useRangeDate/index.tsx

@@ -0,0 +1,7 @@
+import type {RangeValue} from '@components';
+import type {Dayjs} from 'dayjs';
+import {useState} from 'react';
+
+export function useRangeDate(startTime: Dayjs | null = null, endTime: Dayjs | null = null) {
+  return useState<RangeValue<Dayjs>>([startTime, endTime]);
+}

+ 4 - 5
packages/app/src/pages/container-scrap/filter/index.tsx

@@ -1,13 +1,12 @@
-import {FilterButtonGroup, FilterDatePicker, RangeValue} from '@components';
+import {FilterButtonGroup, FilterDatePicker} from '@components';
 import {Card, Row} from 'antd';
-import {FC, useState} from 'react';
-import type {Dayjs} from 'dayjs';
+import {FC} from 'react';
 import {useExport, useSearch} from './hooks';
-import {useTableSearch} from '@hooks';
+import {useRangeDate, useTableSearch} from '@hooks';
 import {searchContext} from '../context';
 
 const Filter: FC = function() {
-  const [dates, setDates] = useState<RangeValue<Dayjs>>([null, null]);
+  const [dates, setDates] = useRangeDate();
   const onSearch = useSearch(dates);
   const [isSearching] = useTableSearch(searchContext);
   const [isExporting, onExport] = useExport();

+ 5 - 9
packages/app/src/pages/menu-id/context.ts

@@ -5,16 +5,14 @@ import {createContext} from 'use-context-selector';
 // #region 整体弹窗管理
 type State = {
   name: string;
-  onClose: null | (() => void);
 };
 
 type Action =
 | {type: 'SEARCH', payload: Pick<State, 'name'>}
-| {type: 'RESET'}
-| {type: 'SET_CLOSE', payload: State['onClose']};
+| {type: 'RESET'};
 
-function initState(onClose?: () => void): State {
-  return {name: '', onClose: onClose ?? null};
+function initState(): State {
+  return {name: ''};
 }
 
 function reducer(state: State, action: Action): State {
@@ -23,8 +21,6 @@ function reducer(state: State, action: Action): State {
   switch (type) {
     case 'SEARCH':
       return {...state, ...action.payload};
-    case 'SET_CLOSE':
-      return {...state, onClose: action.payload};
     case 'RESET':
       return initState();
     default:
@@ -32,8 +28,8 @@ function reducer(state: State, action: Action): State {
   }
 }
 
-export function useContextReducer(onClose: () => void) {
-  return useReducer(reducer, initState(onClose));
+export function useContextReducer() {
+  return useReducer(reducer, initState());
 }
 
 export const context = createContext<[State, Dispatch<Action>]>([initState(), () => null]);

+ 4 - 5
packages/app/src/pages/menu-id/index.tsx

@@ -14,11 +14,10 @@ import {PageProvider, SearchProvider} from '@components';
 
 type Props = {
   id: string,
-  onClose: () => void,
 };
 
-const MenuProvider: ChildrenFC<Pick<Props, 'onClose'>> = function({children, onClose}) {
-  const state = useContextReducer(onClose);
+const MenuProvider: ChildrenFC = function({children}) {
+  const state = useContextReducer();
 
   const {Provider} = context;
 
@@ -32,10 +31,10 @@ const PIdProvider: ChildrenFC<Pick<Props, 'id'>> = function({children, id}) {
   return <Provider value={state}>{children}</Provider>;
 };
 
-const ChildMenu: FC<Props> = function({id, onClose}) {
+const ChildMenu: FC<Props> = function({id}) {
   return (
     <PIdProvider id={id}>
-      <MenuProvider onClose={onClose}>
+      <MenuProvider>
         <SearchProvider context={searchContext}>
           <PageProvider context={pageContext}>
             <section className='content-main' data-testid='child_menu'>

+ 1 - 1
packages/app/src/pages/menu/child-menu/index.tsx

@@ -14,7 +14,7 @@ const ChildMenuModal: FC<Props> = function({visible, id, onClose}) {
       onClose={onClose}
       visible={visible}
     >
-      <ChildMenu id={id} onClose={onClose} />
+      <ChildMenu id={id} />
     </PageModal>
   );
 };