Skip to content

Commit 39a5466

Browse files
fix(web): remove FragmentURL on modal close
1 parent 9a733c7 commit 39a5466

File tree

4 files changed

+39
-24
lines changed

4 files changed

+39
-24
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 "tsx:assets/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: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import React, { useEffect, useState } from "react";
1+
import React, { useCallback, useEffect, useState } from "react";
22
import styled, { css } from "styled-components";
33

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

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

@@ -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,22 +88,24 @@ 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);
9396
const [initialTab, setInitialTab] = useState<number>(0);
9497
const location = useLocation();
9598

96-
const initializeNotifications = () => {
97-
const hasNotificationsPath: boolean = location.hash.includes("#notifications");
99+
const initializeFragmentURL = useCallback(() => {
100+
const hash = location.hash;
101+
const hasOnboardingPath = hash.includes("#onboarding");
102+
const hasNotificationsPath = hash.includes("#notifications");
103+
toggleIsOnboardingMiniGuidesOpen(hasOnboardingPath);
98104
toggleIsSettingsOpen(hasNotificationsPath);
99105
setInitialTab(hasNotificationsPath ? 1 : 0);
100-
};
106+
}, [location.hash, toggleIsSettingsOpen, toggleIsOnboardingMiniGuidesOpen]);
101107

102-
useEffect(() => {
103-
initializeNotifications();
104-
}, [location.hash]);
108+
useEffect(initializeFragmentURL, [initializeFragmentURL]);
105109

106110
useLockOverlayScroll(isDappListOpen || isHelpOpen || isSettingsOpen);
107111

@@ -140,6 +144,7 @@ const DesktopHeader = () => {
140144
{isSettingsOpen && <Settings {...{ toggleIsSettingsOpen, isSettingsOpen, initialTab }} />}
141145
</PopupContainer>
142146
)}
147+
{isOnboardingMiniGuidesOpen && <Onboarding toggleMiniGuide={toggleIsOnboardingMiniGuidesOpen} />}
143148
</>
144149
);
145150
};

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

Lines changed: 7 additions & 1 deletion
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";
@@ -76,7 +77,12 @@ const TABS = [
7677
const Settings: React.FC<ISettings> = ({ toggleIsSettingsOpen, initialTab }) => {
7778
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/pages/Home/index.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
import React, { useEffect } from "react";
1+
import React from "react";
22
import styled from "styled-components";
33

4-
import { useLocation, useToggle } from "react-use";
5-
64
import { HomePageProvider } from "hooks/useHomePageContext";
75
import { getOneYearAgoTimestamp } from "utils/date";
86

97
import { responsiveSize } from "styles/responsiveSize";
108

119
import HeroImage from "components/HeroImage";
1210
import LatestCases from "components/LatestCases";
13-
import Onboarding from "components/Popup/MiniGuides/Onboarding";
1411

1512
import Community from "./Community";
1613
import CourtOverview from "./CourtOverview";
@@ -25,16 +22,8 @@ const Container = styled.div`
2522
`;
2623

2724
const Home: React.FC = () => {
28-
const [isOnboardingMiniGuidesOpen, toggleIsOnboardingMiniGuidesOpen] = useToggle(false);
29-
const location = useLocation();
30-
31-
useEffect(() => {
32-
toggleIsOnboardingMiniGuidesOpen(location.hash.includes("#onboarding"));
33-
}, [location.hash]);
34-
3525
return (
3626
<HomePageProvider timeframe={getOneYearAgoTimestamp()}>
37-
{isOnboardingMiniGuidesOpen && <Onboarding toggleMiniGuide={toggleIsOnboardingMiniGuidesOpen} />}
3827
<HeroImage />
3928
<Container>
4029
<CourtOverview />

0 commit comments

Comments
 (0)