index.tsx
1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* Inbox tab main chat container component
*/
import React, { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { map } from 'lodash/fp';
import {didSetActiveTab} from '../../../tabs/actions';
import {COMMUNICATIONS} from '../../../tabs/constants';
import {LoadingRipple} from '../../../../utilities/components/LoadingRipple';
import PageLayout from '../../../components/PageLayout';
import {getCurrentThreadId} from '../../../selectors/thread';
import {fetchThreadContents} from '../../middlewares/thread-contents';
import {getIsFetchingThreadContents, getThreadContentsCollection} from '../../selectors';
import ChatMessage from '../ChatMessage';
import ThreadContent, {ThreadContentTypes} from '../../../../models/ThreadContent';
import ChatInput from '../ChatInput';
const Thread = () => {
const dispatch = useDispatch();
useEffect(() => {
dispatch(didSetActiveTab(COMMUNICATIONS));
}, []);
const threadId = useSelector(getCurrentThreadId);
const isFetching = useSelector(getIsFetchingThreadContents);
const collection = useSelector(getThreadContentsCollection);
useEffect(() => {
dispatch(fetchThreadContents(threadId));
}, [threadId]);
return (
<PageLayout>
<div id='chat-container' style={{overflowY: 'hidden'}}>
<div className={`chat-body-container`}>
{isFetching && <LoadingRipple isLoading />}
{!isFetching &&
<div className='chat-body'>
{map(
(each: ThreadContent) => (
ThreadContentTypes.MESSAGE === each.type ? <ChatMessage
threadContent={each}
key={`thread_content_${each.id}`}
/> : null
), collection
)}
</div>
}
</div>
<ChatInput />
</div>
</PageLayout>
);
};
export default Thread;