Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/components/Home/Chat/Chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import { useSelector } from 'react-redux'
import { selectActiveConversation } from '../../../state/actions/conversations'
import FileDialog from './FileDialog'

export const fileTypes = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to a consts file

image: 'image',
video: 'video',
}

const useStyles = makeStyles({
root: {
flex: 1,
Expand Down Expand Up @@ -48,6 +53,7 @@ const Chat = () => {
id: msgId,
text,
...(file ? { file: 'pending' } : {}),
...(file ? { fileType: Object.keys(fileTypes).find(type => file.type.includes(type)) } : {}),
from: currentUser.uid,
date: new Date(),
})
Expand Down
27 changes: 23 additions & 4 deletions src/components/Home/Chat/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Drawer from '@material-ui/core/Drawer'
import Fab from '@material-ui/core/Fab'
import CloseIcon from '@material-ui/icons/Close'
import EmojiText from './EmujiText'
import { fileTypes } from './Chat'

const useStyles = makeStyles({
root: {
Expand Down Expand Up @@ -128,6 +129,10 @@ const useStyles = makeStyles({
flex: 'initial',
flexDirection: 'row',
},
video: {
width: '100%',
height: ' auto',
},
})

const Messages = ({ isDragOn }, listRef) => {
Expand Down Expand Up @@ -241,17 +246,31 @@ const Messages = ({ isDragOn }, listRef) => {
{
messages.map((message) => (
<React.Fragment key={message.id}>
<ListItem className={message.from === currentUserId ? classes.listItemSelf : classes.listItem}>
<ListItem
className={message.from === currentUserId ? classes.listItemSelf : classes.listItem}>
<ListItemAvatar className={classes.avatar}>
<Avatar src={users[message.from].photoURL} />
</ListItemAvatar>
{
message.file && (
message.file !== 'pending' ? (
<div className={classes.imgContainer}>
<Button onClick={() => setZoomImg(message.file)}>
<img className={classes.img} src={message.file} />
</Button>
{
message.fileType && (
message.fileType === fileTypes.image ? (
<Button
onClick={() => setZoomImg(message.file)}>
<img className={classes.img}
src={message.file} />
</Button>
) : message.fileType === fileTypes.video ? (
<video className={classes.video} controls>
<source src={message.file}
type="video/mp4" />
</video>
) : <h3>none</h3>
)
}
</div>
) : <CircularProgress color="secondary" />
)
Expand Down