From de933a1a73a00326b245ff3bac1e22634c04281a Mon Sep 17 00:00:00 2001 From: Martin Vladic Date: Mon, 21 Oct 2024 16:05:34 +0200 Subject: [PATCH] fix theme switching --- packages/home/settings.tsx | 11 ++++++++-- .../project-editor/flow/editor/render.tsx | 22 ++++++++++++------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/packages/home/settings.tsx b/packages/home/settings.tsx index 9dc1a9fe..7370358d 100644 --- a/packages/home/settings.tsx +++ b/packages/home/settings.tsx @@ -201,7 +201,13 @@ class SettingsController { setTimeFormat(value); } + onThemeSwitchedTimeout: any; + switchTheme(value: boolean) { + if (this.onThemeSwitchedTimeout) { + return; + } + this.isDarkTheme = value; setIsDarkTheme(value); this.onThemeSwitched(); @@ -238,9 +244,10 @@ class SettingsController { "../../node_modules/flexlayout-react/style/light.css"; } - setTimeout(() => { + this.onThemeSwitchedTimeout = setTimeout(() => { + this.onThemeSwitchedTimeout = undefined; content.style.opacity = ""; - }, 200); + }, 500); } removeItemFromMRU(mruItem: IMruItem) { diff --git a/packages/project-editor/flow/editor/render.tsx b/packages/project-editor/flow/editor/render.tsx index 3893eccd..aaf32489 100644 --- a/packages/project-editor/flow/editor/render.tsx +++ b/packages/project-editor/flow/editor/render.tsx @@ -179,11 +179,6 @@ export const ComponentEnclosure = observer( return; } - if (this.updateComponentTimeout) { - clearTimeout(this.updateComponentTimeout); - this.updateComponentTimeout = undefined; - } - if (this.elRef.current && this.listIndex == 0) { const component = this.props.component; if (component instanceof ProjectEditor.PageClass) { @@ -198,7 +193,6 @@ export const ComponentEnclosure = observer( if (this.elRef.current.offsetParent == null) { // do not calculate geometry if element is not visible - this.updateComponentTimeout = setTimeout(() => { this.updateComponentTimeout = undefined; this.updateComponentGeometry(); @@ -221,12 +215,24 @@ export const ComponentEnclosure = observer( } }; + debounceUpdateComponentGeometry = () => { + if (this.updateComponentTimeout) { + clearTimeout(this.updateComponentTimeout); + this.updateComponentTimeout = undefined; + } + + this.updateComponentTimeout = setTimeout(() => { + this.updateComponentTimeout = undefined; + this.updateComponentGeometry(); + }); + }; + componentDidMount() { - this.updateComponentGeometry(); + this.debounceUpdateComponentGeometry(); } componentDidUpdate() { - this.updateComponentGeometry(); + this.debounceUpdateComponentGeometry(); } componentWillUnmount() {