diff --git a/src/features/accounts/screens/accounts-screen.tsx b/src/features/accounts/screens/accounts-screen.tsx new file mode 100644 index 0000000..16cf906 --- /dev/null +++ b/src/features/accounts/screens/accounts-screen.tsx @@ -0,0 +1,176 @@ +import { Alert, StyleSheet, View } from 'react-native'; +import { useTranslation } from 'react-i18next'; +import { useNavigation } from '@react-navigation/native'; +import type { NativeStackNavigationProp } from '@react-navigation/native-stack'; + +import { Screen } from '@/components/layout/screen'; +import { AppText } from '@/components/ui/app-text'; +import { Avatar } from '@/components/ui/avatar'; +import { Badge } from '@/components/ui/badge'; +import { Button } from '@/components/ui/button'; +import { Card } from '@/components/ui/card'; +import { IconButton } from '@/components/ui/icon-button'; +import { ListItem } from '@/components/ui/list-item'; +import { EmptyState } from '@/components/ui/state-views'; +import type { AccountRecord, InstanceRecord } from '@/core/accounts/types'; +import { useAccountsStore } from '@/core/accounts/accounts-store'; +import { useAccountActions } from '@/features/accounts/use-account-actions'; +import { spacing } from '@/theme/tokens'; +import type { AccountsStackParamList } from '@/navigation/types'; +import type { ScreenProps } from '@/navigation/typing'; + +type Props = ScreenProps; + +/** Manage instances and accounts: switch, add and remove. */ +export function AccountsScreen(_props: Props) { + const navigation = useNavigation>(); + const { t } = useTranslation(); + const instances = useAccountsStore((s) => s.instances); + const accounts = useAccountsStore((s) => s.accounts); + const activeAccountId = useAccountsStore((s) => s.activeAccountId); + const tokens = useAccountsStore((s) => s.tokens); + const { removeAccount, removeInstance, switchAccount } = useAccountActions(); + + const confirmRemoveAccount = (account: AccountRecord) => { + Alert.alert( + t('accounts.removeAccountTitle'), + t('accounts.removeAccountBody', { name: account.login }), + [ + { text: t('common.cancel'), style: 'cancel' }, + { + text: t('common.remove'), + style: 'destructive', + onPress: () => { + void removeAccount(account.id).then(() => Alert.alert(t('accounts.removeDone'))); + }, + }, + ], + ); + }; + + const confirmRemoveInstance = (instance: InstanceRecord) => { + Alert.alert( + t('accounts.removeInstanceTitle'), + t('accounts.removeInstanceBody', { instance: instance.label }), + [ + { text: t('common.cancel'), style: 'cancel' }, + { + text: t('common.disconnect'), + style: 'destructive', + onPress: () => { + void removeInstance(instance.id).then(() => Alert.alert(t('accounts.disconnectDone'))); + }, + }, + ], + ); + }; + + if (instances.length === 0) { + return ( + + navigation.navigate('AddAccount')} + /> + + ); + } + + return ( + +