diff --git a/src/app/App.js b/src/app/App.js index aa08e73..618c37c 100644 --- a/src/app/App.js +++ b/src/app/App.js @@ -8,6 +8,7 @@ import loadable from "@loadable/component"; import { useAuth0 } from "@auth0/auth0-react"; import buildApolloClient from "./apolloClient"; +import PageLayout from "./PageLayout"; const ItemsPage = loadable(() => import("./ItemsPage")); const HomePage = loadable(() => import("./HomePage")); @@ -49,10 +50,14 @@ function App() { - + + + - + + + diff --git a/src/app/HomePage.js b/src/app/HomePage.js index bcf7193..ea8c388 100644 --- a/src/app/HomePage.js +++ b/src/app/HomePage.js @@ -5,21 +5,16 @@ import { Box, Button, Flex, - IconButton, Input, - useColorMode, useColorModeValue, useTheme, useToast, } from "@chakra-ui/core"; -import { MoonIcon, SunIcon } from "@chakra-ui/icons"; -import { Link, useHistory, useLocation } from "react-router-dom"; +import { useHistory, useLocation } from "react-router-dom"; import { useLazyQuery } from "@apollo/client"; -import { useAuth0 } from "@auth0/auth0-react"; import { Heading1, usePageTitle } from "./util"; import OutfitPreview from "./components/OutfitPreview"; -import useCurrentUser from "./components/useCurrentUser"; import HomepageSplashImg from "../images/homepage-splash.png"; import HomepageSplashImg2x from "../images/homepage-splash@2x.png"; @@ -32,13 +27,7 @@ function HomePage() { const [previewState, setPreviewState] = React.useState(null); return ( - - - - - - - + - {username && Hi, {username}!} - {id && ( - - )} - - - ); - } else { - return ( - - ); - } -} - function StartOutfitForm({ onChange }) { const history = useHistory(); @@ -289,21 +236,6 @@ function SubmitPetForm() { ); } -function ColorModeToggleButton() { - const { colorMode, toggleColorMode } = useColorMode(); - - return ( - : } - onClick={toggleColorMode} - variant="ghost" - /> - ); -} - /** * useSupportSetup helps our support staff get set up with special access. * If you provide ?supportSecret=... in the URL, we'll save it in a cookie and diff --git a/src/app/ItemsPage.js b/src/app/ItemsPage.js index b4e8af9..804ad05 100644 --- a/src/app/ItemsPage.js +++ b/src/app/ItemsPage.js @@ -32,23 +32,19 @@ function ItemsPage() { if (loading) { return ( - + ); } if (error) { - return ( - - {error.message} - - ); + return {error.message}; } return ( - - + + {isCurrentUser ? "Items you own" : `Items ${data.user.username} owns`} diff --git a/src/app/PageLayout.js b/src/app/PageLayout.js new file mode 100644 index 0000000..9e62219 --- /dev/null +++ b/src/app/PageLayout.js @@ -0,0 +1,79 @@ +import React from "react"; +import { Box, Button, IconButton, useColorMode } from "@chakra-ui/core"; +import { Link } from "react-router-dom"; +import { useAuth0 } from "@auth0/auth0-react"; +import { MoonIcon, SunIcon } from "@chakra-ui/icons"; + +import useCurrentUser from "./components/useCurrentUser"; + +function PageLayout({ children }) { + return ( + + + + + + + {children} + + ); +} + +function UserLoginLogout() { + const { isLoading, isAuthenticated, loginWithRedirect, logout } = useAuth0(); + const { id, username } = useCurrentUser(); + + if (isLoading) { + return null; + } + + if (isAuthenticated) { + return ( + + {username && Hi, {username}!} + {id && ( + + )} + + + ); + } else { + return ( + + ); + } +} + +function ColorModeToggleButton() { + const { colorMode, toggleColorMode } = useColorMode(); + + return ( + : } + onClick={toggleColorMode} + variant="ghost" + /> + ); +} + +export default PageLayout;