fix: create new groups in the address book being viewed

This commit is contained in:
Linus Rath
2026-09-24 19:45:07 +02:00
parent 40ace883b7
commit a3193ebaf7
2 changed files with 11 additions and 4 deletions
@@ -11,7 +11,9 @@ import {
import type { RootStackParamList } from '../../navigation/types';
import type { AddressBook } from '../../api/types';
import type { ContactCategory } from '../../stores/contacts-store';
import { useContactsStore, selectGroupMembers, selectUncategorized } from '../../stores/contacts-store';
import {
useContactsStore, selectCreateTargetBookId, selectGroupMembers, selectUncategorized,
} from '../../stores/contacts-store';
import { getContactDisplayName, getContactKeywords, isGroup } from '../../lib/contact-utils';
import { spacing, radius, typography, componentSizes, type ThemePalette } from '../../theme/tokens';
import { useColors } from '../../theme/colors';
@@ -223,7 +225,11 @@ export default function ContactsSidebarDrawer({ visible, onClose }: Props) {
muted
onPress={() => {
onClose();
navigation.navigate('ContactForm', { asGroup: true });
// Into the address book being viewed, like a new contact.
navigation.navigate('ContactForm', {
asGroup: true,
addressBookId: selectCreateTargetBookId(selectedCategory, addressBooks),
});
}}
/>
)}
+3 -2
View File
@@ -251,7 +251,8 @@ export default function ContactsScreen() {
}
};
// A new contact lands in the address book being viewed, not the default one.
// A new contact or group lands in the address book being viewed, not the
// default one.
const createBookId = React.useMemo(
() => selectCreateTargetBookId(selectedCategory, addressBooks),
[selectedCategory, addressBooks],
@@ -260,7 +261,7 @@ export default function ContactsScreen() {
const openNewMenu = () => {
Alert.alert('Create', undefined, [
{ text: 'New contact', onPress: () => navigation.navigate('ContactForm', { addressBookId: createBookId }) },
{ text: 'New group', onPress: () => navigation.navigate('ContactForm', { asGroup: true }) },
{ text: 'New group', onPress: () => navigation.navigate('ContactForm', { asGroup: true, addressBookId: createBookId }) },
{ text: 'Cancel', style: 'cancel' },
]);
};