From 13ef6251c688e3139a4f8a7c94ff5dab90719420 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Tue, 6 Sep 2022 00:20:27 +0200 Subject: refactor(frontend): toolbar sm breakpoint Improve toolbar appearance on small screens --- subprojects/frontend/src/TopBar.tsx | 15 +++++++++++++-- subprojects/frontend/src/editor/EditorPane.tsx | 6 +++++- subprojects/frontend/src/editor/GenerateButton.tsx | 12 ++++++++++-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/subprojects/frontend/src/TopBar.tsx b/subprojects/frontend/src/TopBar.tsx index 4424e6b3..a060ff9e 100644 --- a/subprojects/frontend/src/TopBar.tsx +++ b/subprojects/frontend/src/TopBar.tsx @@ -1,10 +1,15 @@ import AppBar from '@mui/material/AppBar'; import Toolbar from '@mui/material/Toolbar'; import Typography from '@mui/material/Typography'; +import { useTheme } from '@mui/material/styles'; +import useMediaQuery from '@mui/material/useMediaQuery'; import { throttle } from 'lodash-es'; +import { observer } from 'mobx-react-lite'; import React, { useEffect, useMemo, useState } from 'react'; +import { useRootStore } from './RootStore'; import ToggleDarkModeButton from './ToggleDarkModeButton'; +import GenerateButton from './editor/GenerateButton'; function useWindowControlsOverlayVisible(): boolean { const [windowControlsOverlayVisible, setWindowControlsOverlayVisible] = @@ -39,8 +44,11 @@ function useWindowControlsOverlayVisible(): boolean { return windowControlsOverlayVisible; } -export default function TopBar(): JSX.Element { +export default observer(function TopBar(): JSX.Element { + const { editorStore } = useRootStore(); const overlayVisible = useWindowControlsOverlayVisible(); + const { breakpoints } = useTheme(); + const showGenerateButton = useMediaQuery(breakpoints.down('sm')); return ( Refinery + {showGenerateButton && ( + + )} ); -} +}); diff --git a/subprojects/frontend/src/editor/EditorPane.tsx b/subprojects/frontend/src/editor/EditorPane.tsx index 079ebcdc..e433e714 100644 --- a/subprojects/frontend/src/editor/EditorPane.tsx +++ b/subprojects/frontend/src/editor/EditorPane.tsx @@ -2,6 +2,8 @@ import Box from '@mui/material/Box'; import Skeleton from '@mui/material/Skeleton'; import Stack from '@mui/material/Stack'; import Toolbar from '@mui/material/Toolbar'; +import { useTheme } from '@mui/material/styles'; +import useMediaQuery from '@mui/material/useMediaQuery'; import { observer } from 'mobx-react-lite'; import React, { useState } from 'react'; @@ -32,12 +34,14 @@ function EditorLoading(): JSX.Element { export default observer(function EditorPane(): JSX.Element { const { editorStore } = useRootStore(); + const { breakpoints } = useTheme(); + const showGenerateButton = useMediaQuery(breakpoints.up('sm')); return ( - + {showGenerateButton && } {editorStore === undefined ? ( diff --git a/subprojects/frontend/src/editor/GenerateButton.tsx b/subprojects/frontend/src/editor/GenerateButton.tsx index 2ffb1a94..485989b5 100644 --- a/subprojects/frontend/src/editor/GenerateButton.tsx +++ b/subprojects/frontend/src/editor/GenerateButton.tsx @@ -7,10 +7,12 @@ import type EditorStore from './EditorStore'; const GENERATE_LABEL = 'Generate'; -export default observer(function GenerateButton({ +const GenerateButton = observer(function GenerateButton({ editorStore, + hideWarnings, }: { editorStore: EditorStore | undefined; + hideWarnings?: boolean | undefined; }): JSX.Element { if (editorStore === undefined) { return ( @@ -26,7 +28,7 @@ export default observer(function GenerateButton({ if (errorCount > 0) { diagnostics.push(`${errorCount} error${errorCount === 1 ? '' : 's'}`); } - if (warningCount > 0) { + if (!(hideWarnings ?? false) && warningCount > 0) { diagnostics.push(`${warningCount} warning${warningCount === 1 ? '' : 's'}`); } const summary = diagnostics.join(' and '); @@ -55,3 +57,9 @@ export default observer(function GenerateButton({ ); }); + +GenerateButton.defaultProps = { + hideWarnings: false, +}; + +export default GenerateButton; -- cgit v1.2.3-70-g09d2