forked from Uniswap/interface
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDarkModeQueryParamReader.tsx
More file actions
32 lines (25 loc) · 920 Bytes
/
Copy pathDarkModeQueryParamReader.tsx
File metadata and controls
32 lines (25 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { useEffect } from 'react'
import { useDispatch } from 'react-redux'
import { RouteComponentProps } from 'react-router-dom'
import { parse } from 'qs'
import { AppDispatch } from '../state'
import { updateUserDarkMode } from '../state/user/actions'
export default function DarkModeQueryParamReader({ location: { search } }: RouteComponentProps): null {
const dispatch = useDispatch<AppDispatch>()
useEffect(() => {
if (!search) return
if (search.length < 2) return
const parsed = parse(search, {
parseArrays: false,
ignoreQueryPrefix: true
})
const theme = parsed.theme
if (typeof theme !== 'string') return
if (theme.toLowerCase() === 'light') {
dispatch(updateUserDarkMode({ userDarkMode: false }))
} else if (theme.toLowerCase() === 'dark') {
dispatch(updateUserDarkMode({ userDarkMode: true }))
}
}, [dispatch, search])
return null
}