toggle all settings category switch
This commit is contained in:
parent
0447fc5d61
commit
147b3c77bd
|
@ -14,7 +14,7 @@ import {
|
||||||
SOUND_SETTINGS_KEY,
|
SOUND_SETTINGS_KEY,
|
||||||
} from 'utils/constants'
|
} from 'utils/constants'
|
||||||
import Switch from '@components/forms/Switch'
|
import Switch from '@components/forms/Switch'
|
||||||
import { useCallback, useMemo, useReducer } from 'react'
|
import { useCallback, useMemo } from 'react'
|
||||||
import { CheckCircleIcon } from '@heroicons/react/20/solid'
|
import { CheckCircleIcon } from '@heroicons/react/20/solid'
|
||||||
import Image from 'next/legacy/image'
|
import Image from 'next/legacy/image'
|
||||||
|
|
||||||
|
@ -62,24 +62,15 @@ const NOTIFICATION_POSITIONS = [
|
||||||
'top-right',
|
'top-right',
|
||||||
]
|
]
|
||||||
|
|
||||||
interface ReducerItems {
|
|
||||||
[key: string]: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export const INITIAL_ANIMATION_SETTINGS = {
|
export const INITIAL_ANIMATION_SETTINGS = {
|
||||||
'orderbook-flash': true,
|
'orderbook-flash': false,
|
||||||
'swap-success': true,
|
'swap-success': false,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const INITIAL_SOUND_SETTINGS = {
|
export const INITIAL_SOUND_SETTINGS = {
|
||||||
'swap-success': true,
|
'swap-success': false,
|
||||||
'transaction-success': true,
|
'transaction-success': false,
|
||||||
'transaction-fail': true,
|
'transaction-fail': false,
|
||||||
}
|
|
||||||
|
|
||||||
const settingsReducer = (state: ReducerItems, name: string) => {
|
|
||||||
const updatedState = { ...state, [name]: !state[name] }
|
|
||||||
return updatedState
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Settings: NextPage = () => {
|
const Settings: NextPage = () => {
|
||||||
|
@ -103,34 +94,43 @@ const Settings: NextPage = () => {
|
||||||
const themes = useMemo(() => {
|
const themes = useMemo(() => {
|
||||||
return [t('settings:light'), t('settings:mango'), t('settings:dark')]
|
return [t('settings:light'), t('settings:mango'), t('settings:dark')]
|
||||||
}, [t])
|
}, [t])
|
||||||
const [, soundsDispatch] = useReducer(settingsReducer, INITIAL_SOUND_SETTINGS)
|
|
||||||
const [soundSettings, setSoundSettings] = useLocalStorageState(
|
const [soundSettings, setSoundSettings] = useLocalStorageState(
|
||||||
SOUND_SETTINGS_KEY,
|
SOUND_SETTINGS_KEY,
|
||||||
INITIAL_SOUND_SETTINGS
|
INITIAL_SOUND_SETTINGS
|
||||||
)
|
)
|
||||||
const [, animationsDispatch] = useReducer(
|
|
||||||
settingsReducer,
|
|
||||||
INITIAL_ANIMATION_SETTINGS
|
|
||||||
)
|
|
||||||
const [animationSettings, setAnimationSettings] = useLocalStorageState(
|
const [animationSettings, setAnimationSettings] = useLocalStorageState(
|
||||||
ANIMATION_SETTINGS_KEY,
|
ANIMATION_SETTINGS_KEY,
|
||||||
INITIAL_ANIMATION_SETTINGS
|
INITIAL_ANIMATION_SETTINGS
|
||||||
)
|
)
|
||||||
|
|
||||||
const handleToggleAnimationSetting = (settingName: string) => {
|
const handleToggleAnimationSetting = (settingName: string) => {
|
||||||
animationsDispatch(settingName)
|
if (settingName === 'all') {
|
||||||
setAnimationSettings({
|
const toggle = !Object.values(animationSettings).includes(false)
|
||||||
...animationSettings,
|
Object.keys(animationSettings).forEach((key) => {
|
||||||
[settingName]: !animationSettings[settingName],
|
animationSettings[key] = !toggle
|
||||||
})
|
})
|
||||||
|
setAnimationSettings(animationSettings)
|
||||||
|
} else {
|
||||||
|
setAnimationSettings({
|
||||||
|
...animationSettings,
|
||||||
|
[settingName]: !animationSettings[settingName],
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleToggleSoundSetting = (settingName: string) => {
|
const handleToggleSoundSetting = (settingName: string) => {
|
||||||
soundsDispatch(settingName)
|
if (settingName === 'all') {
|
||||||
setSoundSettings({
|
const toggle = !Object.values(soundSettings).includes(false)
|
||||||
...soundSettings,
|
Object.keys(soundSettings).forEach((key) => {
|
||||||
[settingName]: !soundSettings[settingName],
|
soundSettings[key] = !toggle
|
||||||
})
|
})
|
||||||
|
setSoundSettings(soundSettings)
|
||||||
|
} else {
|
||||||
|
setSoundSettings({
|
||||||
|
...soundSettings,
|
||||||
|
[settingName]: !soundSettings[settingName],
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleLangChange = useCallback(
|
const handleLangChange = useCallback(
|
||||||
|
@ -201,7 +201,13 @@ const Settings: NextPage = () => {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="col-span-12 border-b border-th-bkg-3 pt-8 lg:col-span-8 lg:col-start-3">
|
<div className="col-span-12 border-b border-th-bkg-3 pt-8 lg:col-span-8 lg:col-start-3">
|
||||||
<h2 className="mb-4 text-base">{t('settings:animations')}</h2>
|
<div className="mb-4 flex items-center justify-between pr-4">
|
||||||
|
<h2 className="text-base">{t('settings:animations')}</h2>
|
||||||
|
<Switch
|
||||||
|
checked={!Object.values(animationSettings).includes(false)}
|
||||||
|
onChange={() => handleToggleAnimationSetting('all')}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<div className="flex items-center justify-between border-t border-th-bkg-3 py-4 md:px-4">
|
<div className="flex items-center justify-between border-t border-th-bkg-3 py-4 md:px-4">
|
||||||
<p className="mb-2 lg:mb-0">{t('settings:orderbook-flash')}</p>
|
<p className="mb-2 lg:mb-0">{t('settings:orderbook-flash')}</p>
|
||||||
<Switch
|
<Switch
|
||||||
|
@ -218,7 +224,13 @@ const Settings: NextPage = () => {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="col-span-12 border-b border-th-bkg-3 pt-8 lg:col-span-8 lg:col-start-3">
|
<div className="col-span-12 border-b border-th-bkg-3 pt-8 lg:col-span-8 lg:col-start-3">
|
||||||
<h2 className="mb-4 text-base">{t('settings:sounds')}</h2>
|
<div className="mb-4 flex items-center justify-between pr-4">
|
||||||
|
<h2 className="text-base">{t('settings:sounds')}</h2>
|
||||||
|
<Switch
|
||||||
|
checked={!Object.values(soundSettings).includes(false)}
|
||||||
|
onChange={() => handleToggleSoundSetting('all')}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<div className="flex items-center justify-between border-t border-th-bkg-3 py-4 md:px-4">
|
<div className="flex items-center justify-between border-t border-th-bkg-3 py-4 md:px-4">
|
||||||
<p className="mb-2 lg:mb-0">{t('settings:transaction-success')}</p>
|
<p className="mb-2 lg:mb-0">{t('settings:transaction-success')}</p>
|
||||||
<Switch
|
<Switch
|
||||||
|
|
Loading…
Reference in New Issue