Skip to content

Commit aeecb23

Browse files
authored
Merge pull request #1607 from kleros/feat(web)/Extra-path-to-the-open-Notifications-and-Onboarding-miniguide
Feat(web)/extra path to the open notifications and onboarding miniguide
2 parents 6e3a6a3 + b1f62dc commit aeecb23

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed

web/src/components/Popup/MiniGuides/MainStructureTemplate.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import React, { Dispatch, SetStateAction, useRef } from "react";
1+
import React, { Dispatch, SetStateAction, useCallback, useRef } from "react";
22
import styled, { css } from "styled-components";
33

4+
import { useLocation, useNavigate } from "react-router-dom";
45
import { useClickAway } from "react-use";
56
import BookOpenIcon from "svgs/icons/book-open.svg";
67

@@ -164,9 +165,16 @@ const Template: React.FC<ITemplate> = ({
164165
isVisible,
165166
}) => {
166167
const containerRef = useRef(null);
168+
const location = useLocation();
169+
const navigate = useNavigate();
170+
const removeOnboardingHashPath = useCallback(() => {
171+
if (isOnboarding && location.hash.includes("#onboarding")) navigate("#", { replace: true });
172+
}, [location.hash, navigate, isOnboarding]);
173+
167174
useClickAway(containerRef, () => {
168175
if (canClose) {
169176
onClose();
177+
removeOnboardingHashPath();
170178
}
171179
});
172180

@@ -196,7 +204,14 @@ const Template: React.FC<ITemplate> = ({
196204
/>
197205
</LeftContainer>
198206
<RightContainer>
199-
<Close onClick={onClose}>Close</Close>
207+
<Close
208+
onClick={() => {
209+
onClose();
210+
removeOnboardingHashPath();
211+
}}
212+
>
213+
Close
214+
</Close>
200215
{RightContent}
201216
</RightContainer>
202217
</Container>

web/src/layout/Header/DesktopHeader.tsx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import React from "react";
1+
import React, { useCallback, useEffect, useState } from "react";
22
import styled, { css } from "styled-components";
33

4+
import { useLocation } from "react-router-dom";
45
import { useToggle } from "react-use";
56

67
import KlerosSolutionsIcon from "svgs/menu-icons/kleros-solutions.svg";
@@ -13,6 +14,7 @@ import { responsiveSize } from "styles/responsiveSize";
1314
import ConnectWallet from "components/ConnectWallet";
1415
import LightButton from "components/LightButton";
1516
import { Overlay } from "components/Overlay";
17+
import Onboarding from "components/Popup/MiniGuides/Onboarding";
1618

1719
import Logo from "./Logo";
1820
import DappList from "./navbar/DappList";
@@ -86,10 +88,25 @@ const PopupContainer = styled.div`
8688
z-index: 30;
8789
`;
8890

89-
const DesktopHeader = () => {
91+
const DesktopHeader: React.FC = () => {
9092
const [isDappListOpen, toggleIsDappListOpen] = useToggle(false);
9193
const [isHelpOpen, toggleIsHelpOpen] = useToggle(false);
9294
const [isSettingsOpen, toggleIsSettingsOpen] = useToggle(false);
95+
const [isOnboardingMiniGuidesOpen, toggleIsOnboardingMiniGuidesOpen] = useToggle(false);
96+
const [initialTab, setInitialTab] = useState<number>(0);
97+
const location = useLocation();
98+
99+
const initializeFragmentURL = useCallback(() => {
100+
const hash = location.hash;
101+
const hasOnboardingPath = hash.includes("#onboarding");
102+
const hasNotificationsPath = hash.includes("#notifications");
103+
toggleIsOnboardingMiniGuidesOpen(hasOnboardingPath);
104+
toggleIsSettingsOpen(hasNotificationsPath);
105+
setInitialTab(hasNotificationsPath ? 1 : 0);
106+
}, [location.hash, toggleIsSettingsOpen, toggleIsOnboardingMiniGuidesOpen]);
107+
108+
useEffect(initializeFragmentURL, [initializeFragmentURL]);
109+
93110
useLockOverlayScroll(isDappListOpen || isHelpOpen || isSettingsOpen);
94111

95112
return (
@@ -124,9 +141,10 @@ const DesktopHeader = () => {
124141
<Overlay />
125142
{isDappListOpen && <DappList {...{ toggleIsDappListOpen, isDappListOpen }} />}
126143
{isHelpOpen && <Help {...{ toggleIsHelpOpen, isHelpOpen }} />}
127-
{isSettingsOpen && <Settings {...{ toggleIsSettingsOpen, isSettingsOpen }} />}
144+
{isSettingsOpen && <Settings {...{ toggleIsSettingsOpen, isSettingsOpen, initialTab }} />}
128145
</PopupContainer>
129146
)}
147+
{isOnboardingMiniGuidesOpen && <Onboarding toggleMiniGuide={toggleIsOnboardingMiniGuidesOpen} />}
130148
</>
131149
);
132150
};

web/src/layout/Header/navbar/Menu/Settings/index.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useRef, useState } from "react";
22
import styled, { css } from "styled-components";
33

4+
import { useLocation, useNavigate } from "react-router-dom";
45
import { useClickAway } from "react-use";
56

67
import { Tabs } from "@kleros/ui-components-library";
@@ -73,10 +74,15 @@ const TABS = [
7374
},
7475
];
7576

76-
const Settings: React.FC<ISettings> = ({ toggleIsSettingsOpen }) => {
77-
const [currentTab, setCurrentTab] = useState<number>(0);
77+
const Settings: React.FC<ISettings> = ({ toggleIsSettingsOpen, initialTab }) => {
78+
const [currentTab, setCurrentTab] = useState<number>(initialTab || 0);
7879
const containerRef = useRef(null);
79-
useClickAway(containerRef, () => toggleIsSettingsOpen());
80+
const location = useLocation();
81+
const navigate = useNavigate();
82+
useClickAway(containerRef, () => {
83+
toggleIsSettingsOpen();
84+
if (location.hash.includes("#notifications")) navigate("#", { replace: true });
85+
});
8086

8187
return (
8288
<>

web/src/layout/Header/navbar/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ const PopupContainer = styled.div`
8282

8383
export interface ISettings {
8484
toggleIsSettingsOpen: () => void;
85+
initialTab?: number;
8586
}
8687

8788
export interface IHelp {

0 commit comments

Comments
 (0)