1
1
import React , { useState , useEffect , useContext , useRef } from 'react'
2
+ import { useRouter } from 'next/router'
2
3
import { AppContext } from '../utils/AppContext'
3
4
import { IconSetContext } from '../utils/IconSetContext'
4
5
import Button from './Button'
@@ -17,6 +18,7 @@ const HowToPanel: React.FC<HowToPanelProps> = ({
17
18
const ref = useRef < HTMLDivElement > ( null )
18
19
const [ iconEditor , setIconEditor ] = useState ( false )
19
20
const [ iconType , setIconType ] = useState ( 'static' )
21
+ const router = useRouter ( )
20
22
21
23
const iconEditorToggle = ( type : 'animated' | 'static' ) => {
22
24
setIconType ( type )
@@ -44,13 +46,9 @@ const HowToPanel: React.FC<HowToPanelProps> = ({
44
46
}
45
47
46
48
useOnClickOrEsc ( ref , ( ) => close ( ) )
47
- let queryString
48
- if ( typeof window !== 'undefined' ) {
49
- queryString = window . location . search
50
- }
51
- const urlParams : URLSearchParams = new URLSearchParams ( queryString )
52
- const urlIconName : string | null = urlParams . get ( 'iconName' )
53
- const urlTagName : string | null = urlParams . get ( 'tagName' )
49
+
50
+ const urlTagName = router . query . tagName as string
51
+ const urlIconName = router . query . iconName as string
54
52
55
53
let setSearchWithUrlParam : string | null =
56
54
urlIconName && ! iconName ? urlIconName : ''
@@ -59,15 +57,14 @@ const HowToPanel: React.FC<HowToPanelProps> = ({
59
57
setSearchWithUrlParam = urlTagName
60
58
}
61
59
62
- const selectTag = ( urlTagName : string , callback : void ) => {
60
+ const selectTag = ( urlTagName : string ) => {
63
61
if ( typeof window !== 'undefined' ) {
64
62
window . history . replaceState (
65
63
'' ,
66
64
'EOS Icons' ,
67
65
`${ window . location . pathname } ?tagName=${ urlTagName } `
68
66
)
69
67
}
70
- return callback
71
68
}
72
69
const setTagInSearch = ( ) => {
73
70
return dispatch ( {
@@ -168,13 +165,11 @@ const HowToPanel: React.FC<HowToPanelProps> = ({
168
165
className = 'badge'
169
166
onClick = { ( ) => {
170
167
iconDispatch ( { type : 'SET_SEARCH_VALUE' , payload : tag } )
171
- selectTag (
172
- tag ,
173
- dispatch ( {
174
- type : 'TOGGLE_ICON_TAGS' ,
175
- selection : tag
176
- } )
177
- )
168
+ selectTag ( tag )
169
+ dispatch ( {
170
+ type : 'TOGGLE_ICON_TAGS' ,
171
+ selection : tag
172
+ } )
178
173
} }
179
174
style = { { cursor : 'pointer' } }
180
175
>
@@ -187,7 +182,7 @@ const HowToPanel: React.FC<HowToPanelProps> = ({
187
182
{ iconEditor ? (
188
183
< IconEditor
189
184
isActive = { iconEditor }
190
- show = { iconEditorToggle as ( ) => void }
185
+ show = { iconEditorToggle }
191
186
iconNames = { [ iconName ] }
192
187
iconType = { iconType }
193
188
theme = { state . iconsTheme }
0 commit comments