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 () => {