sorting contacts

This commit is contained in:
Roland Osborne 2022-10-12 09:42:26 -07:00
parent c279408d0a
commit f012b582ed
3 changed files with 20 additions and 4 deletions

View File

@ -66,10 +66,12 @@ export function useCards() {
})
if (state.sorting) {
filtered.sort((a, b) => {
if (a.name === b.name) {
const aName = a?.name?.toLowerCase();
const bName = b?.name?.toLowerCase();
if (aName === bName) {
return 0;
}
if (!a.name || (a.name < b.name)) {
if (!aName || (aName < bName)) {
return -1;
}
return 1;

View File

@ -61,7 +61,7 @@ export function ChannelsBody({ state, actions, openConversation }) {
<Text style={styles.addHeader}>New Topic:</Text>
<View style={styles.inputField}>
<TextInput style={styles.input} value={state.addSubject} onChangeText={actions.setAddSubject}
autoCapitalize="words" placeholder="Subject" />
autoCapitalize="words" placeholder="Subject (optional)" />
</View>
<Text style={styles.label}>Members:</Text>
{ state.connected.length == 0 && (

View File

@ -33,7 +33,21 @@ export function useChannels() {
useEffect(() => {
const contacts = Array.from(card.state.cards.values());
updateState({ connected: contacts.filter(contact => contact.detail.status === 'connected') });
const connected = contacts.filter(contact => {
return contact.detail.status === 'connected'
});
const sorted = connected.sort((a, b) => {
const aName = a?.profile?.name;
const bName = b?.profile?.name;
if (aName === bName) {
return 0;
}
if (!aName || (aName < bName)) {
return -1;
}
return 1;
});
updateState({ connected: sorted });
}, [card]);
useEffect(() => {