1
- import React from "react" ;
1
+ import React , { useState } from "react" ;
2
+ import { GoPin } from "react-icons/go" ;
2
3
import {
3
4
NavLink as RouterLink ,
4
5
useLocation ,
@@ -7,11 +8,13 @@ import {
7
8
import {
8
9
Button ,
9
10
ButtonGroup ,
11
+ Col ,
10
12
Form ,
11
13
Input ,
12
14
Nav ,
13
15
Navbar ,
14
- Collapse ,
16
+ NavItem ,
17
+ Row ,
15
18
} from "reactstrap" ;
16
19
import { useLoginState } from "../api/InternalAPIClient" ;
17
20
import { extractRivalsParam , normalizeUserId } from "../utils" ;
@@ -43,10 +46,6 @@ const extractUserIds = (
43
46
return { userId, rivalIdString } ;
44
47
} ;
45
48
46
- interface Props {
47
- isOpen : boolean ;
48
- }
49
-
50
49
const generatePath = (
51
50
kind : PageKind ,
52
51
userId : string ,
@@ -56,7 +55,7 @@ const generatePath = (
56
55
return "/" + kind + "/" + users . join ( "/" ) ;
57
56
} ;
58
57
59
- export const UserSearchBar = ( props : Props ) => {
58
+ export const UserSearchBar = ( ) => {
60
59
const { pathname } = useLocation ( ) ;
61
60
const loginState = useLoginState ( ) . data ;
62
61
const pageKind = extractPageKind ( pathname ) ;
@@ -67,6 +66,8 @@ export const UserSearchBar = (props: Props) => {
67
66
68
67
const loggedInUserId = UserState . loggedInUserId ( loginState ) ?? "" ;
69
68
69
+ const [ userSearchBarIsFixed , setUserSearchBarIsFixed ] = useState ( false ) ;
70
+
70
71
const [ userId , setUserId ] = React . useState ( pathUserId ?? "" ) ;
71
72
const [ rivalIdString , setRivalIdString ] = React . useState (
72
73
pathRivalIdString ?? ""
@@ -105,11 +106,11 @@ export const UserSearchBar = (props: Props) => {
105
106
color = "light"
106
107
light
107
108
expand = "md"
108
- className = " border-bottom"
109
+ className = { ` ${ userSearchBarIsFixed ? "sticky-top" : "" } border-bottom` }
109
110
style = { { padding : 0 } }
110
111
>
111
- < Collapse isOpen = { props . isOpen } navbar >
112
- < Nav navbar style = { { padding : "0.5rem 1rem" } } >
112
+ < Nav navbar style = { { padding : "0.5rem 1rem" , width : "100%" } } >
113
+ < NavItem >
113
114
< Form inline >
114
115
< Input
115
116
className = "mt-2 mr-2 mt-lg-0 mt-md-0"
@@ -126,7 +127,6 @@ export const UserSearchBar = (props: Props) => {
126
127
placeholder = { loggedInUserId ? loggedInUserId : "User ID" }
127
128
onChange = { ( e ) : void => setUserId ( e . target . value ) }
128
129
/>
129
-
130
130
< Input
131
131
className = "mt-2 mr-2 mt-lg-0 mt-md-0"
132
132
style = { { width : 160 } }
@@ -142,28 +142,42 @@ export const UserSearchBar = (props: Props) => {
142
142
placeholder = "Rival ID, ..."
143
143
onChange = { ( e ) : void => setRivalIdString ( e . target . value ) }
144
144
/>
145
-
146
- < ButtonGroup className = "mt-2 mb-0 mt-lg-0 mt-md-0" >
147
- < Button tag = { RouterLink } to = { tablePath } color = "light" >
148
- Table
149
- </ Button >
150
-
151
- < Button tag = { RouterLink } to = { listPath } color = "light" >
152
- List
153
- </ Button >
154
-
145
+ </ Form >
146
+ </ NavItem >
147
+ < NavItem style = { { flexGrow : 1 } } >
148
+ < Row className = "justify-content-between align-items-center" >
149
+ < Col className = "col-auto" >
150
+ < ButtonGroup className = "mt-2 mb-0 mt-lg-0 mt-md-0" >
151
+ < Button tag = { RouterLink } to = { tablePath } color = "light" >
152
+ Table
153
+ </ Button >
154
+
155
+ < Button tag = { RouterLink } to = { listPath } color = "light" >
156
+ List
157
+ </ Button >
158
+
159
+ < Button
160
+ disabled = { userId . length === 0 && loggedInUserId . length === 0 }
161
+ tag = { RouterLink }
162
+ to = { userPath }
163
+ color = "light"
164
+ >
165
+ User
166
+ </ Button >
167
+ </ ButtonGroup >
168
+ </ Col >
169
+ < Col className = "col-auto" >
155
170
< Button
156
- disabled = { userId . length === 0 && loggedInUserId . length === 0 }
157
- tag = { RouterLink }
158
- to = { userPath }
159
171
color = "light"
172
+ active = { userSearchBarIsFixed }
173
+ onClick = { ( ) => setUserSearchBarIsFixed ( ( e ) => ! e ) }
160
174
>
161
- User
175
+ < GoPin />
162
176
</ Button >
163
- </ ButtonGroup >
164
- </ Form >
165
- </ Nav >
166
- </ Collapse >
177
+ </ Col >
178
+ </ Row >
179
+ </ NavItem >
180
+ </ Nav >
167
181
</ Navbar >
168
182
) ;
169
183
} ;
0 commit comments