Skip to content

Instantly share code, notes, and snippets.

@vishalnarkhede
Created April 7, 2020 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vishalnarkhede/6fd54659cc3bcffef68560caa8d69f16 to your computer and use it in GitHub Desktop.
Save vishalnarkhede/6fd54659cc3bcffef68560caa8d69f16 to your computer and use it in GitHub Desktop.
import React, {useState, useEffect} from 'react';
import {
View,
Text,
SafeAreaView,
TextInput,
StyleSheet,
SectionList,
} from 'react-native';
import {ChannelListItem} from './ChannelListItem';
export const ChannelList = ({client, changeChannel}) => {
const {
activeChannelId,
setActiveChannelId,
unreadChannels,
readChannels,
oneOnOneConversations,
} = useWatchedChannels(client, changeChannel);
const renderChannelRow = (channel, isUnread) => {
const isOneOnOneConversation =
Object.keys(channel.state.members).length === 2;
return (
<ChannelListItem
activeChannelId={activeChannelId}
setActiveChannelId={setActiveChannelId}
changeChannel={changeChannel}
isOneOnOneConversation={isOneOnOneConversation}
isUnread={isUnread}
channel={channel}
client={client}
key={channel.id}
currentUserId={client.user.id}
/>
);
};
return (
<SafeAreaView>
<View style={styles.container}>
<View style={styles.headerContainer}>
<TextInput
style={styles.inputSearchBox}
placeholderTextColor="grey"
placeholder="Jump to"
/>
</View>
<SectionList
style={styles.sectionList}
sections={[
{
title: 'Unread',
id: 'unread',
data: unreadChannels || [],
},
{
title: 'Channels',
data: readChannels || [],
},
{
title: 'Direct Messages',
data: oneOnOneConversations || [],
},
]}
keyExtractor={(item, index) => item.id + index}
renderItem={({item, section}) => {
return renderChannelRow(item, section.id === 'unread');
}}
renderSectionHeader={({section: {title}}) => (
<View style={styles.groupTitleContainer}>
<Text style={styles.groupTitle}>{title}</Text>
</View>
)}
/>
</View>
</SafeAreaView>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment