11import React from "react" ;
22import styled , { css } from "styled-components" ;
3+ import { landscapeStyle } from "styles/landscapeStyle" ;
34import { Periods } from "consts/periods" ;
45import { useIsList } from "context/IsListProvider" ;
56import BookmarkIcon from "svgs/icons/bookmark.svg" ;
@@ -8,21 +9,71 @@ import LawBalanceIcon from "svgs/icons/law-balance.svg";
89import PileCoinsIcon from "svgs/icons/pile-coins.svg" ;
910import RoundIcon from "svgs/icons/round.svg" ;
1011import Field from "../Field" ;
12+ import { getCourtsPath } from "pages/Courts/CourtDetails" ;
13+ import { useCourtTree } from "hooks/queries/useCourtTree" ;
1114
12- const Container = styled . div < { isList : boolean } > `
15+ const Container = styled . div < { isList : boolean ; isOverview ?: boolean } > `
1316 display: flex;
14- flex-direction: ${ ( { isList } ) => ( isList ? "row" : "column" ) } ;
17+ width: 100% ;
1518 gap: 8px;
19+ flex-direction: column;
20+ justify-content: flex-end;
1621
1722 ${ ( { isList } ) =>
1823 isList &&
1924 css `
20- gap : calc (4px + (24px - 4px ) * ((100vw - 300px ) / (900 - 300 )));
25+ ${ landscapeStyle (
26+ ( ) => css `
27+ gap : 0 ;
28+ height : 100% ;
29+ `
30+ ) }
31+ ` } ;
32+ ` ;
33+
34+ const CourtBranchFieldContainer = styled . div < { isList ?: boolean ; isOverview ?: boolean } > `
35+ ${ ( { isOverview } ) =>
36+ isOverview &&
37+ css `
38+ display : flex;
39+ margin-top : 16px ;
40+ flex-wrap : wrap;
2141 ` } ;
22- justify-content: ${ ( { isList } ) => ( isList ? "space-around" : "center" ) } ;
42+ ` ;
43+
44+ const RestOfFieldsContainer = styled . div < { isList ?: boolean ; isOverview ?: boolean } > `
45+ display: flex;
46+ flex-direction: column;
47+ gap: 8px;
48+ justify-content: center;
2349 align-items: center;
2450 width: 100%;
2551 height: 100%;
52+
53+ ${ ( { isList } ) =>
54+ isList &&
55+ css `
56+ ${ landscapeStyle (
57+ ( ) => css `
58+ flex-direction : row;
59+ gap : calc (4px + (24px - 4px ) * ((100vw - 300px ) / (900 - 300 )));
60+ justify-content : space-around;
61+ `
62+ ) }
63+ ` } ;
64+ ${ ( { isOverview } ) =>
65+ isOverview &&
66+ css `
67+ ${ landscapeStyle (
68+ ( ) => css `
69+ margin-top : 16px ;
70+ gap : 32px ;
71+ flex-direction : row;
72+ flex-wrap : wrap;
73+ justify-content : flex-start;
74+ `
75+ ) }
76+ ` } ;
2677` ;
2778
2879const getPeriodPhrase = ( period : Periods ) : string => {
@@ -47,6 +98,7 @@ export interface IDisputeInfo {
4798 date ?: number ;
4899 round ?: number ;
49100 overrideIsList ?: boolean ;
101+ isOverview ?: boolean ;
50102}
51103
52104const formatDate = ( date : number ) => {
@@ -65,35 +117,92 @@ const DisputeInfo: React.FC<IDisputeInfo> = ({
65117 date,
66118 round,
67119 overrideIsList,
120+ isOverview,
68121} ) => {
69122 const { isList } = useIsList ( ) ;
70123 const displayAsList = isList && ! overrideIsList ;
124+ const { data } = useCourtTree ( ) ;
125+ const courtPath = getCourtsPath ( data ?. court , courtId ) ;
126+ const items = [ ] ;
127+ items . push (
128+ ...( courtPath ?. map ( ( node ) => ( {
129+ text : node . name ,
130+ value : node . id ,
131+ } ) ) ?? [ ] )
132+ ) ;
133+ const courtBranchValue = items . map ( ( item ) => item . text ) . join ( " / " ) ;
71134
72135 return (
73- < Container isList = { displayAsList } >
74- { court && courtId && (
75- < Field
76- icon = { LawBalanceIcon }
77- name = "Court"
78- value = { court }
79- link = { `/courts/${ courtId } ` }
80- displayAsList = { displayAsList }
81- />
82- ) }
83- { category && < Field icon = { BookmarkIcon } name = "Category" value = { category } displayAsList = { displayAsList } /> }
84- { ! category && displayAsList && (
85- < Field icon = { BookmarkIcon } name = "Category" value = "General" displayAsList = { displayAsList } />
86- ) }
87- { round && < Field icon = { RoundIcon } name = "Round" value = { round . toString ( ) } displayAsList = { displayAsList } /> }
88- { rewards && < Field icon = { PileCoinsIcon } name = "Juror Rewards" value = { rewards } displayAsList = { displayAsList } /> }
89- { typeof period !== "undefined" && date && (
90- < Field
91- icon = { CalendarIcon }
92- name = { getPeriodPhrase ( period ) }
93- value = { ! displayAsList ? new Date ( date * 1000 ) . toLocaleString ( ) : formatDate ( date ) }
94- displayAsList = { displayAsList }
95- />
96- ) }
136+ < Container isList = { displayAsList } isOverview = { isOverview } >
137+ < CourtBranchFieldContainer isOverview = { isOverview } >
138+ { court && courtId && isOverview && (
139+ < Field
140+ icon = { LawBalanceIcon }
141+ name = "Court Branch"
142+ value = { courtBranchValue }
143+ displayAsList = { displayAsList }
144+ isOverview = { isOverview }
145+ />
146+ ) }
147+ </ CourtBranchFieldContainer >
148+ < RestOfFieldsContainer isOverview = { isOverview } isList = { displayAsList } >
149+ { court && courtId && ! isOverview && (
150+ < Field
151+ icon = { LawBalanceIcon }
152+ name = "Court"
153+ value = { court }
154+ link = { `/courts/${ courtId } ` }
155+ displayAsList = { displayAsList }
156+ isOverview = { isOverview }
157+ />
158+ ) }
159+
160+ { category && (
161+ < Field
162+ icon = { BookmarkIcon }
163+ name = "Category"
164+ value = { category }
165+ displayAsList = { displayAsList }
166+ isOverview = { isOverview }
167+ />
168+ ) }
169+ { ! category && displayAsList && (
170+ < Field
171+ icon = { BookmarkIcon }
172+ name = "Category"
173+ value = "General"
174+ displayAsList = { displayAsList }
175+ isOverview = { isOverview }
176+ />
177+ ) }
178+ { round && (
179+ < Field
180+ icon = { RoundIcon }
181+ name = "Round"
182+ value = { round . toString ( ) }
183+ displayAsList = { displayAsList }
184+ isOverview = { isOverview }
185+ />
186+ ) }
187+ { rewards && (
188+ < Field
189+ icon = { PileCoinsIcon }
190+ name = "Juror Rewards"
191+ value = { rewards }
192+ displayAsList = { displayAsList }
193+ isOverview = { isOverview }
194+ />
195+ ) }
196+ { typeof period !== "undefined" && date && (
197+ < Field
198+ icon = { CalendarIcon }
199+ name = { getPeriodPhrase ( period ) }
200+ value = { ! displayAsList ? new Date ( date * 1000 ) . toLocaleString ( ) : formatDate ( date ) }
201+ displayAsList = { displayAsList }
202+ isOverview = { isOverview }
203+ />
204+ ) }
205+ </ RestOfFieldsContainer >
97206 </ Container >
98207 ) ;
99208} ;
0 commit comments