-
Notifications
You must be signed in to change notification settings - Fork 734
Video 3732 create message components #441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
olipyskoty
merged 15 commits into
feature/conversations
from
VIDEO-3732-create-message-components
Mar 3, 2021
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
57c4808
add MessageList component with MessageInfo and TextMessage components…
olipyskoty a674b22
add MessageList to ChatWindow to display messages
olipyskoty 7d7e505
add hard-coded date for failing circle/ci tests
olipyskoty 6587475
add new isLocalParticipant variable and update MessageInfo/TextMessag…
olipyskoty db2de6d
update timezone to UTC for circleci tests
olipyskoty e4d1882
add whitespace to code for readability and move MessageList to ChatWi…
olipyskoty 5f16f1f
Merge branch 'feature/conversations' into VIDEO-3732-create-message-c…
olipyskoty 9a4f1c4
add UTC timezone for testing
olipyskoty f9b8d39
remove dummy data and utilize useChatContext hook for grabbing messages
olipyskoty 54220a0
fix type error and update snapshot to include new css
olipyskoty eec7da3
update MessageInfo and TextMessage css
olipyskoty 84794ca
remove unnecessary material-ui methods
olipyskoty 669fc77
remove unnecessary div element
olipyskoty a8d9e6f
Merge branch 'VIDEO-3732-create-message-components' of github.com:twi…
olipyskoty fbf3dc9
update snapshot test to account for removed div in TextMessage
olipyskoty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/components/ChatWindow/MessageList/MessageInfo/MessageInfo.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react'; | ||
import { makeStyles, createStyles } from '@material-ui/core/styles'; | ||
|
||
const useStyles = makeStyles(() => | ||
createStyles({ | ||
messageInfoContainer: { | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
alignItems: 'center', | ||
padding: '1.425em 0 0.083em', | ||
fontSize: '12px', | ||
color: '#606B85', | ||
}, | ||
}) | ||
); | ||
|
||
interface MessageInfoProps { | ||
author: string; | ||
dateCreated: string; | ||
isLocalParticipant: boolean; | ||
} | ||
|
||
export default function MessageInfo({ author, dateCreated, isLocalParticipant }: MessageInfoProps) { | ||
const classes = useStyles(); | ||
|
||
return ( | ||
<div className={classes.messageInfoContainer}> | ||
<div>{isLocalParticipant ? `${author} (You)` : author}</div> | ||
<div>{dateCreated}</div> | ||
</div> | ||
); | ||
} |
61 changes: 61 additions & 0 deletions
61
src/components/ChatWindow/MessageList/MessageList.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import MessageList from './MessageList'; | ||
|
||
jest.mock('../../../hooks/useVideoContext/useVideoContext', () => () => ({ | ||
room: { localParticipant: { identity: 'olivia' } }, | ||
})); | ||
|
||
const arbitraryDate = new Date(1614635301000); | ||
|
||
const messages: any = [ | ||
{ | ||
author: 'olivia', | ||
dateCreated: arbitraryDate, | ||
body: 'This is a message', | ||
sid: 'IMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', | ||
type: 'text', | ||
}, | ||
{ | ||
author: 'tim', | ||
dateCreated: arbitraryDate, | ||
body: 'Hi Olivia!', | ||
sid: 'IMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX2', | ||
type: 'text', | ||
}, | ||
{ | ||
author: 'tim', | ||
dateCreated: arbitraryDate, | ||
body: 'That is pretty rad double line message! How did you do that?', | ||
sid: 'IMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX3', | ||
type: 'text', | ||
}, | ||
{ | ||
author: 'tim', | ||
dateCreated: arbitraryDate, | ||
body: '😉', | ||
sid: 'IMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX4', | ||
type: 'text', | ||
}, | ||
{ | ||
author: 'olivia', | ||
dateCreated: new Date(1614635361000), | ||
body: 'Magic', | ||
sid: 'IMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX5', | ||
type: 'text', | ||
}, | ||
{ | ||
author: 'olivia', | ||
dateCreated: new Date(1614635361000), | ||
body: 'lots of magic', | ||
sid: 'IMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX6', | ||
type: 'text', | ||
}, | ||
]; | ||
|
||
describe('the messageList component', () => { | ||
it('should render correctly', () => { | ||
const { container } = render(<MessageList messages={messages} />); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react'; | ||
import TextMessage from './TextMessage/TextMessage'; | ||
import MessageInfo from './MessageInfo/MessageInfo'; | ||
import { Message } from '@twilio/conversations/lib/message'; | ||
import useVideoContext from '../../../hooks/useVideoContext/useVideoContext'; | ||
|
||
interface MessageListProps { | ||
messages: Message[]; | ||
} | ||
|
||
export default function MessageList({ messages }: MessageListProps) { | ||
const { room } = useVideoContext(); | ||
const localParticipant = room!.localParticipant; | ||
|
||
return ( | ||
<div style={{ padding: '0 1.2em' }}> | ||
{messages.map((message, idx) => { | ||
const time = message.dateCreated | ||
.toLocaleTimeString('en-us', { hour: 'numeric', minute: 'numeric' }) | ||
.toLowerCase(); | ||
const isLocalParticipant = localParticipant.identity === message.author; | ||
|
||
return ( | ||
<React.Fragment key={message.sid}> | ||
{messages[idx - 1]?.author !== message.author && ( | ||
<MessageInfo author={message.author} isLocalParticipant={isLocalParticipant} dateCreated={time} /> | ||
)} | ||
{message.type === 'text' && <TextMessage body={message.body} isLocalParticipant={isLocalParticipant} />} | ||
</React.Fragment> | ||
); | ||
})} | ||
</div> | ||
); | ||
} |
40 changes: 40 additions & 0 deletions
40
src/components/ChatWindow/MessageList/TextMessage/TextMessage.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React from 'react'; | ||
import clsx from 'clsx'; | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
|
||
const useStyles = makeStyles({ | ||
messageContainer: { | ||
borderRadius: '16px', | ||
display: 'inline-flex', | ||
alignItems: 'center', | ||
padding: '0.5em 0.8em 0.6em', | ||
margin: '0.3em 0 0', | ||
wordBreak: 'break-word', | ||
backgroundColor: '#E1E3EA', | ||
hyphens: 'auto', | ||
}, | ||
isLocalParticipant: { | ||
backgroundColor: '#CCE4FF', | ||
}, | ||
}); | ||
|
||
interface TextMessageProps { | ||
body: string; | ||
isLocalParticipant: boolean; | ||
} | ||
|
||
export default function TextMessage({ body, isLocalParticipant }: TextMessageProps) { | ||
const classes = useStyles(); | ||
|
||
return ( | ||
<div> | ||
<div | ||
className={clsx(classes.messageContainer, { | ||
[classes.isLocalParticipant]: isLocalParticipant, | ||
})} | ||
> | ||
{body} | ||
</div> | ||
</div> | ||
); | ||
} |
82 changes: 82 additions & 0 deletions
82
src/components/ChatWindow/MessageList/__snapshots__/MessageList.test.tsx.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`the messageList component should render correctly 1`] = ` | ||
<div> | ||
<div | ||
style="padding: 0px 1.2em;" | ||
> | ||
<div | ||
class="makeStyles-messageInfoContainer-1" | ||
> | ||
<div> | ||
olivia (You) | ||
</div> | ||
<div> | ||
9:48 pm | ||
</div> | ||
</div> | ||
<div> | ||
<div | ||
class="makeStyles-messageContainer-2 makeStyles-isLocalParticipant-3" | ||
> | ||
This is a message | ||
</div> | ||
</div> | ||
<div | ||
class="makeStyles-messageInfoContainer-1" | ||
> | ||
<div> | ||
tim | ||
</div> | ||
<div> | ||
9:48 pm | ||
</div> | ||
</div> | ||
<div> | ||
<div | ||
class="makeStyles-messageContainer-2" | ||
> | ||
Hi Olivia! | ||
</div> | ||
</div> | ||
<div> | ||
<div | ||
class="makeStyles-messageContainer-2" | ||
> | ||
That is pretty rad double line message! How did you do that? | ||
</div> | ||
</div> | ||
<div> | ||
<div | ||
class="makeStyles-messageContainer-2" | ||
> | ||
😉 | ||
</div> | ||
</div> | ||
<div | ||
class="makeStyles-messageInfoContainer-1" | ||
> | ||
<div> | ||
olivia (You) | ||
</div> | ||
<div> | ||
9:49 pm | ||
</div> | ||
</div> | ||
<div> | ||
<div | ||
class="makeStyles-messageContainer-2 makeStyles-isLocalParticipant-3" | ||
> | ||
Magic | ||
</div> | ||
</div> | ||
<div> | ||
<div | ||
class="makeStyles-messageContainer-2 makeStyles-isLocalParticipant-3" | ||
> | ||
lots of magic | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
`; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.