Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

refactor(app): build the account chooser on the new account list

Hampuse4131f7bd7c3
diff --git a/fluxer_app/src/features/auth/components/accounts/AccountList.module.css b/fluxer_app/src/features/auth/components/accounts/AccountList.module.css
new file mode 100644
index 000000000..9dd43ce78
--- /dev/null
+++ b/fluxer_app/src/features/auth/components/accounts/AccountList.module.css
@@ -0,0 +1,272 @@
+/* SPDX-License-Identifier: AGPL-3.0-or-later */
+
+.root {
+ display: flex;
+ flex-direction: column;
+ gap: var(--spacing-3);
+ min-width: 0;
+ container-type: inline-size;
+}
+
+.error {
+ padding: var(--spacing-3);
+ border: 0.0625rem solid hsla(0, calc(100% * var(--saturation-factor)), 50%, 0.2);
+ border-radius: var(--radius-lg);
+ background-color: hsla(0, calc(100% * var(--saturation-factor)), 50%, 0.1);
+ color: var(--status-danger);
+ font-size: 0.875rem;
+ text-align: center;
+}
+
+.list {
+ display: flex;
+ flex-direction: column;
+ gap: var(--spacing-1);
+ margin: 0;
+ padding: 0;
+ list-style: none;
+}
+
+.row {
+ display: grid;
+ grid-template-columns: minmax(0, 1fr) auto;
+ align-items: center;
+ column-gap: var(--spacing-2);
+ min-width: 0;
+ padding-inline-end: var(--spacing-2);
+ border-radius: var(--radius-lg);
+ transition: background-color 120ms ease;
+}
+
+:global(:where(html.window-focused, html.unfocused-fully-interactive):not(.window-focus-activation-guard)) .row:hover {
+ background-color: var(--background-modifier-hover);
+}
+
+.row:has(.main:focus-visible) {
+ background-color: var(--background-modifier-hover);
+}
+
+.row:active:not(:has(.trailing:active, .confirm:active)) {
+ background-color: var(--background-modifier-selected);
+}
+
+.rowSelected,
+:global(:where(html.window-focused, html.unfocused-fully-interactive):not(.window-focus-activation-guard))
+ .rowSelected:hover {
+ background-color: var(--background-modifier-selected);
+}
+
+.rowConfirming {
+ background-color: var(--background-modifier-hover);
+}
+
+.main {
+ display: flex;
+ align-items: center;
+ gap: var(--spacing-3);
+ min-width: 0;
+ min-height: 3.5rem;
+ padding-block: var(--spacing-2);
+ padding-inline: var(--spacing-3) var(--spacing-1);
+ border: 0;
+ border-radius: var(--radius-lg);
+ background: none;
+ color: inherit;
+ font: inherit;
+ text-align: start;
+ cursor: pointer;
+ -webkit-tap-highlight-color: transparent;
+}
+
+.main:disabled {
+ cursor: default;
+}
+
+.avatar {
+ display: flex;
+ flex-shrink: 0;
+ transition: opacity 120ms ease;
+}
+
+.rowExpired .avatar {
+ opacity: 0.5;
+}
+
+.identity {
+ display: flex;
+ flex: 1;
+ flex-direction: column;
+ gap: 0.125rem;
+ min-width: 0;
+}
+
+.nameLine {
+ display: flex;
+ align-items: center;
+ gap: var(--spacing-1-5);
+ min-width: 0;
+}
+
+.name {
+ min-width: 0;
+ overflow: hidden;
+ color: var(--text-primary);
+ font-size: 0.9375rem;
+ font-weight: 600;
+ line-height: 1.25rem;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.username,
+.instance,
+.status {
+ min-width: 0;
+ font-size: 0.8125rem;
+ line-height: 1.125rem;
+}
+
+.username,
+.instance {
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.username {
+ color: var(--text-secondary);
+}
+
+.discriminator {
+ color: var(--text-tertiary);
+}
+
+.instance {
+ display: flex;
+ align-items: center;
+ gap: var(--spacing-1-5);
+ color: var(--text-tertiary);
+}
+
+.instanceMark {
+ display: inline-flex;
+ flex-shrink: 0;
+ width: 0.75rem;
+ height: 0.75rem;
+ align-items: center;
+ justify-content: center;
+ overflow: hidden;
+ border-radius: 0.1875rem;
+}
+
+.instanceMark svg,
+.instanceMark img {
+ display: block;
+ width: 100%;
+ height: 100%;
+ object-fit: cover;
+}
+
+.instanceLabel {
+ min-width: 0;
+ overflow: hidden;
+ text-overflow: ellipsis;
+}
+
+.status {
+ display: flex;
+ align-items: center;
+ gap: var(--spacing-1);
+ color: var(--text-secondary);
+ overflow-wrap: anywhere;
+}
+
+.statusIcon {
+ flex-shrink: 0;
+}
+
+.statusActive .statusIcon {
+ color: var(--status-online);
+}
+
+.statusExpired .statusIcon {
+ color: var(--status-warning);
+}
+
+.trailing {
+ display: flex;
+ align-items: center;
+ justify-content: flex-end;
+}
+
+.menuButton {
+ color: var(--text-secondary);
+}
+
+.menuButtonOpen {
+ background-color: var(--background-modifier-selected);
+ color: var(--text-primary);
+}
+
+.selection {
+ display: inline-flex;
+ flex-shrink: 0;
+ width: 1.25rem;
+ height: 1.25rem;
+ align-items: center;
+ justify-content: center;
+ border: 0.125rem solid var(--background-modifier-accent);
+ border-radius: var(--radius-full);
+ color: var(--text-on-brand-primary);
+}
+
+.selectionChecked {
+ border-color: var(--brand-primary);
+ background-color: var(--brand-primary);
+}
+
+.confirm {
+ display: flex;
+ flex-wrap: wrap;
+ grid-column: 1 / -1;
+ align-items: center;
+ justify-content: space-between;
+ gap: var(--spacing-2) var(--spacing-3);
+ padding-block: 0 var(--spacing-3);
+ padding-inline: var(--spacing-3) var(--spacing-1);
+}
+
+.confirmText {
+ min-width: 0;
+ color: var(--text-primary);
+ font-size: 0.875rem;
+ font-weight: 500;
+ line-height: 1.25rem;
+ overflow-wrap: anywhere;
+}
+
+.confirmActions {
+ display: flex;
+ flex-shrink: 0;
+ gap: var(--spacing-2);
+ margin-inline-start: auto;
+}
+
+.root .list ~ .bulkSignOut {
+ height: auto;
+ padding-block: var(--spacing-2);
+}
+
+.bulkSignOutLabel {
+ min-width: 0;
+ white-space: normal;
+ text-align: center;
+ overflow-wrap: anywhere;
+}
+
+@media (prefers-reduced-motion: reduce) {
+ .row,
+ .avatar {
+ transition: none;
+ }
+}
diff --git a/fluxer_app/src/features/auth/components/accounts/AccountSelector.module.css b/fluxer_app/src/features/auth/components/accounts/AccountSelector.module.css
index 72611cb1a..5660f456b 100644
--- a/fluxer_app/src/features/auth/components/accounts/AccountSelector.module.css
+++ b/fluxer_app/src/features/auth/components/accounts/AccountSelector.module.css
@@ -3,52 +3,29 @@
.container {
display: flex;
flex-direction: column;
- gap: var(--spacing-2);
+ gap: var(--spacing-4);
+ width: 100%;
+}
+
+.header {
+ display: flex;
+ flex-direction: column;
+ gap: var(--spacing-1);
}
.title {
- margin-bottom: 0;
- text-align: center;
+ margin: 0;
+ color: var(--text-primary);
font-size: 1.25rem;
font-weight: 600;
- letter-spacing: 0.025em;
- color: var(--text-primary);
+ line-height: 1.625rem;
+ text-align: center;
}
.description {
margin: 0;
- text-align: center;
- font-size: 0.875rem;
color: var(--text-tertiary);
-}
-
-.error {
- background-color: hsla(0, calc(100% * var(--saturation-factor)), 50%, 0.1);
- border: 0.0625rem solid hsla(0, calc(100% * var(--saturation-factor)), 50%, 0.2);
- border-radius: 0.5rem;
- padding: 0.75rem;
font-size: 0.875rem;
- color: var(--status-danger);
+ line-height: 1.25rem;
text-align: center;
}
-
-.scroller {
- max-height: 17.5rem;
-}
-
-.accountList {
- display: flex;
- flex-direction: column;
- gap: var(--spacing-1);
- padding: var(--spacing-1) 0;
-}
-
-.noAccounts {
- display: flex;
- height: 7.5rem;
- align-items: center;
- justify-content: center;
- color: var(--text-secondary);
- font-size: 0.875rem;
- font-weight: 500;
-}
diff --git a/fluxer_app/src/features/auth/components/accounts/AccountSelector.tsx b/fluxer_app/src/features/auth/components/accounts/AccountSelector.tsx
index c1ab2b71b..7321f25fc 100644
--- a/fluxer_app/src/features/auth/components/accounts/AccountSelector.tsx
+++ b/fluxer_app/src/features/auth/components/accounts/AccountSelector.tsx
@@ -1,15 +1,15 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
-import {AccountRow} from '@app/features/auth/components/accounts/AccountRow';
+import {AccountList} from '@app/features/auth/components/accounts/AccountList';
import styles from '@app/features/auth/components/accounts/AccountSelector.module.css';
-import {getAccountKey} from '@app/features/auth/state/AccountStorageKey';
+import {USE_ANOTHER_ACCOUNT_DESCRIPTOR} from '@app/features/auth/components/accounts/account_switcher_modal/AccountPickerShared';
import type {Account} from '@app/features/platform/state/AuthSession';
+import {remFromPx} from '@app/features/theme/layout/RemFromPx';
import {Button} from '@app/features/ui/button/Button';
-import {Scroller} from '@app/features/ui/components/Scroller';
import * as FormUtils from '@app/lib/forms';
import type {I18n} from '@lingui/core';
import {Trans, useLingui} from '@lingui/react/macro';
-import {PlusIcon} from '@phosphor-icons/react';
+import {UserPlusIcon} from '@phosphor-icons/react';
import {observer} from 'mobx-react-lite';
import type React from 'react';
@@ -20,10 +20,9 @@ interface AccountSelectorProps {
description?: React.ReactNode;
error?: unknown;
disabled?: boolean;
- addButtonLabel?: React.ReactNode;
onSelectAccount: (account: Account) => void;
+ onSignOutAccount?: ((account: Account) => Promise<void>) | null;
onAddAccount?: () => void;
- scrollerKey?: string;
}
function resolveAccountSelectorError(i18n: I18n, error: unknown): string | null {
@@ -39,72 +38,52 @@ function resolveAccountSelectorError(i18n: I18n, error: unknown): string | null
export const AccountSelector = observer(
({
accounts,
- currentAccountKey,
+ currentAccountKey = null,
title,
description,
error,
disabled = false,
- addButtonLabel,
onSelectAccount,
+ onSignOutAccount = null,
onAddAccount,
- scrollerKey,
}: AccountSelectorProps) => {
const {i18n} = useLingui();
- const defaultTitle = <Trans>Choose an account</Trans>;
- const defaultDescription = <Trans>Select an account to continue, or add a different one.</Trans>;
const errorMessage = resolveAccountSelectorError(i18n, error);
return (
- <div className={styles.container} aria-busy={disabled} data-flx="auth.accounts.account-selector.container">
- <h1 className={styles.title} data-flx="auth.accounts.account-selector.title">
- {title ?? defaultTitle}
- </h1>
- <p className={styles.description} data-flx="auth.accounts.account-selector.description">
- {description ?? defaultDescription}
- </p>
- {errorMessage != null && (
- <div className={styles.error} role="alert" data-flx="auth.accounts.account-selector.error">
- {errorMessage}
- </div>
- )}
- {accounts.length === 0 ? (
- <div className={styles.noAccounts} data-flx="auth.accounts.account-selector.no-accounts">
- <Trans>No accounts</Trans>
- </div>
- ) : (
- <Scroller
- className={styles.scroller}
- key={scrollerKey ?? 'account-selector-scroller'}
- data-flx="auth.accounts.account-selector.scroller"
- >
- <div className={styles.accountList} data-flx="auth.accounts.account-selector.account-list">
- {accounts.map((account) => {
- const accountKey = getAccountKey(account);
- return (
- <AccountRow
- key={accountKey}
- account={account}
- isCurrent={accountKey === currentAccountKey}
- isExpired={account.isValid === false}
- onClick={() => onSelectAccount(account)}
- disabled={disabled}
- showCaretIndicator
- data-flx="auth.accounts.account-selector.account-row.select-account"
- />
- );
- })}
- </div>
- </Scroller>
- )}
+ <div className={styles.container} data-flx="auth.accounts.account-selector.container">
+ <div className={styles.header} data-flx="auth.accounts.account-selector.header">
+ <h1 className={styles.title} data-flx="auth.accounts.account-selector.title">
+ {title ?? <Trans>Choose an account</Trans>}
+ </h1>
+ <p className={styles.description} data-flx="auth.accounts.account-selector.description">
+ {description ?? <Trans>Select an account to continue, or add a different one.</Trans>}
+ </p>
+ </div>
+ <AccountList
+ accounts={accounts}
+ currentAccountKey={currentAccountKey}
+ error={errorMessage}
+ disabled={disabled}
+ onSelect={onSelectAccount}
+ onSignOut={onSignOutAccount}
+ data-flx="auth.accounts.account-selector.account-list"
+ />
{onAddAccount && (
<Button
variant="secondary"
- leftIcon={<PlusIcon size={18} weight="bold" data-flx="auth.accounts.account-selector.plus-icon" />}
+ leftIcon={
+ <UserPlusIcon
+ size={remFromPx(18)}
+ weight="bold"
+ data-flx="auth.accounts.account-selector.user-plus-icon"
+ />
+ }
onClick={onAddAccount}
disabled={disabled}
fitContainer
data-flx="auth.accounts.account-selector.button.add-account"
>
- {addButtonLabel ?? <Trans>Add an account</Trans>}
+ {i18n._(USE_ANOTHER_ACCOUNT_DESCRIPTOR)}
</Button>
)}
</div>