add cute back to home link
This commit is contained in:
parent
e33e5fb88f
commit
b086a4a8d7
2 changed files with 67 additions and 14 deletions
|
@ -55,7 +55,7 @@ function App() {
|
||||||
</PageLayout>
|
</PageLayout>
|
||||||
</Route>
|
</Route>
|
||||||
<Route path="/">
|
<Route path="/">
|
||||||
<PageLayout>
|
<PageLayout hideHomeLink>
|
||||||
<HomePage />
|
<HomePage />
|
||||||
</PageLayout>
|
</PageLayout>
|
||||||
</Route>
|
</Route>
|
||||||
|
|
|
@ -1,16 +1,25 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { Box, Button, IconButton, useColorMode } from "@chakra-ui/core";
|
import { Box, Button, HStack, IconButton, useColorMode } from "@chakra-ui/core";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import { useAuth0 } from "@auth0/auth0-react";
|
import { useAuth0 } from "@auth0/auth0-react";
|
||||||
import { MoonIcon, SunIcon } from "@chakra-ui/icons";
|
import { ChevronLeftIcon, MoonIcon, SunIcon } from "@chakra-ui/icons";
|
||||||
|
|
||||||
import useCurrentUser from "./components/useCurrentUser";
|
import useCurrentUser from "./components/useCurrentUser";
|
||||||
|
|
||||||
function PageLayout({ children }) {
|
// TODO: Replace with lower-res version
|
||||||
|
import HomepageSplashImg from "../images/homepage-splash.png";
|
||||||
|
|
||||||
|
function PageLayout({ children, hideHomeLink }) {
|
||||||
return (
|
return (
|
||||||
<Box padding="6" paddingTop="3">
|
<Box padding="6" paddingTop="3">
|
||||||
<Box width="100%" display="flex" alignItems="center" marginBottom="6">
|
<Box
|
||||||
<ColorModeToggleButton />
|
width="100%"
|
||||||
|
display="flex"
|
||||||
|
alignItems="center"
|
||||||
|
flexWrap="wrap"
|
||||||
|
marginBottom="6"
|
||||||
|
>
|
||||||
|
{!hideHomeLink && <HomeLink />}
|
||||||
<Box flex="1 0 0" />
|
<Box flex="1 0 0" />
|
||||||
<UserLoginLogout />
|
<UserLoginLogout />
|
||||||
</Box>
|
</Box>
|
||||||
|
@ -19,6 +28,47 @@ function PageLayout({ children }) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function HomeLink() {
|
||||||
|
return (
|
||||||
|
<Box
|
||||||
|
as={Link}
|
||||||
|
to="/"
|
||||||
|
display="flex"
|
||||||
|
alignItems="center"
|
||||||
|
position="relative"
|
||||||
|
role="group"
|
||||||
|
transition="transform 0.2s"
|
||||||
|
_hover={{ transform: "scale(1.1)" }}
|
||||||
|
_focus={{ outline: "0", transform: "scale(1.1)" }}
|
||||||
|
>
|
||||||
|
<Box position="absolute" right="100%">
|
||||||
|
<ChevronLeftIcon />
|
||||||
|
</Box>
|
||||||
|
<Box
|
||||||
|
as="img"
|
||||||
|
src={HomepageSplashImg}
|
||||||
|
alt=""
|
||||||
|
height="2em"
|
||||||
|
width="2em"
|
||||||
|
borderRadius="lg"
|
||||||
|
boxShadow="md"
|
||||||
|
/>
|
||||||
|
<Box
|
||||||
|
height="2em"
|
||||||
|
width="2em"
|
||||||
|
position="absolute"
|
||||||
|
top="0"
|
||||||
|
left="0"
|
||||||
|
right="0"
|
||||||
|
bottom="0"
|
||||||
|
borderRadius="lg"
|
||||||
|
transition="border 0.2s"
|
||||||
|
_groupFocus={{ border: "2px", borderColor: "green.400" }}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function UserLoginLogout() {
|
function UserLoginLogout() {
|
||||||
const { isLoading, isAuthenticated, loginWithRedirect, logout } = useAuth0();
|
const { isLoading, isAuthenticated, loginWithRedirect, logout } = useAuth0();
|
||||||
const { id, username } = useCurrentUser();
|
const { id, username } = useCurrentUser();
|
||||||
|
@ -29,15 +79,15 @@ function UserLoginLogout() {
|
||||||
|
|
||||||
if (isAuthenticated) {
|
if (isAuthenticated) {
|
||||||
return (
|
return (
|
||||||
<Box display="flex" alignItems="center">
|
<HStack align="center" spacing="2">
|
||||||
{username && <Box fontSize="sm">Hi, {username}!</Box>}
|
{username && <Box fontSize="sm">Hi, {username}!</Box>}
|
||||||
|
<ColorModeToggleButton />
|
||||||
{id && (
|
{id && (
|
||||||
<Button
|
<Button
|
||||||
as={Link}
|
as={Link}
|
||||||
to={`/user/${id}/items`}
|
to={`/user/${id}/items`}
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
marginLeft="2"
|
|
||||||
>
|
>
|
||||||
Items
|
Items
|
||||||
</Button>
|
</Button>
|
||||||
|
@ -46,17 +96,19 @@ function UserLoginLogout() {
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
onClick={() => logout({ returnTo: window.location.origin })}
|
onClick={() => logout({ returnTo: window.location.origin })}
|
||||||
marginLeft="2"
|
|
||||||
>
|
>
|
||||||
Log out
|
Log out
|
||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</HStack>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
<Button size="sm" variant="outline" onClick={() => loginWithRedirect()}>
|
<HStack align="center" spacing="2">
|
||||||
Log in
|
<ColorModeToggleButton />
|
||||||
</Button>
|
<Button size="sm" variant="outline" onClick={() => loginWithRedirect()}>
|
||||||
|
Log in
|
||||||
|
</Button>
|
||||||
|
</HStack>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,7 +123,8 @@ function ColorModeToggleButton() {
|
||||||
}
|
}
|
||||||
icon={colorMode === "light" ? <MoonIcon /> : <SunIcon />}
|
icon={colorMode === "light" ? <MoonIcon /> : <SunIcon />}
|
||||||
onClick={toggleColorMode}
|
onClick={toggleColorMode}
|
||||||
variant="ghost"
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue