- API: comments CRUD, create/edit issue, milestones, collaborators, pull files, raw unified diff (getText), reviews, merge, combined commit status - hooks: comment thread + composer mutations, issue compose mutations, pull files/diff/reviews, create review, merge, combined status - UI: TextArea, ChipSelect, CommentItem, CommentComposer, native DiffView (parseDiff), StatusChecks - screens: IssueCompose (create/edit), PullFiles, PullDiff, PullReview; issue detail gains thread + close/reopen; PR detail gains reviews, merge, files, checks; commit detail shows checks - navigation/types + i18n (en/nl) updated; centralized safeHost helper - tests: diff parser, endpoint body shapes (merge capitalisation), client getText
170 lines
6.3 KiB
TypeScript
170 lines
6.3 KiB
TypeScript
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 { safeHost } from '@/core/api/instance-url';
|
|
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>
|
|
);
|
|
}
|
|
|
|
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 },
|
|
});
|