From 04b510d88b9ba923b34d864da8412404e70a8a80 Mon Sep 17 00:00:00 2001 From: infinite-persistence Date: Thu, 5 Aug 2021 15:00:21 +0800 Subject: [PATCH] [Account] grab SyncToggle and AccountPassword Also made visual changes for the new Settings Page. ## SyncToggle: It will no longer be under a dedicated Card, so the "Sync" title is not there to give context for the case of "no verified email". Changed it such that the checkbox is always visible (it's label is self-explanatory) but disable when email is not set. The "Add Email" button will then appear below, so everything now makes sense in context. --- ui/component/settingAccount/index.js | 15 ++++ ui/component/settingAccount/view.jsx | 55 ++++++++++++ ui/component/settingAccountPassword/view.jsx | 95 ++++++++++---------- ui/component/syncToggle/view.jsx | 30 ++++--- ui/page/settings/index.js | 7 +- ui/page/settings/view.jsx | 50 ++--------- 6 files changed, 144 insertions(+), 108 deletions(-) create mode 100644 ui/component/settingAccount/index.js create mode 100644 ui/component/settingAccount/view.jsx diff --git a/ui/component/settingAccount/index.js b/ui/component/settingAccount/index.js new file mode 100644 index 000000000..9abbe808b --- /dev/null +++ b/ui/component/settingAccount/index.js @@ -0,0 +1,15 @@ +import { connect } from 'react-redux'; +import { doWalletStatus, selectWalletIsEncrypted } from 'lbry-redux'; +import { selectUserVerifiedEmail } from 'redux/selectors/user'; +import SettingAccount from './view'; + +const select = (state) => ({ + isAuthenticated: selectUserVerifiedEmail(state), + walletEncrypted: selectWalletIsEncrypted(state), +}); + +const perform = (dispatch) => ({ + doWalletStatus: () => dispatch(doWalletStatus()), +}); + +export default connect(select, perform)(SettingAccount); diff --git a/ui/component/settingAccount/view.jsx b/ui/component/settingAccount/view.jsx new file mode 100644 index 000000000..4097b532d --- /dev/null +++ b/ui/component/settingAccount/view.jsx @@ -0,0 +1,55 @@ +// @flow +import React from 'react'; +import Card from 'component/common/card'; +import SettingAccountPassword from 'component/settingAccountPassword'; +import SyncToggle from 'component/syncToggle'; +import { getPasswordFromCookie } from 'util/saved-passwords'; + +type Props = { + // --- select --- + isAuthenticated: boolean, + walletEncrypted: boolean, + // --- perform --- + doWalletStatus: () => void, +}; + +export default function SettingAccount(props: Props) { + const { isAuthenticated, walletEncrypted, doWalletStatus } = props; + const [storedPassword, setStoredPassword] = React.useState(false); + + // Determine if password is stored. + React.useEffect(() => { + if (isAuthenticated || !IS_WEB) { + doWalletStatus(); + getPasswordFromCookie().then((p) => { + if (typeof p === 'string') { + setStoredPassword(true); + } + }); + } + // enterSettings(); @KP need to do this at each component, or just at Settings Page? + }, []); // eslint-disable-line react-hooks/exhaustive-deps + + return ( + + {isAuthenticated && ( +
+ +
+ )} + + {/* @if TARGET='app' */} +
+ +
+ {/* @endif */} + + } + /> + ); +} diff --git a/ui/component/settingAccountPassword/view.jsx b/ui/component/settingAccountPassword/view.jsx index a63dff59a..494d078e6 100644 --- a/ui/component/settingAccountPassword/view.jsx +++ b/ui/component/settingAccountPassword/view.jsx @@ -3,7 +3,6 @@ import React, { useState } from 'react'; import { FormField, Form } from 'component/common/form'; import Button from 'component/button'; import ErrorText from 'component/common/error-text'; -import Card from 'component/common/card'; import * as PAGES from 'constants/pages'; type Props = { @@ -38,54 +37,52 @@ export default function SettingAccountPassword(props: Props) { } }, [passwordSetSuccess, setOldPassword, setNewPassword, doClearPasswordEntry, doToast]); - return ( - -
- {hasPassword && ( - setOldPassword(e.target.value)} - /> - )} - setNewPassword(e.target.value)} - /> - -
-
- - {passwordSetError && ( -
- {passwordSetError} -
- )} - - ) : ( -