From 04a777a98ee382cf07ecb1650df56c18bbd2fe66 Mon Sep 17 00:00:00 2001 From: lucas lelievre Date: Sun, 19 Feb 2023 23:01:39 +0100 Subject: [PATCH] hide overlay when no initial response fronm it --- gui/src/components/widgets/OverlayWidget.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/gui/src/components/widgets/OverlayWidget.tsx b/gui/src/components/widgets/OverlayWidget.tsx index 6fa84268ec..fb010339da 100644 --- a/gui/src/components/widgets/OverlayWidget.tsx +++ b/gui/src/components/widgets/OverlayWidget.tsx @@ -1,18 +1,19 @@ -import { useEffect } from 'react'; +import { useLocalization } from '@fluent/react'; +import { useEffect, useState } from 'react'; import { useForm } from 'react-hook-form'; import { KeyValuesT, MessageT, Payload, Topic } from 'solarxr-protocol'; import { OVERLAY_DISPLAY_SETTINGS_TOPIC, PayloadData, - usePubSub, + usePubSub } from '../../hooks/pubSub'; import { CheckBox } from '../commons/Checkbox'; -import { useLocalization } from '@fluent/react'; import { Typography } from '../commons/Typography'; export function OverlayWidget() { const { l10n } = useLocalization(); const { publish, subscribe, keyValues } = usePubSub(); + const [loading, setLoading] = useState(true); const { reset, control, handleSubmit, watch } = useForm<{ isVisible: boolean; isMirrored: boolean; @@ -26,6 +27,7 @@ export function OverlayWidget() { subscribe( OVERLAY_DISPLAY_SETTINGS_TOPIC, (payload: PayloadData, type: Payload) => { + setLoading(false); if (type !== Payload.KeyValues) throw new Error('Invalid payload'); const obj = keyValues(payload); reset({ @@ -63,7 +65,7 @@ export function OverlayWidget() { publish(message); }; - return ( + return !loading ? (
@@ -83,5 +85,7 @@ export function OverlayWidget() { label={l10n.getString('widget-overlay-is_mirrored_label')} > + ) : ( + <> ); }