-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathindex.tsx
163 lines (138 loc) · 3.77 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import React from "react";
import styled, { css } from "styled-components";
import { useParams } from "react-router-dom";
import { useToggle } from "react-use";
import { Card, Breadcrumb } from "@kleros/ui-components-library";
import { isProductionDeployment } from "consts/index";
import { isUndefined } from "utils/index";
import { useCourtPolicy } from "queries/useCourtPolicy";
import { useCourtTree, CourtTreeQuery } from "queries/useCourtTree";
import { landscapeStyle } from "styles/landscapeStyle";
import { responsiveSize } from "styles/responsiveSize";
import ClaimPnkButton from "components/ClaimPnkButton";
import HowItWorks from "components/HowItWorks";
import LatestCases from "components/LatestCases";
import Staking from "components/Popup/MiniGuides/Staking";
import { StyledSkeleton } from "components/StyledSkeleton";
import ScrollTop from "components/ScrollTop";
import Description from "./Description";
import StakePanel from "./StakePanel";
import Stats from "./Stats";
const Container = styled.div``;
const CourtHeader = styled.h1`
display: flex;
flex-direction: row;
justify-content: space-between;
gap: 24px;
flex-wrap: wrap;
margin-bottom: 24px;
${landscapeStyle(
() => css`
margin-bottom: 32px;
`
)};
`;
const CourtInfo = styled.div`
display: flex;
flex-direction: column;
gap: 8px;
`;
const ButtonContainer = styled.div`
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: center;
gap: 20px;
${landscapeStyle(
() => css`
align-items: flex-end;
`
)};
`;
const StyledCard = styled(Card)`
padding: ${responsiveSize(16, 32)};
padding-bottom: 16px;
margin-top: 12px;
width: 100%;
height: auto;
min-height: 100px;
`;
const StyledBreadcrumb = styled(Breadcrumb)`
align-items: center;
button {
font-size: 16px;
}
`;
const CourtDetails: React.FC = () => {
const { id } = useParams();
const { data: policy } = useCourtPolicy(id);
const { data } = useCourtTree();
const [isStakingMiniGuideOpen, toggleStakingMiniGuide] = useToggle(false);
const courtPath = getCourtsPath(data?.court, id);
const items = [];
items.push(
...(courtPath?.map((node) => ({
text: node.name,
value: node.id,
})) ?? [])
);
return (
<Container>
<StyledCard>
<CourtHeader>
<CourtInfo>
{policy ? policy.name : <StyledSkeleton width={200} />}
{items.length > 1 && items[0]?.value !== 1 ? <StyledBreadcrumb items={items} /> : null}
</CourtInfo>
<ButtonContainer>
{!isProductionDeployment() && <ClaimPnkButton />}
<HowItWorks
isMiniGuideOpen={isStakingMiniGuideOpen}
toggleMiniGuide={toggleStakingMiniGuide}
MiniGuideComponent={Staking}
/>
</ButtonContainer>
</CourtHeader>
<StakePanel id={!isUndefined(id) ? id : ""} courtName={policy?.name} />
<Stats />
</StyledCard>
<StyledCard>
<Description />
</StyledCard>
<LatestCases filters={{ court: id }} />
<ScrollTop />
</Container>
);
};
export default CourtDetails;
interface IItem {
name: string;
id: string;
}
export const getCourtsPath = (
node: CourtTreeQuery["court"],
id: string | undefined,
path: IItem[] = []
): IItem[] | null => {
if (!node || !id) return null;
if (node.id === id) {
path.unshift({
name: node.name || "",
id: node.id,
});
return path;
}
if (node.children) {
for (const child of node.children) {
const pathFromChild = getCourtsPath(child, id, path.slice());
if (pathFromChild) {
pathFromChild.unshift({
name: node.name || "",
id: node.id,
});
return pathFromChild;
}
}
}
return null;
};