refactor: move user-related data to appStore
This commit is contained in:
@@ -11,20 +11,17 @@ import TargetedKeyboardEvent = JSXInternal.TargetedKeyboardEvent;
|
|||||||
import { WebApplication } from '@/ui_models/application';
|
import { WebApplication } from '@/ui_models/application';
|
||||||
import { useEffect, useRef, useState } from 'preact/hooks';
|
import { useEffect, useRef, useState } from 'preact/hooks';
|
||||||
import TargetedMouseEvent = JSXInternal.TargetedMouseEvent;
|
import TargetedMouseEvent = JSXInternal.TargetedMouseEvent;
|
||||||
import { User } from '@standardnotes/snjs/dist/@types/services/api/responses';
|
|
||||||
import { observer } from 'mobx-react-lite';
|
import { observer } from 'mobx-react-lite';
|
||||||
import { AppState } from '@/ui_models/app_state';
|
import { AppState } from '@/ui_models/app_state';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
application: WebApplication;
|
application: WebApplication;
|
||||||
appState: AppState;
|
appState: AppState;
|
||||||
user: User | undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Authentication = observer(({
|
const Authentication = observer(({
|
||||||
application,
|
application,
|
||||||
appState,
|
appState,
|
||||||
user
|
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
|
|
||||||
const [showAdvanced, setShowAdvanced] = useState(false);
|
const [showAdvanced, setShowAdvanced] = useState(false);
|
||||||
@@ -50,6 +47,8 @@ const Authentication = observer(({
|
|||||||
closeAccountMenu
|
closeAccountMenu
|
||||||
} = appState.accountMenu;
|
} = appState.accountMenu;
|
||||||
|
|
||||||
|
const user = application.getUser();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isEmailFocused) {
|
if (isEmailFocused) {
|
||||||
emailInputRef.current.focus();
|
emailInputRef.current.focus();
|
||||||
|
|||||||
@@ -1,19 +1,16 @@
|
|||||||
import { AppState } from '@/ui_models/app_state';
|
import { AppState } from '@/ui_models/app_state';
|
||||||
import { useState } from 'preact/hooks';
|
import { useState } from 'preact/hooks';
|
||||||
import { WebApplication } from '@/ui_models/application';
|
import { WebApplication } from '@/ui_models/application';
|
||||||
import { User } from '@standardnotes/snjs/dist/@types/services/api/responses';
|
|
||||||
import { observer } from 'mobx-react-lite';
|
import { observer } from 'mobx-react-lite';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
application: WebApplication;
|
application: WebApplication;
|
||||||
appState: AppState;
|
appState: AppState;
|
||||||
user: User | undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Footer = observer(({
|
const Footer = observer(({
|
||||||
application,
|
application,
|
||||||
appState,
|
appState,
|
||||||
user
|
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const {
|
const {
|
||||||
showLogin,
|
showLogin,
|
||||||
@@ -23,6 +20,8 @@ const Footer = observer(({
|
|||||||
setSigningOut
|
setSigningOut
|
||||||
} = appState.accountMenu;
|
} = appState.accountMenu;
|
||||||
|
|
||||||
|
const user = application.getUser();
|
||||||
|
|
||||||
const { showBetaWarning, disableBetaWarning: disableAppStateBetaWarning } = appState;
|
const { showBetaWarning, disableBetaWarning: disableAppStateBetaWarning } = appState;
|
||||||
|
|
||||||
const [appVersion] = useState(() => `v${((window as any).electronAppVersion || application.bridge.appVersion)}`);
|
const [appVersion] = useState(() => `v${((window as any).electronAppVersion || application.bridge.appVersion)}`);
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { WebApplication } from '@/ui_models/application';
|
import { WebApplication } from '@/ui_models/application';
|
||||||
import { FunctionalComponent } from 'preact';
|
import { FunctionalComponent } from 'preact';
|
||||||
import { useCallback, useState } from '@node_modules/preact/hooks';
|
import { useCallback, useState } from 'preact/hooks';
|
||||||
import { useEffect } from 'preact/hooks';
|
import { useEffect } from 'preact/hooks';
|
||||||
import { ApplicationEvent } from '@node_modules/@standardnotes/snjs';
|
import { ApplicationEvent } from '@standardnotes/snjs';
|
||||||
import { isSameDay } from '@/utils';
|
import { isSameDay } from '@/utils';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
|
|||||||
@@ -2,19 +2,19 @@ import { observer } from 'mobx-react-lite';
|
|||||||
import { AppState } from '@/ui_models/app_state';
|
import { AppState } from '@/ui_models/app_state';
|
||||||
import { PasswordWizardType } from '@/types';
|
import { PasswordWizardType } from '@/types';
|
||||||
import { WebApplication } from '@/ui_models/application';
|
import { WebApplication } from '@/ui_models/application';
|
||||||
|
import { User } from '@standardnotes/snjs/dist/@types/services/api/responses';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
email: string;
|
|
||||||
appState: AppState;
|
appState: AppState;
|
||||||
application: WebApplication;
|
application: WebApplication;
|
||||||
}
|
}
|
||||||
|
|
||||||
const User = observer(({
|
const User = observer(({
|
||||||
email,
|
|
||||||
appState,
|
appState,
|
||||||
application,
|
application,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const { server, closeAccountMenu } = appState.accountMenu;
|
const { server, closeAccountMenu } = appState.accountMenu;
|
||||||
|
const user = application.getUser();
|
||||||
|
|
||||||
const openPasswordWizard = () => {
|
const openPasswordWizard = () => {
|
||||||
closeAccountMenu();
|
closeAccountMenu();
|
||||||
@@ -48,7 +48,7 @@ const User = observer(({
|
|||||||
<div className="sk-panel-row">
|
<div className="sk-panel-row">
|
||||||
<div className="sk-panel-column">
|
<div className="sk-panel-column">
|
||||||
<div className="sk-h1 sk-bold wrap">
|
<div className="sk-h1 sk-bold wrap">
|
||||||
{email}
|
{(user as User).email}
|
||||||
</div>
|
</div>
|
||||||
<div className="sk-subtitle neutral">
|
<div className="sk-subtitle neutral">
|
||||||
{server}
|
{server}
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ import { observer } from 'mobx-react-lite';
|
|||||||
import { toDirective } from '@/components/utils';
|
import { toDirective } from '@/components/utils';
|
||||||
import { AppState } from '@/ui_models/app_state';
|
import { AppState } from '@/ui_models/app_state';
|
||||||
import { WebApplication } from '@/ui_models/application';
|
import { WebApplication } from '@/ui_models/application';
|
||||||
import { useEffect, useState } from 'preact/hooks';
|
|
||||||
import { ApplicationEvent } from '@standardnotes/snjs';
|
|
||||||
import { ConfirmSignoutContainer } from '@/components/ConfirmSignoutModal';
|
import { ConfirmSignoutContainer } from '@/components/ConfirmSignoutModal';
|
||||||
import Authentication from '@/components/AccountMenu/Authentication';
|
import Authentication from '@/components/AccountMenu/Authentication';
|
||||||
import Footer from '@/components/AccountMenu/Footer';
|
import Footer from '@/components/AccountMenu/Footer';
|
||||||
@@ -20,27 +18,13 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const AccountMenu = observer(({ application, appState }: Props) => {
|
const AccountMenu = observer(({ application, appState }: Props) => {
|
||||||
const [user, setUser] = useState(application.getUser());
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
showLogin,
|
showLogin,
|
||||||
showRegister,
|
showRegister,
|
||||||
closeAccountMenu
|
closeAccountMenu
|
||||||
} = appState.accountMenu;
|
} = appState.accountMenu;
|
||||||
|
|
||||||
// Add the required event observers
|
const user = application.getUser();
|
||||||
useEffect(() => {
|
|
||||||
const removeKeyStatusChangedObserver = application.addEventObserver(
|
|
||||||
async () => {
|
|
||||||
setUser(application.getUser());
|
|
||||||
},
|
|
||||||
ApplicationEvent.KeyStatusChanged
|
|
||||||
);
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
removeKeyStatusChangedObserver();
|
|
||||||
};
|
|
||||||
}, [application]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="sn-component">
|
<div className="sn-component">
|
||||||
@@ -53,7 +37,6 @@ const AccountMenu = observer(({ application, appState }: Props) => {
|
|||||||
<Authentication
|
<Authentication
|
||||||
application={application}
|
application={application}
|
||||||
appState={appState}
|
appState={appState}
|
||||||
user={user}
|
|
||||||
/>
|
/>
|
||||||
{!showLogin && !showRegister && (
|
{!showLogin && !showRegister && (
|
||||||
<div>
|
<div>
|
||||||
@@ -61,7 +44,6 @@ const AccountMenu = observer(({ application, appState }: Props) => {
|
|||||||
<User
|
<User
|
||||||
application={application}
|
application={application}
|
||||||
appState={appState}
|
appState={appState}
|
||||||
email={user.email}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<Encryption appState={appState} />
|
<Encryption appState={appState} />
|
||||||
@@ -85,7 +67,6 @@ const AccountMenu = observer(({ application, appState }: Props) => {
|
|||||||
<Footer
|
<Footer
|
||||||
application={application}
|
application={application}
|
||||||
appState={appState}
|
appState={appState}
|
||||||
user={user}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user