refactor: move user-related data to appStore

This commit is contained in:
VardanHakobyan
2021-06-16 17:00:13 +04:00
parent 018251838c
commit c897199d33
5 changed files with 10 additions and 31 deletions

View File

@@ -2,8 +2,6 @@ import { observer } from 'mobx-react-lite';
import { toDirective } from '@/components/utils';
import { AppState } from '@/ui_models/app_state';
import { WebApplication } from '@/ui_models/application';
import { useEffect, useState } from 'preact/hooks';
import { ApplicationEvent } from '@standardnotes/snjs';
import { ConfirmSignoutContainer } from '@/components/ConfirmSignoutModal';
import Authentication from '@/components/AccountMenu/Authentication';
import Footer from '@/components/AccountMenu/Footer';
@@ -20,27 +18,13 @@ type Props = {
};
const AccountMenu = observer(({ application, appState }: Props) => {
const [user, setUser] = useState(application.getUser());
const {
showLogin,
showRegister,
closeAccountMenu
} = appState.accountMenu;
// Add the required event observers
useEffect(() => {
const removeKeyStatusChangedObserver = application.addEventObserver(
async () => {
setUser(application.getUser());
},
ApplicationEvent.KeyStatusChanged
);
return () => {
removeKeyStatusChangedObserver();
};
}, [application]);
const user = application.getUser();
return (
<div className="sn-component">
@@ -53,7 +37,6 @@ const AccountMenu = observer(({ application, appState }: Props) => {
<Authentication
application={application}
appState={appState}
user={user}
/>
{!showLogin && !showRegister && (
<div>
@@ -61,7 +44,6 @@ const AccountMenu = observer(({ application, appState }: Props) => {
<User
application={application}
appState={appState}
email={user.email}
/>
)}
<Encryption appState={appState} />
@@ -85,7 +67,6 @@ const AccountMenu = observer(({ application, appState }: Props) => {
<Footer
application={application}
appState={appState}
user={user}
/>
</div>
</div>