Skip to content

Commit ccc2188

Browse files
removing redundant typecast to void functions
1 parent b853ab0 commit ccc2188

10 files changed

+153
-107
lines changed

.eslintrc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
"react/prop-types": "off"
1818
},
1919
"globals": {
20-
"JSX": "true"
20+
"JSX": true
2121
}
2222
}

components/CookiesBanner.tsx

+7-5
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ const CookiesBanner = () => {
88
const [cookiesBanner, setCookiesBanner] = useState<boolean>(false)
99

1010
/* Toggle customizable functionality */
11-
const cookiesHandler = (callback: void) => {
11+
const cookiesHandler = () => {
1212
setCookiesBanner(true)
13-
return callback
1413
}
1514

1615
useEffect(() => {
@@ -45,9 +44,12 @@ const CookiesBanner = () => {
4544
Edit preferences
4645
</Link>
4746
<Button
48-
onClick={() =>
49-
cookiesHandler(dispatch({ type: 'TOGGLE_CUSTOMIZE_COOKIES' }))
50-
}
47+
onClick={() => {
48+
cookiesHandler()
49+
dispatch({
50+
type: 'TOGGLE_CUSTOMIZE_COOKIES'
51+
})
52+
}}
5153
primary
5254
customClass='js-cookies-accept'
5355
>

components/CustomizeIconsPanel.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const CustomizeIconsPanel: React.FC<CustomizeIconsPanelProps> = (props) => {
2929
const { state, dispatch } = useContext(AppContext)
3030
const [iconEditor, setIconEditor] = useState(false)
3131

32-
const iconEditorToggle = (e: MouseEvent) => {
32+
const iconEditorToggle = (e: React.MouseEvent) => {
3333
e.preventDefault()
3434
if (state.multipleIcons.length > 0) setIconEditor(!iconEditor)
3535
else window.alert('Please select atleast one icon')
@@ -44,7 +44,7 @@ const CustomizeIconsPanel: React.FC<CustomizeIconsPanelProps> = (props) => {
4444
setModal(!modal)
4545
}
4646

47-
const generateFont = (e: MouseEvent) => {
47+
const generateFont = (e: React.MouseEvent) => {
4848
if (state.multipleIcons.length > 0) {
4949
e.preventDefault()
5050
modalToggle()
@@ -73,10 +73,10 @@ const CustomizeIconsPanel: React.FC<CustomizeIconsPanelProps> = (props) => {
7373
<div className='generate-div'>
7474
<span>{state.multipleIcons.length} icons selected</span>
7575
<span>Export as: </span>
76-
<Button type='submit' onClick={generateFont as () => void}>
76+
<Button type='submit' onClick={generateFont}>
7777
Font
7878
</Button>
79-
<Button type='button' onClick={iconEditorToggle as () => void}>
79+
<Button type='button' onClick={iconEditorToggle}>
8080
Images
8181
</Button>
8282
</div>
@@ -101,7 +101,7 @@ const CustomizeIconsPanel: React.FC<CustomizeIconsPanelProps> = (props) => {
101101
{iconEditor ? (
102102
<IconEditor
103103
isActive={iconEditor}
104-
show={iconEditorToggle as () => void}
104+
show={iconEditorToggle}
105105
iconNames={state.multipleIcons}
106106
/>
107107
) : (

components/HowToPanel.tsx

+12-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useState, useEffect, useContext, useRef } from 'react'
2+
import { useRouter } from 'next/router'
23
import { AppContext } from '../utils/AppContext'
34
import { IconSetContext } from '../utils/IconSetContext'
45
import Button from './Button'
@@ -17,6 +18,7 @@ const HowToPanel: React.FC<HowToPanelProps> = ({
1718
const ref = useRef<HTMLDivElement>(null)
1819
const [iconEditor, setIconEditor] = useState(false)
1920
const [iconType, setIconType] = useState('static')
21+
const router = useRouter()
2022

2123
const iconEditorToggle = (type: 'animated' | 'static') => {
2224
setIconType(type)
@@ -44,13 +46,9 @@ const HowToPanel: React.FC<HowToPanelProps> = ({
4446
}
4547

4648
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
5452

5553
let setSearchWithUrlParam: string | null =
5654
urlIconName && !iconName ? urlIconName : ''
@@ -59,15 +57,14 @@ const HowToPanel: React.FC<HowToPanelProps> = ({
5957
setSearchWithUrlParam = urlTagName
6058
}
6159

62-
const selectTag = (urlTagName: string, callback: void) => {
60+
const selectTag = (urlTagName: string) => {
6361
if (typeof window !== 'undefined') {
6462
window.history.replaceState(
6563
'',
6664
'EOS Icons',
6765
`${window.location.pathname}?tagName=${urlTagName}`
6866
)
6967
}
70-
return callback
7168
}
7269
const setTagInSearch = () => {
7370
return dispatch({
@@ -168,13 +165,11 @@ const HowToPanel: React.FC<HowToPanelProps> = ({
168165
className='badge'
169166
onClick={() => {
170167
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+
})
178173
}}
179174
style={{ cursor: 'pointer' }}
180175
>
@@ -187,7 +182,7 @@ const HowToPanel: React.FC<HowToPanelProps> = ({
187182
{iconEditor ? (
188183
<IconEditor
189184
isActive={iconEditor}
190-
show={iconEditorToggle as () => void}
185+
show={iconEditorToggle}
191186
iconNames={[iconName]}
192187
iconType={iconType}
193188
theme={state.iconsTheme}

components/IconEditor.tsx

+17-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import React, { useState, useEffect, useContext, useRef } from 'react'
1+
import React, {
2+
useState,
3+
useEffect,
4+
useContext,
5+
useRef,
6+
MouseEventHandler
7+
} from 'react'
28
import { SketchPicker } from 'react-color'
39
import Button from './Button'
410
import axios, { AxiosResponse } from 'axios'
@@ -63,12 +69,12 @@ const IconEditor: React.FC<IconEditorProps> = ({
6369
.value
6470
)
6571
}
66-
const flipIconHorizontal = (e: MouseEvent) => {
72+
const flipIconHorizontal = (e: React.MouseEvent) => {
6773
e.preventDefault()
6874
setHorizontalFlip(!horizontalFlip)
6975
}
7076

71-
const flipIconVertical = (e: MouseEvent) => {
77+
const flipIconVertical = (e: React.MouseEvent) => {
7278
e.preventDefault()
7379
setVerticalFlip(!verticalFlip)
7480
}
@@ -160,7 +166,7 @@ const IconEditor: React.FC<IconEditorProps> = ({
160166
}
161167
return window.open(downloadEndPoints, '_blank')
162168
}
163-
const generateCustomizedIcon = (e: MouseEvent) => {
169+
const generateCustomizedIcon = (e: React.MouseEvent) => {
164170
if (!generating) {
165171
e.preventDefault()
166172
setGenerate(true)
@@ -191,7 +197,10 @@ const IconEditor: React.FC<IconEditorProps> = ({
191197
className='icon-editor-card'
192198
ref={iconEditorRef as React.RefObject<HTMLDivElement>}
193199
>
194-
<div className='close' onClick={show as () => void} />
200+
<div
201+
className='close'
202+
onClick={show as MouseEventHandler<HTMLDivElement>}
203+
/>
195204
<h2>Customize Icon</h2>
196205
<div className='flex flex-row icon-editor-content'>
197206
<div>
@@ -292,10 +301,10 @@ const IconEditor: React.FC<IconEditorProps> = ({
292301
<div>
293302
<p>Flip</p>
294303
<div>
295-
<button onClick={flipIconHorizontal as () => void}>
304+
<button onClick={flipIconHorizontal}>
296305
<i className='eos-icons'>flip</i>
297306
</button>
298-
<button onClick={flipIconVertical as () => void}>
307+
<button onClick={flipIconVertical}>
299308
<i className='eos-icons rotate-flip-icon'>flip</i>
300309
</button>
301310
</div>
@@ -341,10 +350,7 @@ const IconEditor: React.FC<IconEditorProps> = ({
341350
''
342351
)}
343352
<div className='export-btn'>
344-
<Button
345-
type='button'
346-
onClick={generateCustomizedIcon as () => void}
347-
>
353+
<Button type='button' onClick={generateCustomizedIcon}>
348354
{!generating ? (
349355
<span>Export as {exportAs.toUpperCase()}</span>
350356
) : (

interface/index.ts

+5-11
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface AboutBlockProps {
1111

1212
export interface ButtonProps {
1313
children: React.ReactNode
14-
onClick: () => void
14+
onClick: ((e: React.MouseEvent) => void) | (() => void)
1515
primary?: boolean
1616
type?: 'button' | 'submit' | 'reset'
1717
customClass?: string
@@ -62,7 +62,10 @@ export interface IconProps {
6262

6363
export interface IconEditorProps {
6464
isActive: boolean
65-
show: () => void
65+
show:
66+
| ((type: 'animated' | 'static') => void)
67+
| ((e: React.MouseEvent) => void)
68+
| (() => void)
6669
iconNames: string[]
6770
iconType?: string
6871
theme?: string
@@ -98,15 +101,6 @@ export interface eosIconsStateType {
98101
cookiesToggle: boolean
99102
}
100103

101-
export interface eosIconsActionType {
102-
type: string
103-
selection: string
104-
search: string
105-
data: string[]
106-
category: string
107-
action: string
108-
}
109-
110104
export interface ModalProps {
111105
isActive: boolean
112106
show: () => void

tsconfig.tsbuildinfo

+1-1
Large diffs are not rendered by default.

types/index.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export type eosIconsActionType =
2+
| { type: string }
3+
| { type: string; selection: string }
4+
| { type: string; search: string }
5+
| { type: string; search: string }
6+
| { type: string; data: string[] }
7+
| { type: string; action: string }
8+
| { type: string; category: string }

utils/AppContext.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import React, { createContext, useReducer } from 'react'
22
import { iconsReducer, eosIconsState } from './EosIcons.store'
33
import { eosIconsStateType } from '../interface'
4+
import { eosIconsActionType } from '../types'
5+
import type { Dispatch } from 'react'
46

57
export const AppContext = createContext<{
68
state: eosIconsStateType
7-
dispatch: React.Dispatch<any>
9+
dispatch: Dispatch<eosIconsActionType>
810
}>({ state: eosIconsState, dispatch: () => null })
911

1012
interface AppWrapperProps {

0 commit comments

Comments
 (0)