import React from 'react'; import { ChatFeedProps } from './props'; import { styles } from './styles'; import { ChatHeader } from './ChatHeader'; import { MessageList } from './MessageList'; import { MessageForm } from './MessageForm'; import { WelcomeGif } from './WelcomeGif'; import { getDateTime, formatDateTime } from '../../util/dateTime'; import { Spinner } from '../../Components/Spinner'; import { ChatObject } from '../../../interfaces'; const getDescription = ( chat: ChatObject | undefined, timezoneOffset: number = 0 ) => { if (!chat) { return '⬅️ ⬅️ ⬅️'; } else if ( chat.last_message.created && chat.last_message.created.length > 0 ) { const dateTime = getDateTime(chat.last_message.created, timezoneOffset); const formattedDateTime = formatDateTime(dateTime); return `Active ${formattedDateTime}`; } else { return 'Say hello!'; } }; export const ChatFeed: React.FC = (props: ChatFeedProps) => { const { chat } = props; const otherPerson = chat && chat.people.find((person) => person.person.username !== props.username); const title = props.isLoading ? ( ) : !chat ? ( 'Create a chat!' ) : chat.is_direct_chat && otherPerson ? ( otherPerson.person.username ) : ( chat.title ); if (props.renderChatFeed) { return <>{props.renderChatFeed(props)}; } return (
{props.messages.length === 0 && !props.isLoading && ( )}
); };