-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathLegacy.tsx
35 lines (28 loc) · 925 Bytes
/
Legacy.tsx
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
33
34
35
import { FC, useState } from 'react'
import { useAppSelector, useObserverAncestor } from '@/hooks'
import { selectOptions } from '../global/optionsSlice'
import Timer from './Timer'
import { getRoot } from './utils'
const Legacy: FC<{ beta?: boolean }> = () => {
const options = useAppSelector(selectOptions)
const [timerRoot, setTimerRoot] = useState<HTMLElement>()
const showTimer = !!options?.problemsPage.timer
useObserverAncestor(
async state => {
if (!showTimer) return
const parent = await getRoot()
if (!state.isMount) return
const root = document.createElement('div')
root.style.marginRight = '15px'
parent.prepend(root)
setTimerRoot(root)
state.unmount.push(() => root && root.remove())
return root
},
[showTimer]
)
return (
<>{showTimer && timerRoot && <Timer beta={false} root={timerRoot} />}</>
)
}
export default Legacy