refactor: read the required data from appState instead of passing by parent component
This commit is contained in:
@@ -18,16 +18,12 @@ import { AppState } from '@/ui_models/app_state';
|
|||||||
type Props = {
|
type Props = {
|
||||||
application: WebApplication;
|
application: WebApplication;
|
||||||
appState: AppState;
|
appState: AppState;
|
||||||
closeAccountMenu: () => void;
|
|
||||||
notesAndTagsCount: number;
|
|
||||||
user: User | undefined;
|
user: User | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Authentication = observer(({
|
const Authentication = observer(({
|
||||||
application,
|
application,
|
||||||
appState,
|
appState,
|
||||||
closeAccountMenu,
|
|
||||||
notesAndTagsCount,
|
|
||||||
user
|
user
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
|
|
||||||
@@ -45,11 +41,13 @@ const Authentication = observer(({
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
server,
|
server,
|
||||||
|
notesAndTagsCount,
|
||||||
showLogin,
|
showLogin,
|
||||||
showRegister,
|
showRegister,
|
||||||
setShowLogin,
|
setShowLogin,
|
||||||
setShowRegister,
|
setShowRegister,
|
||||||
setServer
|
setServer,
|
||||||
|
closeAccountMenu
|
||||||
} = appState.accountMenu;
|
} = appState.accountMenu;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -3,14 +3,10 @@ import { observer } from 'mobx-react-lite';
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
appState: AppState;
|
appState: AppState;
|
||||||
notesAndTagsCount: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Encryption = observer(({
|
const Encryption = observer(({ appState }: Props) => {
|
||||||
appState,
|
const { isEncryptionEnabled, encryptionStatusString, notesAndTagsCount } = appState.accountMenu;
|
||||||
notesAndTagsCount
|
|
||||||
}: Props) => {
|
|
||||||
const { isEncryptionEnabled, encryptionStatusString } = appState.accountMenu;
|
|
||||||
|
|
||||||
const getEncryptionStatusForNotes = () => {
|
const getEncryptionStatusForNotes = () => {
|
||||||
const length = notesAndTagsCount;
|
const length = notesAndTagsCount;
|
||||||
|
|||||||
@@ -7,16 +7,14 @@ type Props = {
|
|||||||
email: string;
|
email: string;
|
||||||
appState: AppState;
|
appState: AppState;
|
||||||
application: WebApplication;
|
application: WebApplication;
|
||||||
closeAccountMenu: () => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const User = observer(({
|
const User = observer(({
|
||||||
email,
|
email,
|
||||||
appState,
|
appState,
|
||||||
application,
|
application,
|
||||||
closeAccountMenu
|
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const { server } = appState.accountMenu;
|
const { server, closeAccountMenu } = appState.accountMenu;
|
||||||
|
|
||||||
const openPasswordWizard = () => {
|
const openPasswordWizard = () => {
|
||||||
closeAccountMenu();
|
closeAccountMenu();
|
||||||
|
|||||||
@@ -23,16 +23,11 @@ const AccountMenu = observer(({ application, appState }: Props) => {
|
|||||||
const [user, setUser] = useState(application.getUser());
|
const [user, setUser] = useState(application.getUser());
|
||||||
|
|
||||||
const {
|
const {
|
||||||
notesAndTagsCount,
|
|
||||||
showLogin,
|
showLogin,
|
||||||
showRegister,
|
showRegister,
|
||||||
closeAccountMenu: closeAppStateAccountMenu
|
closeAccountMenu
|
||||||
} = appState.accountMenu;
|
} = appState.accountMenu;
|
||||||
|
|
||||||
const closeAccountMenu = () => {
|
|
||||||
closeAppStateAccountMenu();
|
|
||||||
};
|
|
||||||
|
|
||||||
// Add the required event observers
|
// Add the required event observers
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const removeKeyStatusChangedObserver = application.addEventObserver(
|
const removeKeyStatusChangedObserver = application.addEventObserver(
|
||||||
@@ -58,8 +53,6 @@ const AccountMenu = observer(({ application, appState }: Props) => {
|
|||||||
<Authentication
|
<Authentication
|
||||||
application={application}
|
application={application}
|
||||||
appState={appState}
|
appState={appState}
|
||||||
closeAccountMenu={closeAccountMenu}
|
|
||||||
notesAndTagsCount={notesAndTagsCount}
|
|
||||||
user={user}
|
user={user}
|
||||||
/>
|
/>
|
||||||
{!showLogin && !showRegister && (
|
{!showLogin && !showRegister && (
|
||||||
@@ -69,13 +62,9 @@ const AccountMenu = observer(({ application, appState }: Props) => {
|
|||||||
application={application}
|
application={application}
|
||||||
appState={appState}
|
appState={appState}
|
||||||
email={user.email}
|
email={user.email}
|
||||||
closeAccountMenu={closeAccountMenu}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<Encryption
|
<Encryption appState={appState} />
|
||||||
appState={appState}
|
|
||||||
notesAndTagsCount={notesAndTagsCount}
|
|
||||||
/>
|
|
||||||
<Protections application={application} />
|
<Protections application={application} />
|
||||||
<PasscodeLock
|
<PasscodeLock
|
||||||
application={application}
|
application={application}
|
||||||
|
|||||||
Reference in New Issue
Block a user