From 17515848b434da5944f0be62e7b98c4dd01c6c32 Mon Sep 17 00:00:00 2001 From: VardanHakobyan Date: Wed, 16 Jun 2021 16:00:14 +0400 Subject: [PATCH] fix: observe `KeyStatusChanged` event and correctly update `hasProtections` info --- .../javascripts/components/AccountMenu/Protections.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/components/AccountMenu/Protections.tsx b/app/assets/javascripts/components/AccountMenu/Protections.tsx index 2b4049974..fbc180566 100644 --- a/app/assets/javascripts/components/AccountMenu/Protections.tsx +++ b/app/assets/javascripts/components/AccountMenu/Protections.tsx @@ -14,7 +14,7 @@ const Protections: FunctionalComponent = ({ application }) => { application.clearProtectionSession(); }; - const hasProtections = application.hasProtectionSources(); + const [hasProtections, setHasProtections] = useState(() => application.hasProtectionSources()); const getProtectionsDisabledUntil = useCallback((): string | null => { const protectionExpiry = application.getProtectionSessionExpiryDate(); @@ -51,8 +51,16 @@ const Protections: FunctionalComponent = ({ application }) => { ApplicationEvent.ProtectionSessionExpiryDateChanged ); + const removeKeyStatusChangedObserver = application.addEventObserver( + async () => { + setHasProtections(application.hasProtectionSources()); + }, + ApplicationEvent.KeyStatusChanged + ); + return () => { removeProtectionSessionExpiryDateChangedObserver(); + removeKeyStatusChangedObserver(); }; }, [application, getProtectionsDisabledUntil]);