Skip to content

Commit

Permalink
feat: improve mobile navigation (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
PupoSDC authored Jan 20, 2024
1 parent 7e00544 commit c1a773c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
10 changes: 1 addition & 9 deletions libs/react/components/src/app-buttons/app-buttons.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useEffect, useState } from "react";
import { useRouter } from "next/router";
import { default as ChevronLeftIcon } from "@mui/icons-material/ChevronLeft";
import { default as DarkModeIcon } from "@mui/icons-material/DarkMode";
import { default as GithubIcon } from "@mui/icons-material/GitHub";
Expand Down Expand Up @@ -72,15 +71,8 @@ export const ThemeButton: FunctionComponent<IconButtonProps> = (props) => {
};

export const BackButton: FunctionComponent<IconButtonProps> = (props) => {
const { back } = useRouter();

const onClick: IconButtonProps["onClick"] = (e) => {
props.onClick?.(e);
back();
};

return (
<StyledButton {...props} onClick={onClick}>
<StyledButton {...props}>
<ChevronLeftIcon />
</StyledButton>
);
Expand Down
34 changes: 24 additions & 10 deletions libs/react/containers/src/layouts/layout-module/layout-module.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useRouter } from "next/router";
import { NoSsr } from "@mui/base";
import { default as HomeIcon } from "@mui/icons-material/ConnectingAirportsOutlined";
import { default as TestIcon } from "@mui/icons-material/FlightTakeoffOutlined";
import { default as LearningObjectivesIcon } from "@mui/icons-material/ListOutlined";
Expand All @@ -13,16 +14,17 @@ import {
Stack,
Typography,
listItemContentClasses,
useTheme,
} from "@mui/joy";
import {
AppLogo,
BackButton,
GithubButton,
HamburgerButton,
Sidebar,
SidebarListItem,
ThemeButton,
ThemeOverrideColorScheme,
useMediaQuery,
useSidebar,
} from "@chair-flight/react/components";
import { trpc } from "@chair-flight/trpc/client";
Expand Down Expand Up @@ -62,6 +64,8 @@ export const LayoutModule = container<Props, Params, Data>(
const { openSidebar } = useSidebar();
const router = useRouter();
const config = LayoutModule.useData({ questionBank });
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down("sm"));

const isQuestions = router.asPath.includes("questions");
const isTests = router.asPath.includes("tests");
Expand All @@ -75,6 +79,10 @@ export const LayoutModule = container<Props, Params, Data>(
!isFlashcards &&
!isLearningObjectives;

const secondToLastBreadcrumb = breadcrumbs?.at(-2);
const lastBreadcrumb = breadcrumbs?.at(-1);

console.log(secondToLastBreadcrumb);
return (
<>
<ThemeOverrideColorScheme questionBank={questionBank} />
Expand Down Expand Up @@ -171,15 +179,21 @@ export const LayoutModule = container<Props, Params, Data>(
right: 0,
}}
>
<Breadcrumbs separator="›" sx={{ ml: 2, display: ["none", "flex"] }}>
{breadcrumbs?.slice(0, -1).map(([name, url]) => (
<Link key={url} color="neutral" href={url}>
{name}
</Link>
))}
{breadcrumbs && <Typography>{breadcrumbs?.at(-1)}</Typography>}
</Breadcrumbs>
<BackButton sx={{ ml: 2, display: ["flex", "none"] }} />
<NoSsr>
<Breadcrumbs separator="›" sx={{ ml: 2 }}>
{isMobile && secondToLastBreadcrumb && (
<Link href={secondToLastBreadcrumb[1]}>•••</Link>
)}
{!isMobile &&
breadcrumbs?.slice(0, -1).map(([name, url]) => (
<Link key={url} color="neutral" href={url}>
{name}
</Link>
))}
{lastBreadcrumb && <Typography>{lastBreadcrumb}</Typography>}
</Breadcrumbs>
</NoSsr>

<GithubButton sx={{ ml: "auto" }} />
<ThemeButton />
<HamburgerButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ export const QuestionSearch = container<Props, Params, Data>(
<Stack
direction="row"
sx={{
mb: 2,
mb: { xs: 1, sm: 2 },
gap: 1,

[`& .${selectClasses.root}`]: {
display: { xs: "none", md: "flex" },
width: "13em",
Expand Down

1 comment on commit c1a773c

@vercel
Copy link

@vercel vercel bot commented on c1a773c Jan 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.