diff --git a/src/app/GlobalNavBar.js b/src/app/GlobalNavBar.js new file mode 100644 index 0000000..7fec604 --- /dev/null +++ b/src/app/GlobalNavBar.js @@ -0,0 +1,193 @@ +import React from "react"; +import { + Box, + Button, + HStack, + IconButton, + Menu, + MenuButton, + MenuItem, + MenuList, + useBreakpointValue, + useColorMode, +} from "@chakra-ui/core"; +import { Link, useLocation } from "react-router-dom"; +import { useAuth0 } from "@auth0/auth0-react"; +import { + ChevronLeftIcon, + HamburgerIcon, + MoonIcon, + SunIcon, +} from "@chakra-ui/icons"; + +import useCurrentUser from "./components/useCurrentUser"; + +import HomeLinkIcon from "../images/home-link-icon.png"; +import HomeLinkIcon2x from "../images/home-link-icon@2x.png"; + +function GlobalNavBar() { + const navStyle = useBreakpointValue({ base: "menu", md: "buttons" }); + + return ( + + + + {navStyle === "menu" && } + {navStyle === "buttons" && } + + + + + + ); +} + +function HomeLink() { + const { pathname } = useLocation(); + const isHomePage = pathname === "/"; + + return ( + + + + + + + + ); +} + +function UserNavBarSection() { + const { isLoading, isAuthenticated, loginWithRedirect, logout } = useAuth0(); + const { id, username } = useCurrentUser(); + + if (isLoading) { + return null; + } + + if (isAuthenticated) { + return ( + + {username && ( + + Hi, {username}! + + )} + {id && ( + + Items + + )} + logout({ returnTo: window.location.origin })}> + Log out + + + ); + } else { + return loginWithRedirect()}>Log in; + } +} + +function NavMenu() { + const { colorMode, toggleColorMode } = useColorMode(); + + return ( + + } /> + + + Modeling + + + {colorMode === "light" ? ( + + Dark mode + + + ) : ( + + Light mode + + + )} + + + + ); +} + +function NavButtons() { + const { colorMode, toggleColorMode } = useColorMode(); + + return ( + <> + + Modeling + + : } + onClick={toggleColorMode} + /> + + ); +} + +const NavButton = React.forwardRef(({ icon, ...props }, ref) => { + const Component = icon ? IconButton : Button; + + // Opacity is in a separate Box, to avoid overriding the built-in Button + // hover/focus states. + return ( + + + + ); +}); + +export default GlobalNavBar; diff --git a/src/app/PageLayout.js b/src/app/PageLayout.js index 2d3cc0e..767f05e 100644 --- a/src/app/PageLayout.js +++ b/src/app/PageLayout.js @@ -1,204 +1,23 @@ import React from "react"; -import { - Box, - Button, - HStack, - IconButton, - Menu, - MenuButton, - MenuItem, - MenuList, - useBreakpointValue, - useColorMode, -} from "@chakra-ui/core"; -import { Link, useLocation } from "react-router-dom"; -import { useAuth0 } from "@auth0/auth0-react"; -import { - ChevronLeftIcon, - HamburgerIcon, - MoonIcon, - SunIcon, -} from "@chakra-ui/icons"; +import { Box } from "@chakra-ui/core"; +import loadable from "@loadable/component"; -import useCurrentUser from "./components/useCurrentUser"; - -import HomeLinkIcon from "../images/home-link-icon.png"; -import HomeLinkIcon2x from "../images/home-link-icon@2x.png"; +const GlobalNavBar = loadable(() => import("./GlobalNavBar")); function PageLayout({ children }) { - const navStyle = useBreakpointValue({ base: "menu", md: "buttons" }); - return ( - - - {navStyle === "menu" && } - {navStyle === "buttons" && } - - - - + {children} ); } -function HomeLink() { - const { pathname } = useLocation(); - const isHomePage = pathname === "/"; - - return ( - - - - - - - - ); -} - -function UserNavBarSection() { - const { isLoading, isAuthenticated, loginWithRedirect, logout } = useAuth0(); - const { id, username } = useCurrentUser(); - - if (isLoading) { - return null; - } - - if (isAuthenticated) { - return ( - - {username && ( - - Hi, {username}! - - )} - {id && ( - - Items - - )} - logout({ returnTo: window.location.origin })}> - Log out - - - ); - } else { - return loginWithRedirect()}>Log in; - } -} - -function NavMenu() { - const { colorMode, toggleColorMode } = useColorMode(); - - return ( - - } /> - - - Modeling - - - {colorMode === "light" ? ( - - Dark mode - - - ) : ( - - Light mode - - - )} - - - - ); -} - -function NavButtons() { - const { colorMode, toggleColorMode } = useColorMode(); - - return ( - <> - - Modeling - - : } - onClick={toggleColorMode} - /> - - ); -} - -const NavButton = React.forwardRef(({ icon, ...props }, ref) => { - const Component = icon ? IconButton : Button; - - // Opacity is in a separate Box, to avoid overriding the built-in Button - // hover/focus states. - return ( - - - - ); -}); - export default PageLayout;