@@ -16,6 +16,8 @@ import {
16
16
useEventListener ,
17
17
} from "@chakra-ui/react"
18
18
19
+ import { LocaleDisplayInfo } from "@/lib/types"
20
+
19
21
import { Button } from "@/components/Buttons"
20
22
import { BaseLink } from "@/components/Link"
21
23
@@ -61,22 +63,38 @@ const LanguagePicker = ({
61
63
inputRef . current ?. focus ( )
62
64
} )
63
65
64
- const MobileCloseBar = ( ) => {
65
- return (
66
- < Flex
67
- justifyContent = "end"
68
- hideFrom = "md"
69
- position = "sticky"
70
- zIndex = "sticky"
71
- top = "0"
72
- bg = "background.base"
66
+ // onClick handlers
67
+ const handleMobileCloseBarClick = ( ) => onClose ( )
68
+ const handleMenuItemClose = ( displayInfo : LocaleDisplayInfo ) =>
69
+ onClose ( {
70
+ eventAction : "Locale chosen" ,
71
+ eventName : displayInfo . localeOption ,
72
+ } )
73
+ const handleBaseLinkClose = ( ) =>
74
+ onClose ( {
75
+ eventAction : "Translation program link (menu footer)" ,
76
+ eventName : "/contributing/translation-program" ,
77
+ } )
78
+
79
+ const MobileCloseBar = ( ) => (
80
+ < Flex
81
+ justifyContent = "end"
82
+ hideFrom = "md"
83
+ position = "sticky"
84
+ zIndex = "sticky"
85
+ top = "0"
86
+ bg = "background.base"
87
+ >
88
+ < Button
89
+ p = "4"
90
+ variant = "ghost"
91
+ alignSelf = "end"
92
+ onClick = { handleMobileCloseBarClick }
73
93
>
74
- < Button p = "4" variant = "ghost" alignSelf = "end" onClick = { ( ) => onClose ( ) } >
75
- { t ( "common:close" ) }
76
- </ Button >
77
- </ Flex >
78
- )
79
- }
94
+ { t ( "common:close" ) }
95
+ </ Button >
96
+ </ Flex >
97
+ )
80
98
81
99
return (
82
100
< Menu isLazy placement = { placement } autoSelect = { false } { ...disclosure } >
@@ -178,12 +196,7 @@ const LanguagePicker = ({
178
196
e . preventDefault ( )
179
197
inputRef . current ?. focus ( )
180
198
} }
181
- onClick = { ( ) =>
182
- onClose ( {
183
- eventAction : "Locale chosen" ,
184
- eventName : displayInfo . localeOption ,
185
- } )
186
- }
199
+ onClick = { ( ) => handleMenuItemClose ( displayInfo ) }
187
200
/>
188
201
) ) }
189
202
@@ -216,12 +229,7 @@ const LanguagePicker = ({
216
229
< BaseLink
217
230
ref = { footerRef }
218
231
href = "/contributing/translation-program"
219
- onClick = { ( ) =>
220
- onClose ( {
221
- eventAction : "Translation program link (menu footer)" ,
222
- eventName : "/contributing/translation-program" ,
223
- } )
224
- }
232
+ onClick = { handleBaseLinkClose }
225
233
>
226
234
{ t ( "common:learn-more" ) }
227
235
</ BaseLink >
0 commit comments