From e4a0094b3e2d52f06429f887eb357ed16e31162b Mon Sep 17 00:00:00 2001 From: CrescentLeaf Date: Sat, 6 Sep 2025 23:27:22 +0800 Subject: [PATCH] fix(?): SplitJS init after React Component inited --- client/index.html | 8 -------- client/ui/App.tsx | 33 ++++++++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/client/index.html b/client/index.html index a63f62e..dffd93b 100644 --- a/client/index.html +++ b/client/index.html @@ -124,14 +124,6 @@ } window.addEventListener('resize', onResize) onResize() - - window.addEventListener('load', () => { - Split(['#SideBar', '#ChatFragment'], { - sizes: [25, 75], - minSize: [200, 400], - gutterSize: 2, - }) - }) diff --git a/client/ui/App.tsx b/client/ui/App.tsx index 263bafd..8988e76 100644 --- a/client/ui/App.tsx +++ b/client/ui/App.tsx @@ -11,6 +11,24 @@ import { MduiDialog, React, MduiNavigationRail, MduiTextField, MduiButton } from import User from "../api/client_data/User.ts" import RecentChat from "../api/client_data/RecentChat.ts" +import '../typedef/mdui-jsx.d.ts' + +declare function Split(r: unknown, s: unknown): { + setSizes?: undefined; + getSizes?: undefined; + collapse?: undefined; + destroy?: undefined; + parent?: undefined; + pairs?: undefined; +} | { + setSizes: (e: unknown) => void; + getSizes: () => unknown; + collapse: (e: unknown) => void; + destroy: (e: unknown, t: unknown) => void; + parent: unknown; + pairs: unknown[]; +} + export default function App() { const [recentsList, setRecentsList] = React.useState([ { @@ -54,8 +72,13 @@ export default function App() { const loginButtonRef: React.MutableRefObject = React.useRef(null) React.useEffect(() => { - // deno-lint-ignore no-window-prefix no-window - window.addEventListener('load', async () => { + ;(async () => { + Split(['#SideBar', '#ChatFragment'], { + sizes: [25, 75], + minSize: [200, 400], + gutterSize: 2, + }) + Client.connect() const re = await Client.invoke("User.auth", { access_token: data.access_token, @@ -64,7 +87,7 @@ export default function App() { loginDialogRef.current!.open = true else if (re.code != 200) snackbar("驗證失敗: " + re.msg) - }) + })() }, []) return ( @@ -97,7 +120,7 @@ export default function App() { { recentsList.map((v) => @@ -115,7 +138,7 @@ export default function App() { {