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: make mobile navbar close when clicking on header, make it occup… #1761

Draft
wants to merge 10 commits into
base: dev
Choose a base branch
from
2 changes: 1 addition & 1 deletion web/src/components/DisputeView/DisputeInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const DisputeInfo: React.FC<IDisputeInfo> = ({
{
icon: CalendarIcon,
name: getPeriodPhrase(period ?? 0),
value: !displayAsList ? new Date(date * 1000).toLocaleString() : formatDate(date),
value: !displayAsList ? new Date(date * 1000).toLocaleString() + " (Local Time)" : formatDate(date),
display: !isUndefined(period) && !isUndefined(date),
style: "grid-column: 2 / 4;",
},
Expand Down
52 changes: 28 additions & 24 deletions web/src/layout/Header/MobileHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React, { useContext, useMemo, useRef } from "react";
import React, { useState } from "react";
import styled, { css } from "styled-components";

import { useClickAway, useToggle } from "react-use";

import HamburgerIcon from "svgs/header/hamburger.svg";

import { useLockBodyScroll } from "react-use";

import { landscapeStyle } from "styles/landscapeStyle";

import LightButton from "components/LightButton";
Expand Down Expand Up @@ -37,30 +36,35 @@ const StyledLightButton = styled(LightButton)`
}
`;

const OpenContext = React.createContext({
isOpen: false,
toggleIsOpen: () => {
// Placeholder
},
});

export function useOpenContext() {
return useContext(OpenContext);
}
const Overlay = styled.div`
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 64px;
z-index: 1;
`;
kemuru marked this conversation as resolved.
Show resolved Hide resolved

const MobileHeader = () => {
const [isOpen, toggleIsOpen] = useToggle(false);
const containerRef = useRef(null);
useClickAway(containerRef, () => toggleIsOpen(false));
const memoizedContext = useMemo(() => ({ isOpen, toggleIsOpen }), [isOpen, toggleIsOpen]);
const [isOpen, setIsOpen] = useState(false);
useLockBodyScroll(isOpen);

const handleOpenNavbar = () => {
setIsOpen(true);
};

const handleCloseNavbar = () => {
setIsOpen(false);
};

return (
<Container ref={containerRef}>
<OpenContext.Provider value={memoizedContext}>
<Logo />
<NavBar />
<StyledLightButton text="" Icon={HamburgerIcon} onClick={toggleIsOpen} />
</OpenContext.Provider>
<Container>
{isOpen ? <Overlay {...{ isOpen }} onClick={handleCloseNavbar} /> : null}
<Logo />
<StyledLightButton text="" Icon={HamburgerIcon} onClick={handleOpenNavbar} />
<NavBar {...{ isOpen, handleCloseNavbar }} />
</Container>
);
};

export default MobileHeader;
5 changes: 1 addition & 4 deletions web/src/layout/Header/navbar/DappList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { landscapeStyle } from "styles/landscapeStyle";
import { responsiveSize } from "styles/responsiveSize";

import Product from "./Product";
import { IDappList } from "./index";

const Header = styled.h1`
padding-top: 32px;
Expand Down Expand Up @@ -136,10 +137,6 @@ const ITEMS = [
},
];

interface IDappList {
toggleIsDappListOpen: () => void;
}

const DappList: React.FC<IDappList> = ({ toggleIsDappListOpen }) => {
const containerRef = useRef(null);
useClickAway(containerRef, () => toggleIsDappListOpen());
Expand Down
11 changes: 6 additions & 5 deletions web/src/layout/Header/navbar/Explore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { Link, useLocation } from "react-router-dom";
import { landscapeStyle } from "styles/landscapeStyle";
import { responsiveSize } from "styles/responsiveSize";

import { useOpenContext } from "../MobileHeader";

const Container = styled.div`
display: flex;
gap: 0px;
Expand Down Expand Up @@ -59,9 +57,12 @@ const links = [
{ to: "/get-pnk", text: "Get PNK" },
];

const Explore: React.FC = () => {
interface IExplore {
handleCloseNavbar?: () => void;
}

const Explore: React.FC<IExplore> = ({ handleCloseNavbar }) => {
kemuru marked this conversation as resolved.
Show resolved Hide resolved
const location = useLocation();
const { toggleIsOpen } = useOpenContext();

return (
<Container>
Expand All @@ -70,7 +71,7 @@ const Explore: React.FC = () => {
<LinkContainer key={text}>
<StyledLink
to={to}
onClick={toggleIsOpen}
onClick={handleCloseNavbar}
isActive={to === "/" ? location.pathname === "/" : location.pathname.startsWith(to)}
>
{text}
Expand Down
2 changes: 1 addition & 1 deletion web/src/layout/Header/navbar/Menu/Help.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { landscapeStyle } from "styles/landscapeStyle";

import Onboarding from "components/Popup/MiniGuides/Onboarding";

import { IHelp } from "..";
import { IHelp } from "../index";
import Debug from "../Debug";

const Container = styled.div`
Expand Down
26 changes: 9 additions & 17 deletions web/src/layout/Header/navbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@ import { useAccount } from "wagmi";

import KlerosSolutionsIcon from "svgs/menu-icons/kleros-solutions.svg";

import { useLockOverlayScroll } from "hooks/useLockOverlayScroll";

import ConnectWallet from "components/ConnectWallet";
import LightButton from "components/LightButton";
import { Overlay } from "components/Overlay";

import { useOpenContext } from "../MobileHeader";

import DappList from "./DappList";
import Explore from "./Explore";
import Menu from "./Menu";
Expand All @@ -40,7 +35,7 @@ const Container = styled.div<{ isOpen: boolean }>`
top: 0;
left: 0;
right: 0;
max-height: calc(100vh - 160px);
height: 100%;
overflow-y: auto;
z-index: 1;
background-color: ${({ theme }) => theme.whiteBackground};
Expand Down Expand Up @@ -94,28 +89,25 @@ export interface IDappList {
toggleIsDappListOpen: () => void;
}

const NavBar: React.FC = () => {
interface INavBar {
isOpen: boolean;
handleCloseNavbar: () => void;
}

const NavBar: React.FC<INavBar> = ({ isOpen, handleCloseNavbar }) => {
kemuru marked this conversation as resolved.
Show resolved Hide resolved
const { isConnected } = useAccount();
const [isDappListOpen, toggleIsDappListOpen] = useToggle(false);
const [isHelpOpen, toggleIsHelpOpen] = useToggle(false);
const [isSettingsOpen, toggleIsSettingsOpen] = useToggle(false);
const { isOpen } = useOpenContext();
useLockOverlayScroll(isOpen);

return (
<>
<Wrapper {...{ isOpen }}>
<StyledOverlay>
<Container {...{ isOpen }}>
<LightButton
text="Kleros Solutions"
onClick={() => {
toggleIsDappListOpen();
}}
Icon={KlerosSolutionsIcon}
/>
<LightButton text="Kleros Solutions" onClick={toggleIsDappListOpen} Icon={KlerosSolutionsIcon} />
<hr />
<Explore />
<Explore {...{ handleCloseNavbar }} />
<hr />
<WalletContainer>
<ConnectWallet />
Expand Down