feat(features): auth, accounts, home, repositories, issues, notifications
- auth: welcome/connect screens, shared connect form, connect flow, app lock - accounts: session hook, actions, switcher + add-account screens - home: dashboard (identity, shortcuts, recent repos, assigned issues, review requests, activity, unread badge) - repositories/repository: list+search, overview, files, file viewer, commits, commit detail, branches, tags, repo issues/pulls, issue/pull detail - issues/notifications: cross-repo search, query hooks, inbox with read marking and lifecycle-aware polling - settings: theme/language/biometrics/poll interval/cache/about
This commit is contained in:
1 parent
ad81db07b3
commit
0a889ebfed
36 files changed
+4186
No files matched your search
@@ -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<AccountsStackParamList, 'Accounts'>;
|
||||
|
||||
/** Manage instances and accounts: switch, add and remove. */
|
||||
export function AccountsScreen(_props: Props) {
|
||||
const navigation = useNavigation<NativeStackNavigationProp<AccountsStackParamList>>();
|
||||
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 (
|
||||
<Screen padded>
|
||||
<EmptyState
|
||||
icon="people"
|
||||
title={t('accounts.noAccounts')}
|
||||
body={t('accounts.addFirstAccount')}
|
||||
actionLabel={t('accounts.addAccount')}
|
||||
onAction={() => navigation.navigate('AddAccount')}
|
||||
/>
|
||||
</Screen>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Screen scroll padded>
|
||||
<Button
|
||||
label={t('accounts.addAccount')}
|
||||
iconLeft="plus"
|
||||
variant="secondary"
|
||||
fullWidth
|
||||
onPress={() => navigation.navigate('AddAccount')}
|
||||
/>
|
||||
|
||||
{instances.map((instance) => {
|
||||
const instanceAccounts = accounts.filter((account) => account.instanceId === instance.id);
|
||||
return (
|
||||
<View key={instance.id} style={styles.group}>
|
||||
<View style={styles.groupHeader}>
|
||||
<AppText variant="subheading" numberOfLines={1} style={styles.groupTitle}>
|
||||
{instance.label}
|
||||
</AppText>
|
||||
{instance.version ? (
|
||||
<Badge tone="neutral">{t('accounts.version', { version: instance.version })}</Badge>
|
||||
) : null}
|
||||
</View>
|
||||
|
||||
<Card padded={false} variant="flat">
|
||||
{instanceAccounts.map((account, index) => {
|
||||
const active = account.id === activeAccountId;
|
||||
return (
|
||||
<ListItem
|
||||
key={account.id}
|
||||
leading={
|
||||
<Avatar
|
||||
url={account.avatarUrl ?? null}
|
||||
name={account.fullName ?? account.login}
|
||||
size={36}
|
||||
token={tokens[account.id] ?? null}
|
||||
host={safeHost(instance.baseUrl)}
|
||||
/>
|
||||
}
|
||||
title={account.fullName ?? account.login}
|
||||
subtitle={t('accounts.signedInAs', { name: account.login })}
|
||||
trailing={
|
||||
<View style={styles.trailing}>
|
||||
{active ? <Badge tone="primary">{t('accounts.active')}</Badge> : null}
|
||||
<IconButton
|
||||
name="trash"
|
||||
size={18}
|
||||
muted
|
||||
accessibilityLabel={t('accounts.removeAccountTitle')}
|
||||
onPress={() => confirmRemoveAccount(account)}
|
||||
/>
|
||||
</View>
|
||||
}
|
||||
onPress={() => {
|
||||
if (!active) void switchAccount(account.id);
|
||||
}}
|
||||
accessibilityLabel={t('accounts.switchTo', { name: account.login })}
|
||||
divider={index < instanceAccounts.length - 1}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
<ListItem
|
||||
leadingIcon="close"
|
||||
title={t('common.disconnect')}
|
||||
onPress={() => confirmRemoveInstance(instance)}
|
||||
divider={false}
|
||||
style={styles.disconnect}
|
||||
/>
|
||||
</Card>
|
||||
</View>
|
||||
);
|
||||
})}
|
||||
|
||||
<AppText variant="caption" tone="tertiary" style={styles.footer}>
|
||||
{t('common.unofficialNotice')}
|
||||
</AppText>
|
||||
</Screen>
|
||||
);
|
||||
}
|
||||
|
||||
function safeHost(baseUrl: string): string | null {
|
||||
try {
|
||||
return new URL(baseUrl).host;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
group: { gap: spacing.sm },
|
||||
groupHeader: { flexDirection: 'row', alignItems: 'center', gap: spacing.sm },
|
||||
groupTitle: { flexShrink: 1 },
|
||||
trailing: { flexDirection: 'row', alignItems: 'center', gap: spacing.xs },
|
||||
disconnect: { opacity: 0.9 },
|
||||
footer: { textAlign: 'center', paddingVertical: spacing.lg },
|
||||
});
|
||||
Reference in new issue
Block a user