ISSUE-011 - Hooked up Redux. Switched to using embedded route. Using central store to keep track of menu height information. Refactored fullscreen calculations.

This commit is contained in:
Kyle Geib committed 2022-01-06 14:08:43 -05:00
1 parent 3add2f3237
commit f3e4ac318c
5 files changed
+34 -12

No files matched your search

+14 -1
View File
@@ -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<HTMLDivElement>();
useEffect(() => {
// Make sure to not dispatch during a render.
dispatch(setMenuDimensions({ height }));
}, [height]);
return (
<div className="App">
<MainMenu />
<MainMenu ref={ref} />
<Outlet />
</div>
);
@@ -0,0 +1,3 @@
import { RootState } from "../../types/state";
export const menuSelector = (state: RootState) => state.pageDimensions.menu;
+3 -2
View File
@@ -20,8 +20,9 @@ ReactDOM.render(
<GlobalFonts />
<BrowserRouter>
<Routes>
<Route path="/" element={<App />} />
<Route path="/broadcast" element={<Broadcast />} />
<Route path="/" element={<App />} >
<Route path="/broadcast" element={<Broadcast />} />
</Route>
</Routes>
</BrowserRouter>
</ThemeProvider>
+6 -6
View File
@@ -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<HTMLDivElement>();
const { height } = useSelector(menuSelector);
return (
<FullScreenContainer minHeight={700} minWidth={900}>
<MainMenu ref={ref}/>
<Layout headerHeight={height} />
<FullScreenContainer minHeight={700} minWidth={900} heightCutoff={height}>
<Layout />
</FullScreenContainer>
);
}
+8 -3
View File
@@ -3,16 +3,21 @@ import styled from "styled-components";
type FullScreenContainerProps = {
minHeight?: number,
minWidth?: number,
}
heightCutoff?: number,
widthCutoff?: number,
};
export const FullScreenContainer = styled.div<FullScreenContainerProps>`
--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);