/* * Copyright (C) 2026 Fluxer Contributors * * This file is part of Fluxer. * * Fluxer is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Fluxer is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with Fluxer. If not, see . */ import {Trans, useLingui} from '@lingui/react/macro'; import {CaretRightIcon, CheckIcon, DotsThreeIcon, GlobeIcon} from '@phosphor-icons/react'; import clsx from 'clsx'; import {observer} from 'mobx-react-lite'; import React from 'react'; import FocusRing from '~/components/uikit/FocusRing/FocusRing'; import {MockAvatar} from '~/components/uikit/MockAvatar'; import {Tooltip} from '~/components/uikit/Tooltip'; import type {AccountSummary} from '~/stores/AccountManager'; import {getAccountAvatarUrl} from './AccountListItem'; import styles from './AccountRow.module.css'; const STANDARD_INSTANCES = new Set(['web.fluxer.app', 'web.canary.fluxer.app']); function getInstanceHost(account: AccountSummary): string | null { const endpoint = account.instance?.apiEndpoint; if (!endpoint) { return null; } try { return new URL(endpoint).hostname; } catch (error) { console.error('Failed to parse instance host:', error); return null; } } function getInstanceEndpoint(account: AccountSummary): string | null { return account.instance?.apiEndpoint ?? null; } type AccountRowVariant = 'default' | 'manage' | 'compact'; interface AccountRowProps { account: AccountSummary; variant?: AccountRowVariant; isCurrent?: boolean; isExpired?: boolean; showInstance?: boolean; onMenuClick?: (event: React.MouseEvent) => void; onClick?: () => void; showCaretIndicator?: boolean; className?: string; meta?: React.ReactNode; } export const AccountRow = observer( ({ account, variant = 'default', isCurrent = false, isExpired = false, showInstance = false, onMenuClick, onClick, showCaretIndicator = false, className, meta, }: AccountRowProps) => { const {t} = useLingui(); const avatarUrl = getAccountAvatarUrl(account); const displayName = account.userData?.username ?? t`Unknown user`; const discriminator = account.userData?.discriminator ?? '0000'; const instanceHost = showInstance ? getInstanceHost(account) : null; const instanceEndpoint = showInstance ? getInstanceEndpoint(account) : null; const shouldShowInstance = typeof instanceHost === 'string' && !STANDARD_INSTANCES.has(instanceHost); const handleMenuClick = React.useCallback( (event: React.MouseEvent) => { event.stopPropagation(); event.preventDefault(); onMenuClick?.(event); }, [onMenuClick], ); const avatarSize = variant === 'compact' ? 32 : 40; const variantClassName = variant === 'manage' ? styles.manage : variant === 'compact' ? styles.compact : undefined; const isClickable = typeof onClick === 'function'; const MainButtonComponent = isClickable ? 'button' : 'div'; return (
{variant === 'compact' ? (
{displayName} #{discriminator} {shouldShowInstance && instanceEndpoint ? ( ) : null}
) : ( <>
{variant === 'manage' ? ( {displayName} #{discriminator} ) : ( {displayName} )} {shouldShowInstance && instanceEndpoint ? ( ) : null}
{variant !== 'manage' ? ( {displayName} #{discriminator} ) : null} {variant === 'manage' && isCurrent ? ( Active account ) : null} {meta && {meta}} {isExpired && {t`Expired`}} )}
{isCurrent && variant !== 'manage' ? (
) : null} {showCaretIndicator ? (
) : null} {onMenuClick && variant !== 'compact' && !showCaretIndicator ? ( ) : null}
); }, );