From b3954c1091dc88381916077853e591110e2b3dfe Mon Sep 17 00:00:00 2001 From: goodmice Date: Mon, 26 Dec 2022 17:57:56 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20=D0=BE=D0=BA=D1=80?= =?UTF-8?q?=D1=8B=D1=82=D0=B8=D1=8F=20=D1=81=D0=B5=D0=BB=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B0=20=D1=81=D0=BA=D0=B2=D0=B0=D0=B6=D0=B8=D0=BD?= =?UTF-8?q?=20=D0=B2=20LayoutPropsContext?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/LayoutPortal.tsx | 4 +++- src/context/layout_props.ts | 16 ++++++++++++---- src/pages/Deposit/index.jsx | 2 +- src/pages/Well/index.jsx | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/components/LayoutPortal.tsx b/src/components/LayoutPortal.tsx index ef88f30..c9c9d9c 100644 --- a/src/components/LayoutPortal.tsx +++ b/src/components/LayoutPortal.tsx @@ -55,6 +55,8 @@ const _LayoutPortal = memo(() => { const setLayoutProps = useCallback((props: LayoutPortalProps) => setProps({ ...defaultProps, ...props}), []) + const layoutPropsValue = useMemo(() => ({ setLayoutProps, openWellTreeSelector: () => setWellsTreeOpen(true) }), [setLayoutProps]) + useEffect(() => { if (typeof showSelector === 'boolean') setWellsTreeOpen(showSelector) @@ -123,7 +125,7 @@ const _LayoutPortal = memo(() => { {topRightBlock} )} - + }> diff --git a/src/context/layout_props.ts b/src/context/layout_props.ts index cd07ff3..fb2db5b 100644 --- a/src/context/layout_props.ts +++ b/src/context/layout_props.ts @@ -2,22 +2,30 @@ import { createContext, useContext, useEffect } from 'react' import { LayoutPortalProps } from '@components/LayoutPortal' +export type LayoutPropsContext = { + setLayoutProps: (props: LayoutPortalProps) => void + openWellTreeSelector: () => void +} + /** Контекст метода редактирования параметров заголовка и меню */ -export const LayoutPropsContext = createContext<(props: LayoutPortalProps) => void>(() => {}) +export const LayoutPropsContext = createContext({ + setLayoutProps: () => {}, + openWellTreeSelector: () => {}, +}) /** * Получить метод задания параметров заголовка и меню * * @returns Получить метод задания параметров заголовка и меню */ -export const useLayoutProps = (props?: LayoutPortalProps) => { - const setLayoutProps = useContext(LayoutPropsContext) +export const useLayoutProps = (props?: LayoutPortalProps): LayoutPropsContext => { + const { setLayoutProps, ...other } = useContext(LayoutPropsContext) useEffect(() => { if (props) setLayoutProps(props) }, [setLayoutProps, props]) - return setLayoutProps + return { setLayoutProps, ...other } } /** Контекст для блока справа от крошек на страницах скважин и админки */ diff --git a/src/pages/Deposit/index.jsx b/src/pages/Deposit/index.jsx index a4cadf6..e727016 100644 --- a/src/pages/Deposit/index.jsx +++ b/src/pages/Deposit/index.jsx @@ -16,7 +16,7 @@ const breadcrumb = makeMenuBreadcrumbItemsRender(menuItems, /^\/deposit\/[^\/#?] const Deposit = memo(() => { const { '*': param } = useParams() - const setLayoutProps = useLayoutProps() + const { setLayoutProps } = useLayoutProps() const deposits = useDepositList() const root = useRootPath() diff --git a/src/pages/Well/index.jsx b/src/pages/Well/index.jsx index 61a42a7..8c5df4d 100644 --- a/src/pages/Well/index.jsx +++ b/src/pages/Well/index.jsx @@ -50,7 +50,7 @@ const Well = memo(() => { const root = useRootPath() const rootPath = useMemo(() => `${root}/well/${idWell}`, [root, idWell]) - const setLayoutProps = useLayoutProps() + const { setLayoutProps } = useLayoutProps() const updateWell = useCallback((data) => invokeWebApiWrapperAsync( async () => {