move thememodule init to react land

pull/1760/merge
Joseph Izang 3 years ago committed by yann300
parent 235d7c5fda
commit 4cbfe7c5fe
  1. 30
      libs/remix-ui/theme-module/src/lib/remix-ui-theme-module.tsx

@ -10,6 +10,7 @@ export interface RemixUiThemeModuleProps {
export function RemixUiThemeModule({ themeModule }: RemixUiThemeModuleProps) { export function RemixUiThemeModule({ themeModule }: RemixUiThemeModuleProps) {
const [themeName, setThemeName] = useState('') const [themeName, setThemeName] = useState('')
const themeRef = useRef<any>(null)
useEffect(() => { useEffect(() => {
themeModule.switchTheme() themeModule.switchTheme()
@ -20,22 +21,27 @@ export function RemixUiThemeModule({ themeModule }: RemixUiThemeModuleProps) {
const linkRef = useRef<any>(null) const linkRef = useRef<any>(null)
function initTheme (callback: () => void) { function initTheme (callback: () => void) {
// const theme = yo`<link rel="stylesheet" href="${nextTheme.url}" id="theme-link"/>` // const theme = yo`<link rel="stylesheet" href="${nextTheme.url}" id="theme-link"/>`
if (themeModule.active) { if (themeModule.active) {
setNextTheme(themeModule.themes[themeModule.active]) // Theme setNextTheme(themeModule.themes[themeModule.active]) // Theme
document.documentElement.style.setProperty('--theme', nextTheme.quality) document.documentElement.style.setProperty('--theme', nextTheme.quality)
}
} }
} useEffect(() => {
useEffect(() => { const shell = document.querySelector('div[data-id="remixIDE"]') as any
const callback = () => { const splashScreen = document.querySelector('div[data-id="remixIDESplash"]') as Node
setTimeout(() => { const callback = () => {
document.body.removeChild(self._view.splashScreen) // setTimeout(() => {
self._view.el.style.visibility = 'visible' // document.body.removeChild(splashScreen)
}, 1500) // // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
addEventListener('load', () => { // shell!.style.visibility = 'visible'
// }, 1500)
}
document.addEventListener('load', () => {
if (callback) callback() if (callback) callback()
}) })
document.head.insertBefore(linkRef.current, document.head.firstChild) document.head.insertBefore(linkRef.current, document.head.firstChild)
}, []) }, [])
return ( return (
<link rel="stylesheet" href={nextTheme.url} ref={linkRef} id="theme-link"/> <link rel="stylesheet" href={nextTheme.url} ref={linkRef} id="theme-link"/>
) )

Loading…
Cancel
Save