From 17850b8b40c65ab76a0931df8956a74cef98601c Mon Sep 17 00:00:00 2001 From: SrGooglo Date: Mon, 26 Jun 2023 23:31:56 +0000 Subject: [PATCH] split hooks --- .../src/components/Layout/topBar/index.jsx | 29 ++----------------- .../src/components/Layout/topBar/index.less | 5 +--- .../src/hooks/useDefaultVisibility/index.js | 13 +++++++++ .../app/src/hooks/useLayoutInterface/index.js | 13 +++++++++ 4 files changed, 30 insertions(+), 30 deletions(-) create mode 100644 packages/app/src/hooks/useDefaultVisibility/index.js create mode 100644 packages/app/src/hooks/useLayoutInterface/index.js diff --git a/packages/app/src/components/Layout/topBar/index.jsx b/packages/app/src/components/Layout/topBar/index.jsx index ff1d9a5a..a91a8332 100644 --- a/packages/app/src/components/Layout/topBar/index.jsx +++ b/packages/app/src/components/Layout/topBar/index.jsx @@ -2,32 +2,11 @@ import React from "react" import classnames from "classnames" import { Motion, spring } from "react-motion" +import useLayoutInterface from "hooks/useLayoutInterface" +import useDefaultVisibility from "hooks/useDefaultVisibility" + import "./index.less" -const useLayoutInterface = (namespace, ctx) => { - React.useEffect(() => { - if (app.layout["namespace"] === "object") { - throw new Error(`Layout namespace [${namespace}] already exists`) - } - - app.layout[namespace] = ctx - }, []) - - return app.layout[namespace] -} - -const useDefaultVisibility = (defaultValue) => { - const [visible, setVisible] = React.useState(defaultValue ?? false) - - React.useEffect(() => { - setTimeout(() => { - setVisible(true) - }, 10) - }, []) - - return [visible, setVisible] -} - export const UseTopBar = (props) => { app.layout.top_bar.render( @@ -124,8 +103,6 @@ export default (props) => { const heightValue = visible ? Number(app.cores.style.defaultVar("top-bar-height").replace("px", "")) : 0 - console.log(render) - return { + const [visible, setVisible] = React.useState(defaultValue ?? false) + + React.useEffect(() => { + setTimeout(() => { + setVisible(true) + }, 10) + }, []) + + return [visible, setVisible] +} \ No newline at end of file diff --git a/packages/app/src/hooks/useLayoutInterface/index.js b/packages/app/src/hooks/useLayoutInterface/index.js new file mode 100644 index 00000000..d7948a96 --- /dev/null +++ b/packages/app/src/hooks/useLayoutInterface/index.js @@ -0,0 +1,13 @@ +import React from "react" + +export default (namespace, ctx) => { + React.useEffect(() => { + if (app.layout["namespace"] === "object") { + throw new Error(`Layout namespace [${namespace}] already exists`) + } + + app.layout[namespace] = ctx + }, []) + + return app.layout[namespace] +} \ No newline at end of file