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 all commits
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
6 changes: 1 addition & 5 deletions components/DesktopNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useTranslation } from "next-i18next"
import React from "react"
import { SignInWithButton, signOutAndRedirectToHome, useAuth } from "./auth"
import { Container, Dropdown, Nav, NavDropdown } from "./bootstrap"
import { useProfile } from "./db"

import {
Avatar,
Expand All @@ -25,9 +24,6 @@ export const DesktopNav: React.FC<React.PropsWithChildren<unknown>> = () => {
const { authenticated } = useAuth()
const { t } = useTranslation(["common", "auth"])

const result = useProfile()
let isOrg = result?.profile?.role === "organization"

return (
<Container fluid className={`bg-secondary d-flex py-2 sticky-top`}>
<NavbarLinkLogo />
Expand Down Expand Up @@ -81,7 +77,7 @@ export const DesktopNav: React.FC<React.PropsWithChildren<unknown>> = () => {
<div className={`align-self-center justify-content-end`}>
<Dropdown>
<Dropdown.Toggle className={`btn-secondary`}>
<Avatar isOrg={isOrg} />
<Avatar />
</Dropdown.Toggle>
<Dropdown.Menu>
<NavDropdown.Item>
Expand Down
219 changes: 115 additions & 104 deletions components/MobileNav.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useTranslation } from "next-i18next"
import React, { FC, useState } from "react"
import React, { 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 { useProfile } from "./db"
import { Col, Nav, Navbar, NavDropdown } from "./bootstrap"
import {
Avatar,
NavbarLinkBills,
Expand All @@ -20,122 +21,132 @@ 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, *
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, sadly setting specific heights aren't covered by bootstrap. Weird that styled-components aren't respecting that - not worth digging into here, but thanks for the heads up to look out for this issue in the future.

That said, why do we need to set a specific height here? Shouldn't the menu just be the height of the links list, whichever set of links we're dealing with?

* both styled-components and bootstrap classes 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 closeNav = () => setIsExpanded(false)
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 result = useProfile()
let isOrg = result?.profile?.role === "organization"
const closeNav = () => setIsExpanded(false)

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>

<NavbarLinkLogo />

<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>
</>
<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 className="d-flex justify-content-center">
<NavbarLinkLogo handleClick={closeNav} />
</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" />
) : (
<SignInWithButton />
<Avatar />
)}
</Navbar>
</NavBarBox>
</NavBarBoxContainer>
</Container>
</Nav.Link>
</Navbar.Brand>
) : (
<SignInWithButton />
)}
</Col>

<BlackCollapse />
</Navbar>
)
}
10 changes: 8 additions & 2 deletions components/NavbarComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import Image from "react-bootstrap/Image"
import { useMediaQuery } from "usehooks-ts"
import { useAuth } from "./auth"
import { Nav, NavDropdown } from "./bootstrap"
import { useProfile } from "./db"
import { NavLink } from "./Navlink"

export const Avatar = ({ isOrg }: { isOrg: boolean }) => {
export const Avatar = () => {
const result = useProfile()
let isOrg = result?.profile?.role === "organization"

return (
<>
{isOrg ? (
Expand Down Expand Up @@ -134,16 +138,18 @@ export const NavbarLinkGoals: React.FC<

export const NavbarLinkLogo: React.FC<
React.PropsWithChildren<{
handleClick?: any
other?: any
}>
> = ({ other }) => {
> = ({ handleClick, other }) => {
const isMobile = useMediaQuery("(max-width: 768px)")
const { t } = useTranslation(["common", "auth"])
return (
<div
className={
isMobile ? "" : "align-items-center justify-content-start me-3"
}
onClick={handleClick}
>
<NavLink className={isMobile ? "" : "py-0 px-2"} href="/" {...other}>
<Image
Expand Down
3 changes: 3 additions & 0 deletions public/Union.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.