From 549217e953dc98a8ec9045a09040fd13e658d16f Mon Sep 17 00:00:00 2001 From: Davor Hrg Date: Tue, 12 Oct 2021 10:44:16 +0100 Subject: [PATCH] Hide console option in view menu (#545) * Update menuConfig.tsx * Revert "Update menuConfig.tsx" This reverts commit 7be28e2a76166566030fdbc788feaa57024543f7. * second attempt * Update mosaic tree to remove and add the console. * Added Toggle UI component * Remove console noise from Toggle component Co-authored-by: Kurt Hutten Co-authored-by: Frank Johnson --- app/web/config/tailwind.config.js | 3 + .../components/IdeContainer/IdeContainer.tsx | 2 +- .../components/IdeSideBar/sidebarConfig.tsx | 104 +++++++++++++++--- app/web/src/components/Toggle/Toggle.tsx | 33 ++++++ app/web/src/helpers/hooks/useIdeState.ts | 2 +- 5 files changed, 129 insertions(+), 15 deletions(-) create mode 100644 app/web/src/components/Toggle/Toggle.tsx diff --git a/app/web/config/tailwind.config.js b/app/web/config/tailwind.config.js index 90382d8..f9123b6 100644 --- a/app/web/config/tailwind.config.js +++ b/app/web/config/tailwind.config.js @@ -98,6 +98,9 @@ module.exports = { minHeight: { md: '28rem', }, + outline: { + gray: ['2px solid #3B3E4B', '8px'], + }, skew: { '-20': '-20deg', }, diff --git a/app/web/src/components/IdeContainer/IdeContainer.tsx b/app/web/src/components/IdeContainer/IdeContainer.tsx index b67be61..d5058b3 100644 --- a/app/web/src/components/IdeContainer/IdeContainer.tsx +++ b/app/web/src/components/IdeContainer/IdeContainer.tsx @@ -106,7 +106,7 @@ const IdeContainer = () => { }} value={state.layout} onChange={(newLayout) => - thunkDispatch({ type: 'setLayout', payload: { message: newLayout } }) + thunkDispatch({ type: 'setLayout', payload: newLayout }) } onRelease={handleViewerSizeUpdate} /> diff --git a/app/web/src/components/IdeSideBar/sidebarConfig.tsx b/app/web/src/components/IdeSideBar/sidebarConfig.tsx index 11925e5..1f20584 100644 --- a/app/web/src/components/IdeSideBar/sidebarConfig.tsx +++ b/app/web/src/components/IdeSideBar/sidebarConfig.tsx @@ -1,6 +1,9 @@ -import React, { ReactNode } from 'react' +import { ReactNode } from 'react' import { SvgNames } from 'src/components/Svg/Svg' import { useIdeContext } from 'src/helpers/hooks/useIdeContext' +import { createRemoveUpdate, updateTree } from 'react-mosaic-component' +import type { MosaicPath } from 'react-mosaic-component' +import Toggle from 'src/components/Toggle' interface SidebarConfigType { name: string @@ -9,6 +12,39 @@ interface SidebarConfigType { panel: ReactNode | null } +interface MosaicTree { + first: string | MosaicTree + second: string | MosaicTree +} + +const getPathById = ( + tree: MosaicTree, + id: string, + path: MosaicPath = [] +): MosaicPath => { + if (tree.first === id || tree.second === id) { + return [...path, tree.first === id ? 'first' : 'second'] + } + if (typeof tree.first !== 'string' && typeof tree.second !== 'string') { + throw new Error('id not found') + } + try { + if (typeof tree.first !== 'string') { + return getPathById(tree.first, id, [...path, 'first']) + } + } catch (error) { + throw new Error('id not found') + } + try { + if (typeof tree.second !== 'string') { + return getPathById(tree.second, id, [...path, 'second']) + } + } catch (error) { + throw new Error('id not found') + } + throw new Error('id not found') +} + export const sidebarTopConfig: SidebarConfigType[] = [ { name: 'Files', @@ -105,18 +141,60 @@ const settingsConfig: settingsConfig[] = [ { title: 'Console', name: 'console', - Content: () => ( -
-

- Coming Soon -

-
-

- We're building configuration settings for the Viewer pane now. Join us - on if you want to lend a hand! -

-
- ), + Content: () => { + const { state, thunkDispatch } = useIdeContext() + const consolePath = React.useMemo(() => { + try { + const path = getPathById(state.layout, 'Console') + return path + } catch (error) { + return null + } + }, [state.layout]) + return ( +
+
  • + +
  • +
    + ) + }, }, ] diff --git a/app/web/src/components/Toggle/Toggle.tsx b/app/web/src/components/Toggle/Toggle.tsx new file mode 100644 index 0000000..5c6a446 --- /dev/null +++ b/app/web/src/components/Toggle/Toggle.tsx @@ -0,0 +1,33 @@ +const Toggle = ({ offLabel = 'off', onLabel = 'on', checked, onChange }) => { + return ( +
    + {offLabel} +
    +
    +
    + {onLabel} + +
    + ) +} + +export default Toggle diff --git a/app/web/src/helpers/hooks/useIdeState.ts b/app/web/src/helpers/hooks/useIdeState.ts index 6b3aff0..185b8b9 100644 --- a/app/web/src/helpers/hooks/useIdeState.ts +++ b/app/web/src/helpers/hooks/useIdeState.ts @@ -182,7 +182,7 @@ const reducer = (state: State, { type, payload }): State => { case 'setLayout': return { ...state, - layout: payload.message, + layout: payload, } case 'updateCamera': return {