diff --git a/src/App.tsx b/src/App.tsx index 3021702..3b1e5de 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,11 +1,24 @@ import { Outlet } from "react-router-dom"; +import { useDimensions } from "./utils/hooks"; +import { setMenuDimensions } from "./features/pageDimensions/pageDimensionsSlice"; + import { MainMenu } from "./components/Menu"; +import { useDispatch } from "react-redux"; +import { useEffect } from "react"; function App() { + const dispatch = useDispatch(); + const [ref, { height }] = useDimensions(); + + useEffect(() => { + // Make sure to not dispatch during a render. + dispatch(setMenuDimensions({ height })); + }, [height]); + return (
- +
); diff --git a/src/features/pageDimensions/pageDimensionsSelector.ts b/src/features/pageDimensions/pageDimensionsSelector.ts new file mode 100644 index 0000000..413d347 --- /dev/null +++ b/src/features/pageDimensions/pageDimensionsSelector.ts @@ -0,0 +1,3 @@ +import { RootState } from "../../types/state"; + +export const menuSelector = (state: RootState) => state.pageDimensions.menu; diff --git a/src/index.tsx b/src/index.tsx index 434acab..20efb90 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -20,8 +20,9 @@ ReactDOM.render( - } /> - } /> + } > + } /> + diff --git a/src/routes/BroadcastRoute.tsx b/src/routes/BroadcastRoute.tsx index 8cdfbce..dd6b436 100644 --- a/src/routes/BroadcastRoute.tsx +++ b/src/routes/BroadcastRoute.tsx @@ -1,15 +1,15 @@ +import { useSelector } from "react-redux"; + import { FullScreenContainer } from "./styles"; import { Layout } from "../components/Broadcast/Layout"; -import { MainMenu } from "../components/Menu"; -import { useDimensions } from "../utils/hooks"; +import { menuSelector } from "../features/pageDimensions/pageDimensionsSelector"; export default function Broadcast() { - const [ref, { height }] = useDimensions(); + const { height } = useSelector(menuSelector); return ( - - - + + ); } diff --git a/src/routes/styles.ts b/src/routes/styles.ts index 59729c3..c81523a 100644 --- a/src/routes/styles.ts +++ b/src/routes/styles.ts @@ -3,16 +3,21 @@ import styled from "styled-components"; type FullScreenContainerProps = { minHeight?: number, minWidth?: number, -} + heightCutoff?: number, + widthCutoff?: number, +}; export const FullScreenContainer = styled.div` --minHeight: ${({ minHeight = 0 }) => `${minHeight}px`}; --minWidth: ${({ minWidth = 0 }) => `${minWidth}px`}; --overflowY: ${({ minHeight }) => minHeight ? "scroll" : "hidden" }; --overflowX: ${({ minWidth }) => minWidth ? "scroll" : "hidden" }; + --heightCutoff: ${({ heightCutoff = 0 }) => `${heightCutoff}px`}; + --widthCutoff: ${({ widthCutoff = 0 }) => `${widthCutoff}px`}; - height: 100vh; - width: 100%; + position: relative; + height: calc(100vh - var(--heightCutoff)); + width: calc(100vw - var(--widthCutoff)); /* Demand a minimum width/height and scroll to support them. */ min-height: var(--minHeight);