fix: plugins' HFS.onEvent not always effective #154

Massimo Melina committed Mar 14, 2023 at 14:44 UTC 8602137d95d23ae136c6b2dd547c085c4db3af20
1 file changed +8 -1
frontend/src/App.ts
+8 -1
@@ -1,18 +1,25 @@
1 // This file is part of HFS - Copyright 2021-2023, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
2
3 import { BrowserRouter, Route, Routes } from "react-router-dom"
4 -import { createElement as h } from 'react'
4 +import { createElement as h, useState } from 'react'
5 import { BrowseFiles } from "./BrowseFiles"
6 import { Dialogs } from './dialog'
7 import useTheme from "./useTheme"
8 import { useSnapState } from './state'
9 import { I18Nprovider } from './i18n'
10 +import { useEventListener } from 'usehooks-ts'
11
12 function App() {
13 useTheme()
14 + // wait for all plugins to be loaded
15 + const [ready, setReady] = useState(document.readyState === 'complete')
16 + useEventListener('load', () => setReady(true))
17 +
18 const { messageOnly } = useSnapState()
19 if (messageOnly)
20 return h('h1', { style: { textAlign: 'center'} }, messageOnly)
21 + if (!ready)
22 + return h('div', {}, '...')
23 return h(I18Nprovider, {},
24 h(BrowserRouter, {},
25 h(Routes, {},