diff options
| author | David Lönnhager <david.l@mullvad.net> | 2021-06-16 10:22:47 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2021-06-18 11:53:28 +0200 |
| commit | 5453eece3a53c4cc45c8987a88789e43fb214912 (patch) | |
| tree | c36308988a46a5125949f47611e7f76cba21c27a /gui/src/renderer | |
| parent | 335cc80d9347f43264765a3dd359eda83c782bc8 (diff) | |
| download | mullvadvpn-5453eece3a53c4cc45c8987a88789e43fb214912.tar.xz mullvadvpn-5453eece3a53c4cc45c8987a88789e43fb214912.zip | |
Update account history RPCs
Diffstat (limited to 'gui/src/renderer')
| -rw-r--r-- | gui/src/renderer/app.tsx | 10 | ||||
| -rw-r--r-- | gui/src/renderer/components/Login.tsx | 48 | ||||
| -rw-r--r-- | gui/src/renderer/components/Support.tsx | 4 | ||||
| -rw-r--r-- | gui/src/renderer/containers/LoginPage.tsx | 2 | ||||
| -rw-r--r-- | gui/src/renderer/redux/account/actions.ts | 4 | ||||
| -rw-r--r-- | gui/src/renderer/redux/account/reducers.ts | 4 |
6 files changed, 35 insertions, 37 deletions
diff --git a/gui/src/renderer/app.tsx b/gui/src/renderer/app.tsx index 7627428059..9fa0e4a456 100644 --- a/gui/src/renderer/app.tsx +++ b/gui/src/renderer/app.tsx @@ -148,7 +148,7 @@ export default class AppRenderer { this.setAccountExpiry(newAccountData && newAccountData.expiry); }); - IpcRendererEventChannel.accountHistory.listen((newAccountHistory: AccountToken[]) => { + IpcRendererEventChannel.accountHistory.listen((newAccountHistory?: AccountToken) => { this.setAccountHistory(newAccountHistory); }); @@ -337,8 +337,8 @@ export default class AppRenderer { return IpcRendererEventChannel.settings.setDnsOptions(dns); } - public removeAccountFromHistory(accountToken: AccountToken): Promise<void> { - return IpcRendererEventChannel.accountHistory.removeItem(accountToken); + public clearAccountHistory(): Promise<void> { + return IpcRendererEventChannel.accountHistory.clear(); } public async openLinkWithAuth(link: string): Promise<void> { @@ -455,7 +455,7 @@ export default class AppRenderer { return IpcRendererEventChannel.splitTunneling.launchApplication(application); } - public collectProblemReport(toRedact: string[]): Promise<string> { + public collectProblemReport(toRedact?: string): Promise<string> { return IpcRendererEventChannel.problemReport.collectLogs(toRedact); } @@ -653,7 +653,7 @@ export default class AppRenderer { } } - private setAccountHistory(accountHistory: AccountToken[]) { + private setAccountHistory(accountHistory?: AccountToken) { this.reduxActions.account.updateAccountHistory(accountHistory); } diff --git a/gui/src/renderer/components/Login.tsx b/gui/src/renderer/components/Login.tsx index 6118f7ac8e..e672094f99 100644 --- a/gui/src/renderer/components/Login.tsx +++ b/gui/src/renderer/components/Login.tsx @@ -36,13 +36,13 @@ import { AriaControlGroup, AriaControlled, AriaControls } from './AriaGroup'; interface IProps { accountToken?: AccountToken; - accountHistory: AccountToken[]; + accountHistory?: AccountToken; loginState: LoginState; openExternalLink: (type: string) => void; login: (accountToken: AccountToken) => void; resetLoginError: () => void; updateAccountToken: (accountToken: AccountToken) => void; - removeAccountTokenFromHistory: (accountToken: AccountToken) => Promise<void>; + clearAccountHistory: () => Promise<void>; createNewAccount: () => void; } @@ -208,7 +208,9 @@ export default class Login extends React.Component<IProps, IState> { } private shouldShowAccountHistory() { - return this.allowInteraction() && this.state.isActive && this.props.accountHistory.length > 0; + return ( + this.allowInteraction() && this.state.isActive && this.props.accountHistory !== undefined + ); } private shouldShowFooter() { @@ -223,13 +225,13 @@ export default class Login extends React.Component<IProps, IState> { this.props.login(accountToken); }; - private onRemoveAccountFromHistory = (accountToken: string) => { - consumePromise(this.removeAccountFromHistory(accountToken)); + private onClearAccountHistory = () => { + consumePromise(this.clearAccountHistory()); }; - private async removeAccountFromHistory(accountToken: AccountToken) { + private async clearAccountHistory() { try { - await this.props.removeAccountTokenFromHistory(accountToken); + await this.props.clearAccountHistory(); // TODO: Remove account from memory } catch (error) { @@ -288,9 +290,9 @@ export default class Login extends React.Component<IProps, IState> { <Accordion expanded={this.shouldShowAccountHistory()}> <StyledAccountDropdownContainer> <AccountDropdown - items={this.props.accountHistory.slice().reverse()} + item={this.props.accountHistory} onSelect={this.onSelectAccountFromHistory} - onRemove={this.onRemoveAccountFromHistory} + onRemove={this.onClearAccountHistory} /> </StyledAccountDropdownContainer> </Accordion> @@ -316,28 +318,24 @@ export default class Login extends React.Component<IProps, IState> { } interface IAccountDropdownProps { - items: AccountToken[]; + item?: AccountToken; onSelect: (value: AccountToken) => void; onRemove: (value: AccountToken) => void; } function AccountDropdown(props: IAccountDropdownProps) { - const uniqueItems = [...new Set(props.items)]; + const token = props.item; + if (!token) { + return null; + } + const label = formatAccountToken(token); return ( - <> - {uniqueItems.map((token) => { - const label = formatAccountToken(token); - return ( - <AccountDropdownItem - key={token} - value={token} - label={label} - onSelect={props.onSelect} - onRemove={props.onRemove} - /> - ); - })} - </> + <AccountDropdownItem + value={token} + label={label} + onSelect={props.onSelect} + onRemove={props.onRemove} + /> ); } diff --git a/gui/src/renderer/components/Support.tsx b/gui/src/renderer/components/Support.tsx index e7960a30c7..d34e6b6b08 100644 --- a/gui/src/renderer/components/Support.tsx +++ b/gui/src/renderer/components/Support.tsx @@ -49,13 +49,13 @@ interface ISupportState { interface ISupportProps { defaultEmail: string; defaultMessage: string; - accountHistory: AccountToken[]; + accountHistory?: AccountToken; isOffline: boolean; onClose: () => void; viewLog: (path: string) => void; saveReportForm: (form: ISupportReportForm) => void; clearReportForm: () => void; - collectProblemReport: (accountsToRedact: string[]) => Promise<string>; + collectProblemReport: (accountToRedact?: string) => Promise<string>; sendProblemReport: (email: string, message: string, savedReportId: string) => Promise<void>; outdatedVersion: boolean; suggestedIsBeta: boolean; diff --git a/gui/src/renderer/containers/LoginPage.tsx b/gui/src/renderer/containers/LoginPage.tsx index f937beb590..a56e6ec04a 100644 --- a/gui/src/renderer/containers/LoginPage.tsx +++ b/gui/src/renderer/containers/LoginPage.tsx @@ -25,7 +25,7 @@ const mapDispatchToProps = (dispatch: ReduxDispatch, props: IAppContext) => { }, openExternalLink: (url: string) => props.app.openUrl(url), updateAccountToken, - removeAccountTokenFromHistory: (token: string) => props.app.removeAccountFromHistory(token), + clearAccountHistory: () => props.app.clearAccountHistory(), createNewAccount: () => consumePromise(props.app.createNewAccount()), }; }; diff --git a/gui/src/renderer/redux/account/actions.ts b/gui/src/renderer/redux/account/actions.ts index 3c0bad3c7b..b8fbe94d39 100644 --- a/gui/src/renderer/redux/account/actions.ts +++ b/gui/src/renderer/redux/account/actions.ts @@ -44,7 +44,7 @@ interface IUpdateAccountTokenAction { interface IUpdateAccountHistoryAction { type: 'UPDATE_ACCOUNT_HISTORY'; - accountHistory: AccountToken[]; + accountHistory?: AccountToken; } interface IUpdateAccountExpiryAction { @@ -125,7 +125,7 @@ function updateAccountToken(token: AccountToken): IUpdateAccountTokenAction { }; } -function updateAccountHistory(accountHistory: AccountToken[]): IUpdateAccountHistoryAction { +function updateAccountHistory(accountHistory?: AccountToken): IUpdateAccountHistoryAction { return { type: 'UPDATE_ACCOUNT_HISTORY', accountHistory, diff --git a/gui/src/renderer/redux/account/reducers.ts b/gui/src/renderer/redux/account/reducers.ts index 8de7b2d07e..53bc55db1b 100644 --- a/gui/src/renderer/redux/account/reducers.ts +++ b/gui/src/renderer/redux/account/reducers.ts @@ -8,14 +8,14 @@ export type LoginState = | { type: 'failed'; method: LoginMethod; error: Error }; export interface IAccountReduxState { accountToken?: AccountToken; - accountHistory: AccountToken[]; + accountHistory?: AccountToken; expiry?: string; // ISO8601 status: LoginState; } const initialState: IAccountReduxState = { accountToken: undefined, - accountHistory: [], + accountHistory: undefined, expiry: undefined, status: { type: 'none' }, }; |
