import React, { useEffect } from 'react' import { StyleSheet, View, ViewStyle } from 'react-native' import { ConversationsContextProvider, useConversationsContext, } from '../contexts/conversations_context' import { useTheme } from '../hooks' import { ConversationRequestArgs } from '../utils/request/conversation' import { ConversationPreview } from './conversations/conversation_preview' import { Icon, Text } from './display' interface GroupConversationsProps extends Partial { limit?: number onConversationPress: (conversation: any) => void style?: ViewStyle onConversationsLoad?: ({ hasConversations }: { hasConversations: boolean }) => void ListHeaderComponent?: | React.ComponentType | React.ReactElement> ListOverflowFooterComponent?: | React.ComponentType | React.ReactElement> ListEmptyFooterComponent?: | React.ComponentType | React.ReactElement> } /** * GroupConversations is a component that displays a list of conversations * for a specific group. * * Originally designed for use in CCA. */ export const GroupConversations = ({ chat_group_graph_id, ...rest }: GroupConversationsProps) => { return ( ) } const GroupConversationList = ({ limit, onConversationPress, style, onConversationsLoad, ListHeaderComponent, ListOverflowFooterComponent, ListEmptyFooterComponent, }: GroupConversationsProps) => { const styles = useStyles() const { conversations = [], isFetched } = useConversationsContext() useEffect(() => { if (isFetched) { onConversationsLoad?.({ hasConversations: conversations.length > 0 }) } }, [conversations.length, isFetched, onConversationsLoad]) return ( <>{ListHeaderComponent} {isFetched && conversations.length === 0 && ( No conversations found <>{ListEmptyFooterComponent} )} {conversations.slice(0, limit).map(conversation => ( onConversationPress(conversation)} /> ))} {conversations.length > (limit || 0) && <>{ListOverflowFooterComponent}} ) } const useStyles = () => { const { colors } = useTheme() return StyleSheet.create({ constainer: {}, conversation: { borderBottomWidth: 0, }, listItem: { color: colors.fillColorNeutral020 }, listEmpty: { justifyContent: 'center', alignItems: 'center', paddingVertical: 16, gap: 8, }, listEmptyIcon: { color: colors.fillColorNeutral020, }, }) }