-
Notifications
You must be signed in to change notification settings - Fork 736
Conversations UI - create chat window #421
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 25 commits into
feature/conversations
from
VIDEO-3731-conversations-ui-create-chat-window
Feb 19, 2021
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
312623d
Add chat svg icon from designs
olipyskoty 1efbdcb
add chat button to menu bar
olipyskoty 7f6e9a8
add chat window to room and refactor materialui code to make use of m…
olipyskoty 324106a
add chat provider context to index.js
olipyskoty fdcf1e9
add chat window styles to theme
olipyskoty 26835c9
add chat button
olipyskoty f8632cf
add chat window component
olipyskoty 8a4e3f7
add chatProvider and useChatContext hook
olipyskoty 2c22fa5
add button for closing chat window
olipyskoty cb06376
add component for chat window header
olipyskoty b480fd7
add chat window header to chat window component
olipyskoty 4589592
correct formatting
olipyskoty 6a23206
change close chat window button to div to remove hover state
olipyskoty 4f883d9
correct styling for chat header
olipyskoty a645876
move flip camera button back to MenuBar for time being
olipyskoty f6f2b5e
remove FlipCameraButton from menubar
olipyskoty 5d2adba
add unit tests for chat window and chat window button
olipyskoty 178d409
remove chatWindowHeaderHeight from theme
olipyskoty 87b8189
delete CloseChat button folder to move code into ChatWindowHeader com…
olipyskoty e380e46
rename icon to CloseChat icon
olipyskoty 614f563
make ToggleChatButton tests more specific
olipyskoty 4f5617a
fix typo to usechatContext
olipyskoty b696528
remove snapshot tests from Room tests
olipyskoty 1f844db
move ChatWindowHeader component into ChatWindow component directory
olipyskoty d1773d7
fix hover styling/css to match other menu buttons
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
27 changes: 27 additions & 0 deletions
27
src/components/Buttons/ToggleChatButton/ToggleChatButton.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,27 @@ | ||
| import React from 'react'; | ||
| import { shallow } from 'enzyme'; | ||
| import { Button } from '@material-ui/core'; | ||
|
|
||
| import ChatIcon from '../../../icons/ChatIcon'; | ||
| import ToggleChatButton from './ToggleChatButton'; | ||
| import useChatContext from '../../../hooks/useChatContext/useChatContext'; | ||
|
|
||
| jest.mock('../../../hooks/useChatContext/useChatContext'); | ||
| const mockUseChatContext = useChatContext as jest.Mock<any>; | ||
|
|
||
| const mockToggleChatWindow = jest.fn(); | ||
| mockUseChatContext.mockImplementation(() => ({ setIsChatWindowOpen: mockToggleChatWindow, isChatWindowOpen: false })); | ||
|
|
||
| describe('the ToggleChatButton component', () => { | ||
| it('should render correctly when chat is enabled', () => { | ||
| const wrapper = shallow(<ToggleChatButton />); | ||
| expect(wrapper.prop('startIcon')).toEqual(<ChatIcon />); | ||
| expect(wrapper.text()).toBe('Chat'); | ||
| }); | ||
|
|
||
| it('should call the correct toggle function when clicked', () => { | ||
| const wrapper = shallow(<ToggleChatButton />); | ||
| wrapper.find(Button).simulate('click'); | ||
| expect(mockToggleChatWindow).toHaveBeenCalledWith(true); | ||
| }); | ||
| }); |
18 changes: 18 additions & 0 deletions
18
src/components/Buttons/ToggleChatButton/ToggleChatButton.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,18 @@ | ||
| import React from 'react'; | ||
| import Button from '@material-ui/core/Button'; | ||
| import ChatIcon from '../../../icons/ChatIcon'; | ||
| import useChatContext from '../../../hooks/useChatContext/useChatContext'; | ||
|
|
||
| export default function ToggleVideoButton() { | ||
| const { isChatWindowOpen, setIsChatWindowOpen } = useChatContext(); | ||
|
|
||
| const toggleChatWindow = () => { | ||
| setIsChatWindowOpen(!isChatWindowOpen); | ||
| }; | ||
|
|
||
| return ( | ||
| <Button onClick={toggleChatWindow} startIcon={<ChatIcon />}> | ||
| Chat | ||
| </Button> | ||
| ); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import React, { createContext, useState } from 'react'; | ||
|
|
||
| type ChatContextType = { isChatWindowOpen: boolean; setIsChatWindowOpen: (isChatWindowOpen: boolean) => void }; | ||
|
|
||
| export const ChatContext = createContext<ChatContextType>(null!); | ||
|
|
||
| type ChatProviderProps = { | ||
| children: React.ReactNode; | ||
| }; | ||
|
|
||
| export function ChatProvider({ children }: ChatProviderProps) { | ||
| const [isChatWindowOpen, setIsChatWindowOpen] = useState(false); | ||
|
|
||
| return <ChatContext.Provider value={{ isChatWindowOpen, setIsChatWindowOpen }}>{children}</ChatContext.Provider>; | ||
| } |
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,35 @@ | ||
| import React from 'react'; | ||
| import { makeStyles, createStyles, Theme } from '@material-ui/core/styles'; | ||
| import ChatWindowHeader from './ChatWindowHeader/ChatWindowHeader'; | ||
| import useChatContext from '../../hooks/useChatContext/useChatContext'; | ||
|
|
||
| const useStyles = makeStyles((theme: Theme) => | ||
| createStyles({ | ||
| container: { | ||
| overflowY: 'auto', | ||
| background: '#FFFFFF', | ||
| zIndex: 100, | ||
| [theme.breakpoints.down('sm')]: { | ||
| position: 'fixed', | ||
| top: 0, | ||
| left: 0, | ||
| bottom: 0, | ||
| right: 0, | ||
| }, | ||
| }, | ||
| }) | ||
| ); | ||
|
|
||
| export default function ChatWindow() { | ||
| const classes = useStyles(); | ||
| const { isChatWindowOpen } = useChatContext(); | ||
|
|
||
| //if chat window is not open, don't render this component | ||
| if (!isChatWindowOpen) return null; | ||
|
|
||
| return ( | ||
| <aside className={classes.container}> | ||
| <ChatWindowHeader /> | ||
| </aside> | ||
| ); | ||
| } |
24 changes: 24 additions & 0 deletions
24
src/components/ChatWindow/ChatWindowHeader/ChatWindowHeader.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,24 @@ | ||
| import React from 'react'; | ||
| import { shallow } from 'enzyme'; | ||
|
|
||
| import CloseIcon from '../../../icons/CloseIcon'; | ||
| import ChatWindowHeader from './ChatWindowHeader'; | ||
| import useChatContext from '../../../hooks/useChatContext/useChatContext'; | ||
|
|
||
| jest.mock('../../../hooks/useChatContext/useChatContext'); | ||
|
|
||
| const mockUseChatContext = useChatContext as jest.Mock<any>; | ||
|
|
||
| const mockToggleChatWindow = jest.fn(); | ||
| mockUseChatContext.mockImplementation(() => ({ setIsChatWindowOpen: mockToggleChatWindow })); | ||
|
|
||
| describe('the CloseChatWindowHeader component', () => { | ||
| it('should close the chat window when "X" is clicked on', () => { | ||
| const wrapper = shallow(<ChatWindowHeader />); | ||
| wrapper | ||
| .find(CloseIcon) | ||
| .parent() | ||
| .simulate('click'); | ||
| expect(mockToggleChatWindow).toHaveBeenCalledWith(false); | ||
| }); | ||
| }); |
40 changes: 40 additions & 0 deletions
40
src/components/ChatWindow/ChatWindowHeader/ChatWindowHeader.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 { makeStyles, createStyles } from '@material-ui/core/styles'; | ||
| import CloseIcon from '../../../icons/CloseIcon'; | ||
|
|
||
| import useChatContext from '../../../hooks/useChatContext/useChatContext'; | ||
|
|
||
| const useStyles = makeStyles(() => | ||
| createStyles({ | ||
| container: { | ||
| height: '56px', | ||
| background: '#F4F4F6', | ||
| boxShadow: 'inset 0 -0.1em 0 #E4E7E9', | ||
| display: 'flex', | ||
| justifyContent: 'space-between', | ||
| alignItems: 'center', | ||
| padding: '0 1em', | ||
| }, | ||
| text: { | ||
| fontWeight: 'bold', | ||
| }, | ||
| closeChatWindow: { | ||
| cursor: 'pointer', | ||
| display: 'flex', | ||
| }, | ||
| }) | ||
| ); | ||
|
|
||
| export default function ChatWindowHeader() { | ||
| const classes = useStyles(); | ||
| const { setIsChatWindowOpen } = useChatContext(); | ||
|
|
||
| return ( | ||
| <div className={classes.container}> | ||
| <div className={classes.text}>Chat</div> | ||
| <div className={classes.closeChatWindow} onClick={() => setIsChatWindowOpen(false)}> | ||
| <CloseIcon /> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import React from 'react'; | ||
| import { shallow } from 'enzyme'; | ||
|
|
||
| import Room from './Room'; | ||
| import useChatContext from '../../hooks/useChatContext/useChatContext'; | ||
| jest.mock('../../hooks/useChatContext/useChatContext'); | ||
|
|
||
| const mockUseChatContext = useChatContext as jest.Mock<any>; | ||
|
|
||
| const mockToggleChatWindow = jest.fn(); | ||
| mockUseChatContext.mockImplementation(() => ({ setIsChatWindowOpen: mockToggleChatWindow })); | ||
|
|
||
| describe('the Room component', () => { | ||
| it('should render correctly with chat window closed', () => { | ||
| const wrapper = shallow(<Room />); | ||
| expect(wrapper.prop('className')).not.toContain('chatWindowOpen'); | ||
| }); | ||
|
|
||
| it('should render correctly with chat window open', () => { | ||
| mockUseChatContext.mockImplementationOnce(() => ({ isChatWindowOpen: true })); | ||
| const wrapper = shallow(<Room />); | ||
| expect(wrapper.prop('className')).toContain('chatWindowOpen'); | ||
| }); | ||
| }); | ||
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 |
|---|---|---|
| @@ -1,31 +1,39 @@ | ||
| import React from 'react'; | ||
| import clsx from 'clsx'; | ||
| import { makeStyles, Theme } from '@material-ui/core'; | ||
| import ChatWindow from '../ChatWindow/ChatWindow'; | ||
| import ParticipantList from '../ParticipantList/ParticipantList'; | ||
| import { styled } from '@material-ui/core/styles'; | ||
| import MainParticipant from '../MainParticipant/MainParticipant'; | ||
| import useChatContext from '../../hooks/useChatContext/useChatContext'; | ||
|
|
||
| const Container = styled('div')(({ theme }) => { | ||
| const useStyles = makeStyles((theme: Theme) => { | ||
| const totalMobileSidebarHeight = `${theme.sidebarMobileHeight + | ||
| theme.sidebarMobilePadding * 2 + | ||
| theme.participantBorderWidth}px`; | ||
|
|
||
| return { | ||
| position: 'relative', | ||
| height: '100%', | ||
| display: 'grid', | ||
| gridTemplateColumns: `1fr ${theme.sidebarWidth}px`, | ||
| gridTemplateRows: '100%', | ||
| [theme.breakpoints.down('sm')]: { | ||
| gridTemplateColumns: `100%`, | ||
| gridTemplateRows: `calc(100% - ${totalMobileSidebarHeight}) ${totalMobileSidebarHeight}`, | ||
| container: { | ||
| position: 'relative', | ||
| height: '100%', | ||
| display: 'grid', | ||
| gridTemplateColumns: `1fr ${theme.sidebarWidth}px`, | ||
| gridTemplateRows: '100%', | ||
| [theme.breakpoints.down('sm')]: { | ||
| gridTemplateColumns: `100%`, | ||
| gridTemplateRows: `calc(100% - ${totalMobileSidebarHeight}) ${totalMobileSidebarHeight}`, | ||
| }, | ||
| }, | ||
| chatWindowOpen: { gridTemplateColumns: `1fr ${theme.sidebarWidth}px ${theme.chatWindowWidth}px` }, | ||
| }; | ||
| }); | ||
|
|
||
| export default function Room() { | ||
| const classes = useStyles(); | ||
| const { isChatWindowOpen } = useChatContext(); | ||
| return ( | ||
| <Container> | ||
| <div className={clsx(classes.container, { [classes.chatWindowOpen]: isChatWindowOpen })}> | ||
| <MainParticipant /> | ||
| <ParticipantList /> | ||
| </Container> | ||
| <ChatWindow /> | ||
| </div> | ||
| ); | ||
| } |
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,9 @@ | ||
| import useChatContext from './useChatContext'; | ||
| import { renderHook } from '@testing-library/react-hooks'; | ||
|
|
||
| describe('the useChatContext hook', () => { | ||
| it('should throw an error if used outside of the ChatProvider', () => { | ||
| const { result } = renderHook(useChatContext); | ||
| expect(result.error.message).toBe('useChatContext must be used within a ChatProvider'); | ||
| }); | ||
| }); |
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,10 @@ | ||
| import { useContext } from 'react'; | ||
| import { ChatContext } from '../../components/ChatProvider'; | ||
|
|
||
| export default function useChatContext() { | ||
| const context = useContext(ChatContext); | ||
| if (!context) { | ||
| throw new Error('useChatContext must be used within a ChatProvider'); | ||
| } | ||
| return context; | ||
| } |
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,14 @@ | ||
| import React from 'react'; | ||
|
|
||
| export default function ChatIcon() { | ||
| return ( | ||
| <svg width="19" height="17" viewBox="0 0 19 17" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
| <path | ||
| fillRule="evenodd" | ||
| clipRule="evenodd" | ||
| d="M0 1C0 0.723858 0.223858 0.5 0.5 0.5H18.5C18.7761 0.5 19 0.723858 19 1V13C19 13.2761 18.7761 13.5 18.5 13.5H9.3096L6.32421 16.361C6.1796 16.4996 5.96624 16.5385 5.78202 16.4599C5.59779 16.3813 5.47826 16.2003 5.47826 16V13.5H0.5C0.223858 13.5 0 13.2761 0 13V1ZM1 1.5V12.5H5.97826C6.2544 12.5 6.47826 12.7239 6.47826 13V14.8283L8.76274 12.639C8.85583 12.5498 8.97977 12.5 9.1087 12.5H18V1.5H1Z" | ||
| fill="#707578" | ||
| /> | ||
| </svg> | ||
| ); | ||
| } |
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,20 @@ | ||
| import React from 'react'; | ||
|
|
||
| export default function CloseIcon() { | ||
| return ( | ||
| <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
| <path | ||
| fillRule="evenodd" | ||
| clipRule="evenodd" | ||
| d="M2.64645 2.64645C2.84171 2.45118 3.15829 2.45118 3.35355 2.64645L21.3536 20.6464C21.5488 20.8417 21.5488 21.1583 21.3536 21.3536C21.1583 21.5488 20.8417 21.5488 20.6464 21.3536L2.64645 3.35355C2.45118 3.15829 2.45118 2.84171 2.64645 2.64645Z" | ||
| fill="#707578" | ||
| /> | ||
| <path | ||
| fillRule="evenodd" | ||
| clipRule="evenodd" | ||
| d="M21.3536 2.64645C21.5488 2.84171 21.5488 3.15829 21.3536 3.35355L3.35355 21.3536C3.15829 21.5488 2.84171 21.5488 2.64645 21.3536C2.45118 21.1583 2.45118 20.8417 2.64645 20.6464L20.6464 2.64645C20.8417 2.45118 21.1583 2.45118 21.3536 2.64645Z" | ||
| fill="#707578" | ||
| /> | ||
| </svg> | ||
| ); | ||
| } |
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
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.
I really like using snapshot tests - but I'm not sure if they are really needed here. I think that snapshot tests are great for testing lots of different things at once, but here we are testing only one thing. So I think that the
expect(wrapper.prop('className')).toContain('chatWindowOpen');test that you already have is sufficient. Just need to addexpect(wrapper.prop('className')).not.toContain('chatWindowOpen');to the first test.