fix: update protections UI correctly after enabling protections (#587)

This commit is contained in:
Vardan Hakobyan
2022-04-13 17:32:48 +04:00
committed by GitHub
parent 51fd22aa2a
commit cf705b3bd8
2 changed files with 10 additions and 6 deletions

View File

@@ -347,7 +347,7 @@ export const useDeleteNoteWithPrivileges = (
export const useProtectionSessionExpiry = () => {
// Context
const application = React.useContext(ApplicationContext);
const application = useSafeApplicationContext();
const getProtectionsDisabledUntil = React.useCallback(() => {
const protectionExpiry = application?.getProtectionSessionExpiryDate();
@@ -391,7 +391,12 @@ export const useProtectionSessionExpiry = () => {
useEffect(() => {
const removeProtectionLengthSubscriber = application?.addEventObserver(
async event => {
if (event === ApplicationEvent.UnprotectedSessionBegan) {
if (
[
ApplicationEvent.UnprotectedSessionBegan,
ApplicationEvent.UnprotectedSessionExpired,
].includes(event)
) {
setProtectionsDisabledUntil(getProtectionsDisabledUntil());
}
}

View File

@@ -2,8 +2,8 @@ import { ButtonCell } from '@Components/ButtonCell';
import { SectionHeader } from '@Components/SectionHeader';
import { TableSection } from '@Components/TableSection';
import { useProtectionSessionExpiry } from '@Lib/snjs_helper_hooks';
import { ApplicationContext } from '@Root/ApplicationContext';
import React, { useContext } from 'react';
import { useSafeApplicationContext } from '@Root/hooks/useSafeApplicationContext';
import React from 'react';
import {
BaseView,
StyledSectionedTableCell,
@@ -19,8 +19,7 @@ type Props = {
export const ProtectionsSection = (props: Props) => {
// Context
const application = useContext(ApplicationContext);
const application = useSafeApplicationContext();
// State
const [protectionsDisabledUntil] = useProtectionSessionExpiry();