Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement the bottom navigation #12

Merged
merged 2 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: implement the bottom navigation
  • Loading branch information
Keonwoo Kim committed Jul 12, 2023
commit 95639c1fa7ed6d1f4cbccc0558c2149dff8d8254
46 changes: 46 additions & 0 deletions client/src/components/Layout.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
import BottomNavigation from "@mui/material/BottomNavigation";
import BottomNavigationAction from "@mui/material/BottomNavigationAction";
import PersonIcon from "@mui/icons-material/Person";
import FavoriteIcon from "@mui/icons-material/Favorite";
import DirectionsWalkIcon from "@mui/icons-material/DirectionsWalk";
import { Frame } from "./Frame";
import { useLocation, useNavigate } from "react-router-dom";
import { useMemo } from "react";

function getTabIndexFromLocation({ pathname }) {
if (pathname.startsWith("/profiles")) return 0;
if (pathname.startsWith("/favorites")) return 2;
return 1;
}

export function Layout({ children, ...props }) {
const location = useLocation();
const navigate = useNavigate();
const index = useMemo(() => getTabIndexFromLocation(location), [location]);

return (
<Frame
wrapperStyle={{
Expand All @@ -9,6 +26,35 @@ export function Layout({ children, ...props }) {
{...props}
>
{children}

<BottomNavigation
showLabels
style={{
position: "fixed",
bottom: 0,
left: 0,
width: "100%",
zIndex: 20,
}}
value={index}
onChange={(event, newValue) => {
if (newValue === index) return;
navigate(
[
"/profiles",
"/challenges",
"/favorites",
][newValue],
);
}}
>
<BottomNavigationAction label="Profile" icon={<PersonIcon />} />
<BottomNavigationAction
label="Challenges"
icon={<DirectionsWalkIcon />}
/>
<BottomNavigationAction label="Favorites" icon={<FavoriteIcon />} />
</BottomNavigation>
</Frame>
);
}
14 changes: 14 additions & 0 deletions client/src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { Challenges } from "./pages/challenges";
import { Walk } from "./pages/challenges-slug-walk";
import { Finish } from "./pages/challenges-slug-finish";
import { Similarity } from "./pages/challenges-slug-similarity";
import { Profile } from "./pages/profiles";
import { Favorites } from "./pages/favorites";
import { MapProvider } from "./components/Map";

const router = createBrowserRouter([
Expand All @@ -33,6 +35,18 @@ const router = createBrowserRouter([
path: "/challenges/:slug/similarity",
element: <Similarity />,
},
{
path: "/profiles",
element: <Profile />,
},
{
path: "/profiles/:id",
element: <Profile />,
},
{
path: "/favorites",
element: <Favorites />,
},
]);

const theme = createTheme({
Expand Down
14 changes: 14 additions & 0 deletions client/src/pages/favorites/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Layout } from "../../components/Layout";

export function Favorites() {
return (
<Layout
style={{
display: "flex",
flexDirection: "column",
}}
>
Favorites!
</Layout>
);
}
14 changes: 14 additions & 0 deletions client/src/pages/profiles/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Layout } from "../../components/Layout";

export function Profile() {
return (
<Layout
style={{
display: "flex",
flexDirection: "column",
}}
>
Profile!
</Layout>
);
}