refactor: reviewer's comments
- cleanup event observers in `useEffect` - other small changes
This commit is contained in:
@@ -102,12 +102,13 @@ const AccountMenu = observer(({ application, appState }: Props) => {
|
|||||||
const [user, setUser] = useState(application.getUser());
|
const [user, setUser] = useState(application.getUser());
|
||||||
const [canAddPasscode, setCanAddPasscode] = useState(!application.isEphemeralSession());
|
const [canAddPasscode, setCanAddPasscode] = useState(!application.isEphemeralSession());
|
||||||
const [hasProtections] = useState(application.hasProtectionSources());
|
const [hasProtections] = useState(application.hasProtectionSources());
|
||||||
const [notesAndTagsCount] = useState(appState.accountMenu.notesAndTagsCount);
|
|
||||||
|
|
||||||
const [isEmailFocused, setIsEmailFocused] = useState(false);
|
const [isEmailFocused, setIsEmailFocused] = useState(false);
|
||||||
const [isPasscodeFocused, setIsPasscodeFocused] = useState(false);
|
const [isPasscodeFocused, setIsPasscodeFocused] = useState(false);
|
||||||
|
|
||||||
const refreshedCredentialState = () => {
|
const { notesAndTagsCount } = appState.accountMenu;
|
||||||
|
|
||||||
|
const refreshCredentialState = () => {
|
||||||
setUser(application.getUser());
|
setUser(application.getUser());
|
||||||
setCanAddPasscode(!application.isEphemeralSession());
|
setCanAddPasscode(!application.isEphemeralSession());
|
||||||
setHasPasscode(application.hasPasscode());
|
setHasPasscode(application.hasPasscode());
|
||||||
@@ -497,9 +498,9 @@ const AccountMenu = observer(({ application, appState }: Props) => {
|
|||||||
|
|
||||||
// Add the required event observers
|
// Add the required event observers
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
application.addEventObserver(
|
const removeAppLaunchedObserver = application.addEventObserver(
|
||||||
async () => {
|
async () => {
|
||||||
refreshedCredentialState();
|
refreshCredentialState();
|
||||||
loadHost();
|
loadHost();
|
||||||
reloadAutoLockInterval();
|
reloadAutoLockInterval();
|
||||||
refreshEncryptionStatus();
|
refreshEncryptionStatus();
|
||||||
@@ -507,19 +508,25 @@ const AccountMenu = observer(({ application, appState }: Props) => {
|
|||||||
ApplicationEvent.Launched
|
ApplicationEvent.Launched
|
||||||
);
|
);
|
||||||
|
|
||||||
application.addEventObserver(
|
const removeKeyStatusChangedObserver = application.addEventObserver(
|
||||||
async () => {
|
async () => {
|
||||||
refreshedCredentialState();
|
refreshCredentialState();
|
||||||
},
|
},
|
||||||
ApplicationEvent.KeyStatusChanged
|
ApplicationEvent.KeyStatusChanged
|
||||||
);
|
);
|
||||||
|
|
||||||
application.addEventObserver(
|
const removeProtectionSessionExpiryDateChangedObserver = application.addEventObserver(
|
||||||
async () => {
|
async () => {
|
||||||
setProtectionsDisabledUntil(getProtectionsDisabledUntil())
|
setProtectionsDisabledUntil(getProtectionsDisabledUntil());
|
||||||
},
|
},
|
||||||
ApplicationEvent.ProtectionSessionExpiryDateChanged
|
ApplicationEvent.ProtectionSessionExpiryDateChanged
|
||||||
)
|
);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
removeAppLaunchedObserver();
|
||||||
|
removeKeyStatusChangedObserver();
|
||||||
|
removeProtectionSessionExpiryDateChangedObserver();
|
||||||
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// `reloadAutoLockInterval` gets interval asynchronously, therefore we call `useEffect` to set initial
|
// `reloadAutoLockInterval` gets interval asynchronously, therefore we call `useEffect` to set initial
|
||||||
|
|||||||
Reference in New Issue
Block a user