2021-04-22 06:10:43 -07:00
|
|
|
import { useEffect, useState } from 'react'
|
2021-04-22 05:33:35 -07:00
|
|
|
import { RefreshIcon } from '@heroicons/react/outline'
|
|
|
|
import { defaultLayouts } from './TradePageGrid'
|
|
|
|
import useLocalStorageState from '../hooks/useLocalStorageState'
|
2021-04-22 07:45:36 -07:00
|
|
|
import Tooltip from './Tooltip'
|
2021-04-22 05:33:35 -07:00
|
|
|
|
|
|
|
const ResetLayout = ({ className = '' }) => {
|
2021-04-22 06:10:43 -07:00
|
|
|
const [spin, setSpin] = useState(false)
|
2021-04-22 05:33:35 -07:00
|
|
|
const [, setSavedLayouts] = useLocalStorageState(
|
|
|
|
'savedLayouts',
|
|
|
|
defaultLayouts
|
|
|
|
)
|
|
|
|
|
2021-04-22 06:10:43 -07:00
|
|
|
useEffect(() => {
|
|
|
|
const timer = setTimeout(() => {
|
|
|
|
setSpin(false)
|
|
|
|
}, 500)
|
|
|
|
return () => clearTimeout(timer)
|
|
|
|
}, [spin])
|
|
|
|
|
|
|
|
const handleResetLayout = () => {
|
|
|
|
setSavedLayouts(defaultLayouts)
|
|
|
|
setSpin(true)
|
|
|
|
}
|
|
|
|
|
2021-04-22 05:33:35 -07:00
|
|
|
return (
|
|
|
|
<div className={`flex relative ${className}`}>
|
2021-04-22 07:45:36 -07:00
|
|
|
<Tooltip content="Reset layout">
|
|
|
|
<button
|
|
|
|
onClick={() => handleResetLayout()}
|
|
|
|
className="flex items-center justify-center rounded-full bg-th-bkg-3 w-8 h-8 mr-4 hover:text-th-primary focus:outline-none"
|
|
|
|
>
|
|
|
|
<RefreshIcon className={`w-5 h-5 ${spin ? 'animate-spin' : null}`} />
|
|
|
|
</button>
|
|
|
|
</Tooltip>
|
2021-04-22 05:33:35 -07:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ResetLayout
|