11import React , { useState , useMemo } from "react" ;
22import styled , { css } from "styled-components" ;
33
4- import { useNavigate } from "react-router-dom" ;
4+ import { useNavigate , useParams } from "react-router-dom" ;
55
66import { Card , DropdownCascader , Searchbar } from "@kleros/ui-components-library" ;
77
@@ -12,9 +12,10 @@ import { useCourtTree, rootCourtToItems } from "queries/useCourtTree";
1212
1313import { responsiveSize } from "styles/responsiveSize" ;
1414import { landscapeStyle } from "styles/landscapeStyle" ;
15+ import { hoverShortTransitionTiming } from "styles/commonStyles" ;
1516
1617import { StyledSkeleton } from "components/StyledSkeleton" ;
17- import StakeMaintenanceButtons from "./StakeMaintenanceButton" ;
18+ import StakeMaintenanceButtons from ".. /StakeMaintenanceButton" ;
1819
1920const Container = styled . div `
2021 width: 100%;
@@ -57,6 +58,7 @@ const SearchResultsContainer = styled.div`
5758 position: absolute;
5859 margin-top: 45px;
5960 max-height: 400px;
61+ border: 1px solid ${ ( { theme } ) => theme . stroke } ;
6062 width: 100%;
6163 flex-direction: column;
6264 border-radius: 4px;
@@ -65,29 +67,54 @@ const SearchResultsContainer = styled.div`
6567 background-color: ${ ( { theme } ) => theme . whiteBackground } ;
6668` ;
6769
68- const StyledCard = styled ( Card ) `
70+ const StyledCard = styled ( Card ) < { selected : boolean } > `
71+ ${ hoverShortTransitionTiming }
6972 height: auto;
7073 width: 100%;
71- padding: 16px;
72- color: ${ ( { theme } ) => theme . primaryText } ;
74+ padding: ${ ( { selected } ) => ( selected ? "16px 13px" : "16px" ) } ;
7375 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+ }
7483` ;
7584
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 ] ;
78100}
79101
80102const TopSearch : React . FC = ( ) => {
81103 const { data } = useCourtTree ( ) ;
82104 const navigate = useNavigate ( ) ;
105+ const { id : currentCourtId } = useParams ( ) ;
83106 const items = useMemo ( ( ) => ! isUndefined ( data ) && [ rootCourtToItems ( data . court ) ] , [ data ] ) ;
84107 const isUniversity = isKlerosUniversity ( ) ;
85108 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 ] ) ;
91118
92119 return (
93120 < Container >
@@ -110,14 +137,15 @@ const TopSearch: React.FC = () => {
110137 < SearchResultsContainer >
111138 { filteredCourts . map ( ( court ) => (
112139 < StyledCard
113- hover
114140 key = { court . id }
141+ selected = { court . id === currentCourtId }
115142 onClick = { ( ) => {
116143 navigate ( `/courts/${ court . id } ` ) ;
117144 setSearch ( "" ) ;
118145 } }
119146 >
120- { court . name }
147+ { court . parentName && < CourtParentSpan > { court . parentName } / </ CourtParentSpan > }
148+ < CourtNameSpan > { court . name } </ CourtNameSpan >
121149 </ StyledCard >
122150 ) ) }
123151 </ SearchResultsContainer >
0 commit comments