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

Navbar mobile refactored design #1568

Merged
merged 7 commits into from
Jun 21, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
clean up
  • Loading branch information
mertbagt committed Jun 7, 2024
commit c1984cd6f2c79bfadde3e063219324115b73d4f9
217 changes: 118 additions & 99 deletions components/MobileNav.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { useTranslation } from "next-i18next"
import React, { FC, useState } from "react"
import Image from "react-bootstrap/Image"
import styled from "styled-components"
import { SignInWithButton, signOutAndRedirectToHome, useAuth } from "./auth"
import { Container, Nav, Navbar, NavDropdown } from "./bootstrap"
import { Col, Nav, Navbar, NavDropdown } from "./bootstrap"
import { useProfile } from "./db"
import {
Avatar,
Expand All @@ -20,37 +22,87 @@ import {
NavbarLinkWhyUse
} from "./NavbarComponents"

const NavBarBoxContainer: FC<
React.PropsWithChildren<{ className?: string }>
> = ({ children, className }) => {
return (
<div
className={`d-flex flex-row align-items-start justify-content-between w-100`}
>
{children}
</div>
)
}
export const MobileNav: React.FC<React.PropsWithChildren<unknown>> = () => {
const BlackCollapse = styled(() => {
return (
<Navbar.Collapse id="basic-navbar-nav" className="bg-black mt-2 ps-4">
{/* while MAPLE is trying to do away with inline styling *
* both styled-components and bootstrap class have been *
* ignoring height properties for some reason */}
<div style={{ height: "100vh" }}>
{whichMenu == "site" ? <SiteLinks /> : <ProfileLinks />}
</div>
</Navbar.Collapse>
)
})`
.bg-black {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Could this just use the bootstrap provided bg-dark and save some boilerplate? IMO we should probably start pushing designs to standardize on our bootstrap theme colors anyway.

background-color: black;
}
`

const NavBarBox: FC<React.PropsWithChildren<{ className?: string }>> = ({
children,
className
}) => {
return (
<div
className={`col d-flex justify-content-start align-items-center ${className}`}
>
{children}
</div>
)
}
const ProfileLinks = () => {
return (
<Nav className="my-4 d-flex align-items-start">
<NavbarLinkViewProfile />
<NavbarLinkEditProfile
handleClick={() => {
closeNav()
}}
/>
<NavbarLinkSignOut
handleClick={() => {
closeNav()
void signOutAndRedirectToHome()
}}
/>
</Nav>
)
}

const SiteLinks = () => {
return (
<Nav className="my-4">
<NavbarLinkBills handleClick={closeNav} />
<NavbarLinkTestimony handleClick={closeNav} />
<NavDropdown className={"navLink-primary"} title={t("about")}>
<NavbarLinkGoals handleClick={closeNav} />
<NavbarLinkTeam handleClick={closeNav} />
<NavbarLinkSupport handleClick={closeNav} />
<NavbarLinkFAQ handleClick={closeNav} />
</NavDropdown>

<NavDropdown className={"navLink-primary"} title={t("learn")}>
<NavbarLinkEffective handleClick={closeNav} />
<NavbarLinkProcess handleClick={closeNav} />
<NavbarLinkWhyUse handleClick={closeNav} />
</NavDropdown>
</Nav>
)
}

export const MobileNav: React.FC<React.PropsWithChildren<unknown>> = () => {
const { authenticated } = useAuth()
const [isExpanded, setIsExpanded] = useState(false)
const [whichMenu, setWhichMenu] = useState("site")
const { t } = useTranslation(["common", "auth"])

const toggleNav = () => setIsExpanded(!isExpanded)
const toggleSite = () => {
if (isExpanded && whichMenu == "profile") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: for these toggles, if we're setting menu to the same value in both branches, should we move the setMenu call outside the branch?

setWhichMenu("site")
} else {
setWhichMenu("site")
setIsExpanded(!isExpanded)
}
}

const toggleAvatar = () => {
if (isExpanded && whichMenu == "site") {
setWhichMenu("profile")
} else {
setWhichMenu("profile")
setIsExpanded(!isExpanded)
}
}

const closeNav = () => setIsExpanded(false)

const result = useProfile()
Expand All @@ -59,83 +111,50 @@ export const MobileNav: React.FC<React.PropsWithChildren<unknown>> = () => {
return (
<Navbar
bg="secondary"
variant="dark"
sticky="top"
expand={false}
expanded={isExpanded}
className={`w-100 ${isExpanded ? "pb-0" : ""}`}
data-bs-theme="dark"
expand="lg"
expanded={isExpanded}
>
<Container fluid>
<NavBarBoxContainer>
<NavBarBox>
<Navbar expand={false} expanded={isExpanded}>
<Navbar.Brand>
<Navbar.Toggle aria-controls="topnav" onClick={toggleNav} />
</Navbar.Brand>
<Navbar.Collapse id="topnav">
<Nav className="me-auto">
<NavbarLinkBills handleClick={closeNav} />
<NavbarLinkTestimony handleClick={closeNav} />

<NavDropdown className={"navLink-primary"} title={t("about")}>
<NavbarLinkGoals handleClick={closeNav} />
<NavbarLinkTeam handleClick={closeNav} />
<NavbarLinkSupport handleClick={closeNav} />
<NavbarLinkFAQ handleClick={closeNav} />
</NavDropdown>

<NavDropdown className={"navLink-primary"} title={t("learn")}>
<NavbarLinkEffective handleClick={closeNav} />
<NavbarLinkProcess handleClick={closeNav} />
<NavbarLinkWhyUse handleClick={closeNav} />
</NavDropdown>
</Nav>
</Navbar.Collapse>
</Navbar>
</NavBarBox>

<Col className="ms-3 ps-2">
<Navbar.Brand onClick={toggleSite}>
{isExpanded && whichMenu == "site" ? (
<Image
src="/Union.svg"
alt="x"
width="35"
height="35"
className="ms-2"
/>
) : (
<Navbar.Toggle aria-controls="basic-navbar-nav" />
)}
</Navbar.Brand>
</Col>
<Col>
<div className="d-flex justify-content-center">
<NavbarLinkLogo />
</div>
</Col>
<Col className="d-flex justify-content-end me-3 pe-2">
{authenticated ? (
<>
<Navbar.Brand onClick={toggleAvatar}>
<Nav.Link className="p-0 text-white">
{isExpanded && whichMenu == "profile" ? (
<Image src="/Union.svg" alt="x" width="35" height="35" />
) : (
<Avatar isOrg={isOrg} />
)}
</Nav.Link>
</Navbar.Brand>
</>
) : (
<SignInWithButton />
)}
</Col>

<NavBarBox className={`justify-content-end`}>
<Navbar
expand={false}
expanded={isExpanded}
variant="dark"
bg="secondary"
collapseOnSelect={true}
className="d-flex justify-content-end"
>
{authenticated ? (
<>
<Navbar.Brand onClick={toggleNav}>
<Nav.Link className="p-0 text-white">
<Avatar isOrg={isOrg} />
</Nav.Link>
</Navbar.Brand>
<Navbar.Collapse id="profile-nav">
<Nav className="me-4 d-flex align-items-end">
<NavbarLinkViewProfile />
<NavbarLinkEditProfile
handleClick={() => {
closeNav()
}}
/>
<NavbarLinkSignOut
handleClick={() => {
closeNav()
void signOutAndRedirectToHome()
}}
/>
</Nav>
</Navbar.Collapse>
</>
) : (
<SignInWithButton />
)}
</Navbar>
</NavBarBox>
</NavBarBoxContainer>
</Container>
<BlackCollapse />
</Navbar>
)
}