blob: 175f19bc846dafdd12395d3d61db87b7f8622d62 [file] [log] [blame]
Larbi Gharibe9af9732021-03-31 15:08:01 +01001import Message from './Message'
Adrien Béraud4e287b92021-04-24 16:15:56 -04002import React, { useEffect } from 'react'
Adrien Béraud150b4782021-04-21 19:40:59 -04003import { Box, Divider, Typography } from '@material-ui/core'
4import ConversationAvatar from './ConversationAvatar'
Larbi Gharibe9af9732021-03-31 15:08:01 +01005
Adrien Béraudaf09a462021-04-15 18:02:29 -04006export default function MessageList(props) {
Adrien Béraud150b4782021-04-21 19:40:59 -04007 const displayName = props.conversation.getDisplayName()
Adrien Béraud4e287b92021-04-24 16:15:56 -04008 const messages = props.conversation.getMessages()
Adrien Béraud4e287b92021-04-24 16:15:56 -04009
10 useEffect(() => {
Adrien Béraudabba2e52021-04-24 21:39:56 -040011 if (!props.loading)
12 props.loadMore()
Adrien Béraud4e287b92021-04-24 16:15:56 -040013 }, [props.conversation.getId()])
14
Adrien Béraud150b4782021-04-21 19:40:59 -040015 return (
Adrien Béraud4e287b92021-04-24 16:15:56 -040016 <React.Fragment>
17 <Box className="conversation-header">
Adrien Béraud0561d3c2021-05-02 11:23:54 -040018 <Box style={{ margin: 16, flexShrink: 0 }}>
Adrien Béraud150b4782021-04-21 19:40:59 -040019 <ConversationAvatar displayName={props.conversation.getDisplayNameNoFallback()} />
20 </Box>
Adrien Béraud0561d3c2021-05-02 11:23:54 -040021 <Box style={{ flex: "1 1 auto", overflow: 'hidden' }}>
22 <Typography className="title" variant="h6">{displayName}</Typography>
23 <Typography className="subtitle" variant="subtitle1" >{props.conversation.getId()}</Typography>
Adrien Béraud150b4782021-04-21 19:40:59 -040024 </Box>
Adrien Béraud4e287b92021-04-24 16:15:56 -040025 <Divider orientation="horizontal" />
Adrien Béraud150b4782021-04-21 19:40:59 -040026 </Box>
Adrien Béraud4e287b92021-04-24 16:15:56 -040027 <div className="message-list">
Adrien Béraudabba2e52021-04-24 21:39:56 -040028 {messages.map((message) => <Message key={message.id} message={message} />)}
29 <div style={{ border: "1px solid transparent" }}/>
Adrien Béraud4e287b92021-04-24 16:15:56 -040030 </div>
31 </React.Fragment>
Adrien Béraud150b4782021-04-21 19:40:59 -040032 )
Adrien Béraudaf09a462021-04-15 18:02:29 -040033}