1
1
import React , { useState , useMemo } from "react" ;
2
2
import styled , { css } from "styled-components" ;
3
3
4
- import { useNavigate } from "react-router-dom" ;
4
+ import { useNavigate , useParams } from "react-router-dom" ;
5
5
6
6
import { Card , DropdownCascader , Searchbar } from "@kleros/ui-components-library" ;
7
7
@@ -12,9 +12,10 @@ import { useCourtTree, rootCourtToItems } from "queries/useCourtTree";
12
12
13
13
import { responsiveSize } from "styles/responsiveSize" ;
14
14
import { landscapeStyle } from "styles/landscapeStyle" ;
15
+ import { hoverShortTransitionTiming } from "styles/commonStyles" ;
15
16
16
17
import { StyledSkeleton } from "components/StyledSkeleton" ;
17
- import StakeMaintenanceButtons from "./StakeMaintenanceButton" ;
18
+ import StakeMaintenanceButtons from ".. /StakeMaintenanceButton" ;
18
19
19
20
const Container = styled . div `
20
21
width: 100%;
@@ -57,6 +58,7 @@ const SearchResultsContainer = styled.div`
57
58
position: absolute;
58
59
margin-top: 45px;
59
60
max-height: 400px;
61
+ border: 1px solid ${ ( { theme } ) => theme . stroke } ;
60
62
width: 100%;
61
63
flex-direction: column;
62
64
border-radius: 4px;
@@ -65,29 +67,54 @@ const SearchResultsContainer = styled.div`
65
67
background-color: ${ ( { theme } ) => theme . whiteBackground } ;
66
68
` ;
67
69
68
- const StyledCard = styled ( Card ) `
70
+ const StyledCard = styled ( Card ) < { selected : boolean } > `
71
+ ${ hoverShortTransitionTiming }
69
72
height: auto;
70
73
width: 100%;
71
- padding: 16px;
72
- color: ${ ( { theme } ) => theme . primaryText } ;
74
+ padding: ${ ( { selected } ) => ( selected ? "16px 13px" : "16px" ) } ;
73
75
cursor: pointer;
76
+ border: none;
77
+ border-left: ${ ( { selected, theme } ) => ( selected ? `3px solid ${ theme . primaryBlue } ` : "none" ) } ;
78
+ background-color: ${ ( { selected, theme } ) => ( selected ? theme . mediumBlue : "transparent" ) } ;
79
+
80
+ :hover {
81
+ background-color: ${ ( { theme } ) => theme . mediumBlue } ;
82
+ }
74
83
` ;
75
84
76
- function flattenCourts ( court ) {
77
- return court ? [ court , ...( court . children || [ ] ) . flatMap ( flattenCourts ) ] : [ ] ;
85
+ const CourtParentSpan = styled . span `
86
+ color: ${ ( { theme } ) => theme . secondaryText } EE;
87
+ ` ;
88
+
89
+ const CourtNameSpan = styled . span `
90
+ color: ${ ( { theme } ) => theme . primaryText } ;
91
+ ` ;
92
+
93
+ function flattenCourts ( court , parent = null ) {
94
+ const current = {
95
+ ...court ,
96
+ parentName : parent ?. name ?? null ,
97
+ } ;
98
+ const children = ( court . children || [ ] ) . flatMap ( ( child ) => flattenCourts ( child , current ) ) ;
99
+ return [ current , ...children ] ;
78
100
}
79
101
80
102
const TopSearch : React . FC = ( ) => {
81
103
const { data } = useCourtTree ( ) ;
82
104
const navigate = useNavigate ( ) ;
105
+ const { id : currentCourtId } = useParams ( ) ;
83
106
const items = useMemo ( ( ) => ! isUndefined ( data ) && [ rootCourtToItems ( data . court ) ] , [ data ] ) ;
84
107
const isUniversity = isKlerosUniversity ( ) ;
85
108
const [ search , setSearch ] = useState ( "" ) ;
86
- const filteredCourts = useMemo (
87
- ( ) =>
88
- data ?. court ? flattenCourts ( data . court ) . filter ( ( c ) => c . name . toLowerCase ( ) . includes ( search . toLowerCase ( ) ) ) : [ ] ,
89
- [ data , search ]
90
- ) ;
109
+
110
+ const filteredCourts = useMemo ( ( ) => {
111
+ if ( ! data ?. court ) return [ ] ;
112
+ const courts = flattenCourts ( data . court ) . filter ( ( c ) => c . name . toLowerCase ( ) . includes ( search . toLowerCase ( ) ) ) ;
113
+ const selectedCourt = courts . find ( ( c ) => c . id === currentCourtId ) ;
114
+ if ( ! selectedCourt ) return courts ;
115
+
116
+ return [ selectedCourt , ...courts . filter ( ( c ) => c . id !== currentCourtId ) ] ;
117
+ } , [ data , search , currentCourtId ] ) ;
91
118
92
119
return (
93
120
< Container >
@@ -110,14 +137,15 @@ const TopSearch: React.FC = () => {
110
137
< SearchResultsContainer >
111
138
{ filteredCourts . map ( ( court ) => (
112
139
< StyledCard
113
- hover
114
140
key = { court . id }
141
+ selected = { court . id === currentCourtId }
115
142
onClick = { ( ) => {
116
143
navigate ( `/courts/${ court . id } ` ) ;
117
144
setSearch ( "" ) ;
118
145
} }
119
146
>
120
- { court . name }
147
+ { court . parentName && < CourtParentSpan > { court . parentName } / </ CourtParentSpan > }
148
+ < CourtNameSpan > { court . name } </ CourtNameSpan >
121
149
</ StyledCard >
122
150
) ) }
123
151
</ SearchResultsContainer >
0 commit comments