Skip to content

Commit 12f1370

Browse files
committed
feat: scroll top improvements
1 parent b7b7656 commit 12f1370

File tree

10 files changed

+73
-32
lines changed

10 files changed

+73
-32
lines changed

web/src/components/Field.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import { landscapeStyle } from "styles/landscapeStyle";
44

55
import { Link } from "react-router-dom";
66

7-
import { useScrollTop } from "hooks/useScrollTop";
8-
97
const FieldContainer = styled.div<FieldContainerProps>`
108
display: flex;
119
align-items: center;
@@ -96,8 +94,6 @@ const Field: React.FC<IField> = ({
9694
isJurorBalance,
9795
className,
9896
}) => {
99-
const scrollTop = useScrollTop();
100-
10197
return (
10298
<FieldContainer isList={displayAsList} {...{ isOverview, isJurorBalance, width, className }}>
10399
<Icon />
@@ -108,7 +104,6 @@ const Field: React.FC<IField> = ({
108104
to={link}
109105
onClick={(event) => {
110106
event.stopPropagation();
111-
scrollTop();
112107
}}
113108
>
114109
{value}

web/src/pages/Cases/AttachmentDisplay/index.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import React, { lazy, Suspense } from "react";
1+
import React, { lazy, Suspense, useEffect } from "react";
22
import styled from "styled-components";
33

44
import { useSearchParams } from "react-router-dom";
55

6+
import { useScrollTop } from "hooks/useScrollTop";
7+
68
import NewTabIcon from "svgs/icons/new-tab.svg";
79

810
import Loader from "components/Loader";
@@ -39,8 +41,13 @@ const StyledNewTabIcon = styled(NewTabIcon)`
3941

4042
const AttachmentDisplay: React.FC = () => {
4143
const [searchParams] = useSearchParams();
42-
4344
const url = searchParams.get("url");
45+
const scrollTop = useScrollTop();
46+
47+
useEffect(() => {
48+
scrollTop();
49+
}, []);
50+
4451
return (
4552
<Container>
4653
<Header />

web/src/pages/Cases/CasesFetcher.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import React, { useMemo } from "react";
1+
import React, { useEffect, useMemo } from "react";
22

33
import { useParams, useNavigate } from "react-router-dom";
44

55
import useIsDesktop from "hooks/useIsDesktop";
6+
import { useScrollTop } from "hooks/useScrollTop";
67
import { isUndefined } from "utils/index";
78
import { decodeURIFilter, useRootPath } from "utils/uri";
89

@@ -47,6 +48,7 @@ const CasesFetcher: React.FC = () => {
4748
const location = useRootPath();
4849
const navigate = useNavigate();
4950
const isDesktop = useIsDesktop();
51+
const scrollTop = useScrollTop();
5052
const casesPerPage = isDesktop ? 9 : 3;
5153
const pageNumber = parseInt(page ?? "1");
5254
const disputeSkip = casesPerPage * (pageNumber - 1);
@@ -69,6 +71,10 @@ const CasesFetcher: React.FC = () => {
6971
[totalCases, casesPerPage]
7072
);
7173

74+
useEffect(() => {
75+
scrollTop();
76+
}, []);
77+
7278
return (
7379
<CasesDisplay
7480
disputes={data?.disputes as DisputeDetailsFragment[]}

web/src/pages/Courts/CourtDetails/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react";
1+
import React, { useEffect } from "react";
22
import styled, { css } from "styled-components";
33

44
import { useParams } from "react-router-dom";
@@ -9,6 +9,8 @@ import { Card, Breadcrumb } from "@kleros/ui-components-library";
99
import { isProductionDeployment } from "consts/index";
1010
import { isUndefined } from "utils/index";
1111

12+
import { useScrollTop } from "hooks/useScrollTop";
13+
1214
import { useCourtPolicy } from "queries/useCourtPolicy";
1315
import { useCourtTree, CourtTreeQuery } from "queries/useCourtTree";
1416

@@ -83,6 +85,7 @@ const CourtDetails: React.FC = () => {
8385
const { data: policy } = useCourtPolicy(id);
8486
const { data } = useCourtTree();
8587
const [isStakingMiniGuideOpen, toggleStakingMiniGuide] = useToggle(false);
88+
const scrollTop = useScrollTop();
8689

8790
const courtPath = getCourtsPath(data?.court, id);
8891

@@ -94,6 +97,10 @@ const CourtDetails: React.FC = () => {
9497
})) ?? [])
9598
);
9699

100+
useEffect(() => {
101+
scrollTop();
102+
}, []);
103+
97104
return (
98105
<Container>
99106
<StyledCard>

web/src/pages/Dashboard/Courts/CourtCard/CourtName.tsx

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ import React from "react";
22
import styled, { css } from "styled-components";
33

44
import { landscapeStyle } from "styles/landscapeStyle";
5-
import LightButton from "components/LightButton";
65

76
import ArrowIcon from "svgs/icons/arrow.svg";
8-
import { useNavigateAndScrollTop } from "hooks/useNavigateAndScrollTop";
7+
import { Link } from "react-router-dom";
98

109
const Container = styled.div`
1110
display: flex;
@@ -29,17 +28,13 @@ const Container = styled.div`
2928
)}
3029
`;
3130

32-
const StyledButton = styled(LightButton)`
31+
const StyledLink = styled(Link)`
3332
display: flex;
34-
flex-direction: row-reverse;
3533
gap: 8px;
36-
padding: 0px;
37-
> .button-text {
38-
color: ${({ theme }) => theme.primaryBlue};
39-
font-size: 14px;
40-
}
41-
> .button-svg {
42-
margin-right: 0;
34+
align-items: center;
35+
> svg {
36+
height: 15px;
37+
width: 15px;
4338
path {
4439
fill: ${({ theme }) => theme.primaryBlue};
4540
}
@@ -52,17 +47,12 @@ interface ICourtName {
5247
}
5348

5449
const CourtName: React.FC<ICourtName> = ({ name, id }) => {
55-
const navigate = useNavigateAndScrollTop();
56-
5750
return (
5851
<Container>
5952
<small>{name}</small>
60-
<StyledButton
61-
onClick={() => navigate(`/courts/${id?.toString()}`)}
62-
text="Open Court"
63-
Icon={ArrowIcon}
64-
className="reverse-button"
65-
/>
53+
<StyledLink to={`/courts/${id?.toString()}`}>
54+
Open Court <ArrowIcon />
55+
</StyledLink>
6656
</Container>
6757
);
6858
};

web/src/pages/Dashboard/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useMemo } from "react";
1+
import React, { useEffect, useMemo } from "react";
22
import styled from "styled-components";
33

44
import { useNavigate, useParams } from "react-router-dom";
@@ -7,6 +7,8 @@ import { useAccount } from "wagmi";
77
import { isUndefined } from "utils/index";
88
import { decodeURIFilter, useRootPath } from "utils/uri";
99

10+
import { useScrollTop } from "hooks/useScrollTop";
11+
1012
import { DisputeDetailsFragment, useMyCasesQuery } from "queries/useCasesQuery";
1113
import { useUserQuery } from "queries/useUser";
1214

@@ -49,6 +51,7 @@ const Dashboard: React.FC = () => {
4951
const { page, order, filter } = useParams();
5052
const location = useRootPath();
5153
const navigate = useNavigate();
54+
const scrollTop = useScrollTop();
5255
const casesPerPage = 3;
5356
const pageNumber = parseInt(page ?? "1");
5457
const disputeSkip = casesPerPage * (pageNumber - 1);
@@ -68,6 +71,10 @@ const Dashboard: React.FC = () => {
6871
[totalCases, casesPerPage]
6972
);
7073

74+
useEffect(() => {
75+
scrollTop();
76+
}, []);
77+
7178
return (
7279
<Container>
7380
{isConnected ? (

web/src/pages/GetPnk/index.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import React from "react";
1+
import React, { useEffect } from "react";
22
import styled from "styled-components";
33

44
import { isProductionDeployment } from "consts/index";
55

66
import { responsiveSize } from "styles/responsiveSize";
77

8+
import { useScrollTop } from "hooks/useScrollTop";
9+
810
import ClaimPnkButton from "components/ClaimPnkButton";
911
import HeroImage from "components/HeroImage";
1012

@@ -28,6 +30,12 @@ const Container = styled.div`
2830
`;
2931

3032
const GetPnk: React.FC = () => {
33+
const scrollTop = useScrollTop();
34+
35+
useEffect(() => {
36+
scrollTop();
37+
}, []);
38+
3139
return (
3240
<Wrapper>
3341
<HeroImage />

web/src/pages/Home/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import React from "react";
1+
import React, { useEffect } from "react";
22
import styled from "styled-components";
33

44
import { HomePageProvider } from "hooks/useHomePageContext";
5+
import { useScrollTop } from "hooks/useScrollTop";
56
import { getOneYearAgoTimestamp } from "utils/date";
67

78
import { responsiveSize } from "styles/responsiveSize";
@@ -26,6 +27,12 @@ const Container = styled.div`
2627
`;
2728

2829
const Home: React.FC = () => {
30+
const scrollTop = useScrollTop();
31+
32+
useEffect(() => {
33+
scrollTop();
34+
}, []);
35+
2936
return (
3037
<HomePageProvider timeframe={getOneYearAgoTimestamp()}>
3138
<Wrapper>

web/src/pages/Resolver/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react";
1+
import React, { useEffect } from "react";
22
import styled, { css } from "styled-components";
33

44
import { Navigate, Route, Routes, useLocation } from "react-router-dom";
@@ -8,6 +8,8 @@ import { useAccount } from "wagmi";
88
import { landscapeStyle } from "styles/landscapeStyle";
99
import { responsiveSize } from "styles/responsiveSize";
1010

11+
import { useScrollTop } from "hooks/useScrollTop";
12+
1113
import ConnectWallet from "components/ConnectWallet";
1214
import EnsureAuth from "components/EnsureAuth";
1315
import HeroImage from "components/HeroImage";
@@ -77,8 +79,13 @@ const DisputeResolver: React.FC = () => {
7779
const location = useLocation();
7880
const [isDisputeResolverMiniGuideOpen, toggleDisputeResolverMiniGuide] = useToggle(false);
7981
const { isConnected } = useAccount();
82+
const scrollTop = useScrollTop();
8083
const isPreviewPage = location.pathname.includes("/preview");
8184

85+
useEffect(() => {
86+
scrollTop();
87+
}, []);
88+
8289
return (
8390
<Wrapper>
8491
<HeroImage />

web/src/pages/Settings/EmailConfirmation/index.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { isAddress } from "viem";
66

77
import { Button } from "@kleros/ui-components-library";
88

9+
import { useScrollTop } from "hooks/useScrollTop";
10+
911
import CheckIcon from "svgs/icons/check-circle-outline.svg";
1012
import WarningIcon from "svgs/icons/warning-outline.svg";
1113
import InvalidIcon from "svgs/label-icons/minus-circle.svg";
@@ -138,6 +140,7 @@ const EmailConfirmation: React.FC = () => {
138140
const [isTokenInvalid, setIsTokenInvalid] = useState(false);
139141
const [isError, setIsError] = useState(false);
140142
const [searchParams, _] = useSearchParams();
143+
const scrollTop = useScrollTop();
141144
const address = searchParams.get("address");
142145
const token = searchParams.get("token");
143146

@@ -155,6 +158,10 @@ const EmailConfirmation: React.FC = () => {
155158
}
156159
}, [address, token, confirmEmail]);
157160

161+
useEffect(() => {
162+
scrollTop();
163+
}, []);
164+
158165
const { headerMsg, subtitleMsg, buttonMsg, buttonTo, Icon, color } = useMemo(() => {
159166
if (!address || !isAddress(address) || !token || isTokenInvalid) return messageConfigs.invalid;
160167
if (isError) return messageConfigs.error;

0 commit comments

Comments
 (0)