1
+ /* eslint-disable jsx-a11y/no-static-element-interactions */
2
+ /* eslint-disable jsx-a11y/click-events-have-key-events */
1
3
import Link from 'next/link'
2
4
import Image from 'next/image'
3
- import classNames from 'classnames'
4
5
import { useRouter } from 'next/router'
5
6
import { MenuIcon , UserIcon , DiscordIcon } from 'src/components/Icons/icons'
6
7
import { useCallback , useContext , useEffect , useState } from 'react'
7
8
8
- import styles from './Header.module.scss'
9
9
import { ThemeButton } from '../ThemeButton'
10
- import { AuthContext , ModalContext } from 'src/contexts'
10
+ import { AuthContext , ModalContext , WindowSizeContext } from 'src/contexts'
11
11
12
12
export const Header : React . FC = ( ) => {
13
13
const [ showMenu , setShowMenu ] = useState ( false )
14
+ const { isMobile } = useContext ( WindowSizeContext )
14
15
15
16
const { user, connectLichess, logout } = useContext ( AuthContext )
16
17
@@ -49,123 +50,127 @@ export const Header: React.FC = () => {
49
50
} , [ router ] )
50
51
51
52
const userInfo = user ?. lichessId ? (
52
- < div className = { styles . auth } >
53
- < div className = { styles . user } >
54
- { UserIcon }
55
- < div className = { styles . content } >
56
- { user ?. displayName }
57
- < p > View Info</ p >
58
- </ div >
53
+ < div className = "group relative flex w-full items-center gap-3 rounded bg-background-1 px-3 py-2 md:w-auto" >
54
+ < i className = "h-6 w-6" > { UserIcon } </ i >
55
+ < div className = "flex flex-col" >
56
+ < p className = "text-sm" > { user ?. displayName } </ p >
57
+ < p className = "text-xs text-secondary" > View Info</ p >
59
58
</ div >
60
- < div className = { styles . dropdown } >
59
+ < div className = "absolute bottom-[100%] left-0 z-10 hidden w-full overflow-hidden rounded bg-background-2 group-hover:flex group-hover:flex-col md:bottom-auto md:top-[100%]" >
61
60
< Link
62
61
href = "/profile"
63
- className = {
64
- router . pathname . startsWith ( '/profile' ) ? styles . selected : ''
65
- }
62
+ className = "flex w-full items-center justify-start px-3 py-2 hover:bg-background-3"
66
63
>
67
64
Profile
68
65
</ Link >
69
- < button onClick = { logout } > Logout</ button >
66
+ < button
67
+ onClick = { logout }
68
+ className = "flex w-full items-center justify-start px-3 py-2 hover:bg-background-3"
69
+ >
70
+ Logout
71
+ </ button >
70
72
</ div >
71
73
</ div >
72
74
) : (
73
- < div className = { styles . auth } >
74
- < button onClick = { connectLichess } > Sign in</ button >
75
- </ div >
75
+ < button onClick = { connectLichess } > Sign in</ button >
76
76
)
77
77
78
- const headerContent = (
79
- < >
80
- < Link href = "/" passHref >
81
- < div className = "flex flex-row items-center gap-2" >
82
- < Image src = "/maia.png" width = { 40 } height = { 40 } alt = "Maia Logo" />
83
- < h2 className = "text-2xl font-bold" > Maia Chess</ h2 >
84
- </ div >
85
- </ Link >
86
- < div className = { styles . links } >
87
- { user ?. lichessId ? (
88
- < div
89
- className = {
90
- router . pathname . startsWith ( '/play' ) ? styles . selected : ''
91
- }
92
- >
93
- < button > Play</ button >
94
- < div className = { styles . dropdownContent } >
95
- < button onClick = { ( ) => startGame ( 'againstMaia' ) } >
96
- Play Maia
97
- </ button >
98
- < a
99
- href = "https://lichess.org/@/maia1"
100
- target = "_blank"
101
- rel = "noreferrer"
102
- >
103
- Play Maia on Lichess
104
- </ a >
105
- < button onClick = { ( ) => startGame ( 'handAndBrain' ) } >
106
- Play Hand and Brain
107
- </ button >
108
- </ div >
78
+ const desktopLayout = (
79
+ < div className = "flex w-[90%] flex-row items-center justify-between" >
80
+ < div className = "flex flex-row items-center justify-start gap-6" >
81
+ < Link href = "/" passHref >
82
+ < div className = "flex flex-row items-center gap-2" >
83
+ < Image src = "/maia.png" width = { 40 } height = { 40 } alt = "Maia Logo" />
84
+ < h2 className = "text-2xl font-bold" > Maia Chess</ h2 >
109
85
</ div >
110
- ) : (
86
+ </ Link >
87
+ < div className = "hidden flex-row gap-1 *:px-2 *:py-1 md:flex" >
88
+ { user ?. lichessId ? (
89
+ < div
90
+ className = { `${ router . pathname . startsWith ( '/play' ) && 'bg-background-1' } group relative` }
91
+ >
92
+ < button > PLAY</ button >
93
+ < div className = "absolute left-0 top-[100%] z-30 hidden w-48 flex-col items-start bg-background-1 group-hover:flex" >
94
+ < button
95
+ onClick = { ( ) => startGame ( 'againstMaia' ) }
96
+ className = "flex w-full items-center justify-start px-3 py-2 hover:bg-background-2"
97
+ >
98
+ Play Maia
99
+ </ button >
100
+ < a
101
+ className = "flex w-full items-center justify-start px-3 py-2 hover:bg-background-2"
102
+ href = "https://lichess.org/@/maia1"
103
+ target = "_blank"
104
+ rel = "noreferrer"
105
+ >
106
+ Play Maia on Lichess
107
+ </ a >
108
+ < button
109
+ onClick = { ( ) => startGame ( 'handAndBrain' ) }
110
+ className = "flex w-full items-center justify-start px-3 py-2 hover:bg-background-2"
111
+ >
112
+ Play Hand and Brain
113
+ </ button >
114
+ </ div >
115
+ </ div >
116
+ ) : (
117
+ < a
118
+ target = "_blank"
119
+ rel = "noreferrer"
120
+ href = "https://lichess.org/@/maia1"
121
+ >
122
+ Play
123
+ </ a >
124
+ ) }
125
+ < Link
126
+ href = "/analysis"
127
+ className = { `${ router . pathname . startsWith ( '/analysis' ) && 'bg-background-1' } uppercase hover:bg-background-1` }
128
+ >
129
+ Analysis
130
+ </ Link >
131
+ < Link
132
+ href = "/train"
133
+ className = { `${ router . pathname . startsWith ( '/train' ) && 'bg-background-1' } uppercase hover:bg-background-1` }
134
+ >
135
+ Train
136
+ </ Link >
137
+ < Link
138
+ href = "/turing"
139
+ className = { `${ router . pathname . startsWith ( '/turing' ) && 'bg-background-1' } uppercase hover:bg-background-1` }
140
+ >
141
+ Bot-or-not
142
+ </ Link >
143
+ < Link
144
+ href = "/leaderboard"
145
+ className = { `${ router . pathname . startsWith ( '/leaderboard' ) && 'bg-background-1' } uppercase hover:bg-background-1` }
146
+ >
147
+ Leaderboard
148
+ </ Link >
149
+ < Link
150
+ href = "/blog"
151
+ className = { `${ router . pathname . startsWith ( '/blog' ) && 'bg-background-1' } uppercase hover:bg-background-1` }
152
+ >
153
+ Blog
154
+ </ Link >
111
155
< a
112
156
target = "_blank"
113
157
rel = "noreferrer"
114
- href = "https://lichess.org/@/maia1"
158
+ href = "https://twitch.tv/maiachess"
159
+ className = "uppercase hover:bg-background-1"
115
160
>
116
- Play
161
+ WATCH
117
162
</ a >
118
- ) }
119
- < Link
120
- href = "/analysis"
121
- className = {
122
- router . pathname . startsWith ( '/analysis' ) ? styles . selected : ''
123
- }
124
- >
125
- Analysis
126
- </ Link >
127
- < Link
128
- href = "/train"
129
- className = {
130
- router . pathname . startsWith ( '/train' ) ? styles . selected : ''
131
- }
132
- >
133
- Train
134
- </ Link >
135
- < Link
136
- href = "/turing"
137
- className = {
138
- router . pathname . startsWith ( '/turing' ) ? styles . selected : ''
139
- }
140
- >
141
- Bot-or-not
142
- </ Link >
143
- < Link
144
- href = "/leaderboard"
145
- className = {
146
- router . pathname . startsWith ( '/leaderboard' ) ? styles . selected : ''
147
- }
148
- >
149
- Leaderboard
150
- </ Link >
151
- < Link
152
- href = "/blog"
153
- className = { router . pathname . startsWith ( '/blog' ) ? styles . selected : '' }
154
- >
155
- Blog
156
- </ Link >
157
- < a target = "_blank" rel = "noreferrer" href = "https://twitch.tv/maiachess" >
158
- WATCH
159
- </ a >
160
- < a
161
- target = "_blank"
162
- rel = "noreferrer"
163
- href = "https://forms.gle/XYeoTJF4YgUu4Vq28"
164
- >
165
- FEEDBACK
166
- </ a >
163
+ < a
164
+ target = "_blank"
165
+ rel = "noreferrer"
166
+ href = "https://forms.gle/XYeoTJF4YgUu4Vq28"
167
+ className = "uppercase hover:bg-background-1"
168
+ >
169
+ FEEDBACK
170
+ </ a >
171
+ </ div >
167
172
</ div >
168
- < div className = { styles . linksRight } >
173
+ < div className = "hidden flex-row items-center gap-3 md:flex" >
169
174
< ThemeButton />
170
175
< a
171
176
target = "_blank"
@@ -176,27 +181,120 @@ export const Header: React.FC = () => {
176
181
</ a >
177
182
{ userInfo }
178
183
</ div >
184
+ </ div >
185
+ )
186
+
187
+ const mobileLayout = (
188
+ < div className = "flex w-full flex-row justify-between px-4" >
189
+ < Link href = "/" passHref >
190
+ < div className = "flex flex-row items-center gap-2" >
191
+ < Image src = "/maia.png" width = { 40 } height = { 40 } alt = "Maia Logo" />
192
+ < h2 className = "text-2xl font-bold" > Maia Chess</ h2 >
193
+ </ div >
194
+ </ Link >
179
195
< button
180
- className = { styles . button }
196
+ className = "block cursor-pointer *:*:fill-primary md:hidden"
181
197
onClick = { ( ) => setShowMenu ( ( show ) => ! show ) }
182
198
>
183
199
{ MenuIcon }
184
200
</ button >
185
- </ >
201
+ { showMenu && (
202
+ < div className = "fixed left-0 top-0 z-50 flex h-screen w-screen flex-col items-start justify-between bg-backdrop py-4" >
203
+ < div className = "flex w-full flex-row justify-between px-4" >
204
+ < Link href = "/" passHref >
205
+ < div className = "flex flex-row items-center gap-2" >
206
+ < Image src = "/maia.png" width = { 40 } height = { 40 } alt = "Maia Logo" />
207
+ < h2 className = "text-2xl font-bold" > Maia Chess</ h2 >
208
+ </ div >
209
+ </ Link >
210
+ < button
211
+ className = "block cursor-pointer *:*:fill-primary md:hidden"
212
+ onClick = { ( ) => setShowMenu ( false ) }
213
+ >
214
+ { MenuIcon }
215
+ </ button >
216
+ </ div >
217
+ < div className = "flex flex-col gap-6 px-12" >
218
+ { user ?. lichessId ? (
219
+ < div className = "flex flex-col items-start justify-center gap-6" >
220
+ < button > PLAY</ button >
221
+ < div className = "flex flex-col items-start justify-center gap-4" >
222
+ < button onClick = { ( ) => startGame ( 'againstMaia' ) } >
223
+ Play Maia
224
+ </ button >
225
+ < a
226
+ href = "https://lichess.org/@/maia1"
227
+ target = "_blank"
228
+ rel = "noreferrer"
229
+ >
230
+ Play Maia on Lichess
231
+ </ a >
232
+ < button onClick = { ( ) => startGame ( 'handAndBrain' ) } >
233
+ Play Hand and Brain
234
+ </ button >
235
+ </ div >
236
+ </ div >
237
+ ) : (
238
+ < a
239
+ target = "_blank"
240
+ rel = "noreferrer"
241
+ href = "https://lichess.org/@/maia1"
242
+ >
243
+ Play
244
+ </ a >
245
+ ) }
246
+ < Link href = "/analysis" className = "uppercase" >
247
+ Analysis
248
+ </ Link >
249
+ < Link href = "/train" className = "uppercase" >
250
+ Train
251
+ </ Link >
252
+ < Link href = "/turing" className = "uppercase" >
253
+ Bot-or-not
254
+ </ Link >
255
+ < Link href = "/leaderboard" className = "uppercase" >
256
+ Leaderboard
257
+ </ Link >
258
+ < Link href = "/blog" className = "uppercase" >
259
+ Blog
260
+ </ Link >
261
+ < a
262
+ target = "_blank"
263
+ rel = "noreferrer"
264
+ href = "https://twitch.tv/maiachess"
265
+ className = "uppercase"
266
+ >
267
+ Watch
268
+ </ a >
269
+ < a
270
+ target = "_blank"
271
+ rel = "noreferrer"
272
+ href = "https://forms.gle/XYeoTJF4YgUu4Vq28"
273
+ className = "uppercase"
274
+ >
275
+ Feedback
276
+ </ a >
277
+ </ div >
278
+ < div className = "flex w-full flex-row items-center gap-3 px-4" >
279
+ < ThemeButton />
280
+ < a
281
+ target = "_blank"
282
+ rel = "noreferrer"
283
+ href = "https://discord.gg/Az93GqEAs7"
284
+ >
285
+ < div className = "h-6 w-6" > { DiscordIcon } </ div >
286
+ </ a >
287
+ { userInfo }
288
+ </ div >
289
+ </ div >
290
+ ) }
291
+ </ div >
186
292
)
187
293
188
294
return (
189
295
< >
190
- < div className = { styles . header } > { headerContent } </ div >
191
- { /* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */ }
192
- < div
193
- className = { classNames ( styles . menu , { [ styles . active ] : showMenu } ) }
194
- onClick = { ( ) => setShowMenu ( false ) }
195
- >
196
- { /* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */ }
197
- < div className = { styles . mobile } onClick = { ( e ) => e . stopPropagation ( ) } >
198
- { headerContent }
199
- </ div >
296
+ < div className = "flex w-screen flex-row items-center justify-center pt-4" >
297
+ { isMobile ? mobileLayout : desktopLayout }
200
298
</ div >
201
299
</ >
202
300
)
0 commit comments