-
Notifications
You must be signed in to change notification settings - Fork 2
BA-2366: improve messages components #242
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
Changes from all commits
22275f0
181eb44
a63d3f5
ae04873
2ae3f74
4c07d51
451e908
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { ComponentType } from 'react' | ||
|
|
||
| import { Box, BoxProps } from '@mui/material' | ||
| import { styled } from '@mui/material/styles' | ||
|
|
||
| export const MainContainer = styled(Box)(() => ({ | ||
| display: 'grid', | ||
| gridTemplateRows: 'min-content min-content auto', | ||
| height: '100%', | ||
| width: '100%', | ||
| })) | ||
|
|
||
| export const Header: ComponentType<BoxProps> = styled(Box)(({ theme }) => ({ | ||
| width: '100%', | ||
| padding: `${theme.spacing(2.5)} ${theme.spacing(2.5)} ${theme.spacing(2)}`, | ||
| [theme.breakpoints.down('sm')]: { | ||
| padding: `${theme.spacing(2)} ${theme.spacing(1.5)} ${theme.spacing(2)}`, | ||
| }, | ||
| })) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| export const LEFT_PANEL_CONTENT = { | ||
| chatRoomList: 0, | ||
| createChat: 1, | ||
| createGroupChat: 2, | ||
| editGroupChat: 3, | ||
| groupDetails: 4, | ||
| } as const |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,135 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'use client' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { FC, useState } from 'react' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useResponsive } from '@baseapp-frontend/design-system/hooks/web' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useQueryLoader } from 'react-relay' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { GroupDetailsQuery as GroupDetailsQueryType } from '../../../../__generated__/GroupDetailsQuery.graphql' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { GroupDetailsQuery, useChatRoom } from '../../common' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import DefaultAllChatRoomsList from '../AllChatRoomsList' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import ChatRoom from '../ChatRoom' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import DefaultGroupChatCreate from '../GroupChatCreate' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import DefaultGroupChatDetails from '../GroupChatDetails' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import DefaultGroupChatEdit from '../GroupChatEdit' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import DefaultSingleChatCreate from '../SingleChatCreate' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { LEFT_PANEL_CONTENT } from './constants' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { ChatRoomContainer, ChatRoomsContainer, ChatRoomsListContainer } from './styled' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { ChatRoomsComponentProps, LeftPanelContentValues } from './types' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const ChatRoomsComponent: FC<ChatRoomsComponentProps> = ({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chatRoomsQueryData, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| settings, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AllChatRoomsListComponent = DefaultAllChatRoomsList, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| AllChatRoomsListComponentProps = {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| GroupChatCreateComponent = DefaultGroupChatCreate, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| GroupChatCreateComponentProps = {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| GroupChatDetailsComponent = DefaultGroupChatDetails, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| GroupChatDetailsComponentProps = {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| GroupChatEditComponent = DefaultGroupChatEdit, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| GroupChatEditComponentProps = {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SingleChatCreateComponent = DefaultSingleChatCreate, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SingleChatCreateComponentProps = {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const isUpToMd = useResponsive('up', 'md') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [leftPanelContent, setLeftPanelContent] = useState<LeftPanelContentValues>( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LEFT_PANEL_CONTENT.chatRoomList, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [groupDetailsQueryRef, loadGroupDetailsQuery] = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| useQueryLoader<GroupDetailsQueryType>(GroupDetailsQuery) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { id: selectedRoom } = useChatRoom() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const displayGroupDetails = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (selectedRoom) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setLeftPanelContent(LEFT_PANEL_CONTENT.groupDetails) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| loadGroupDetailsQuery({ roomId: selectedRoom }, { fetchPolicy: 'network-only' }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const shouldRenderLeftPanel = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isUpToMd || leftPanelContent !== LEFT_PANEL_CONTENT.chatRoomList || !selectedRoom | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const shouldRenderRightPanel = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isUpToMd || (leftPanelContent === LEFT_PANEL_CONTENT.chatRoomList && !!selectedRoom) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const renderLeftPanelContent = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| switch (leftPanelContent) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case LEFT_PANEL_CONTENT.createGroupChat: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <GroupChatCreateComponent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| allProfilesRef={chatRoomsQueryData} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onValidSubmission={() => setLeftPanelContent(LEFT_PANEL_CONTENT.chatRoomList)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onBackButtonClicked={() => setLeftPanelContent(LEFT_PANEL_CONTENT.createChat)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {...GroupChatCreateComponentProps} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case LEFT_PANEL_CONTENT.editGroupChat: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!groupDetailsQueryRef) return null | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <GroupChatEditComponent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onCancellation={() => setLeftPanelContent(LEFT_PANEL_CONTENT.groupDetails)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onRemovalFromGroup={() => setLeftPanelContent(LEFT_PANEL_CONTENT.chatRoomList)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onValidSubmission={() => setLeftPanelContent(LEFT_PANEL_CONTENT.groupDetails)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| queryRef={groupDetailsQueryRef} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| roomId={selectedRoom} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| allProfilesRef={chatRoomsQueryData} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {...GroupChatEditComponentProps} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case LEFT_PANEL_CONTENT.groupDetails: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!groupDetailsQueryRef) return null | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <GroupChatDetailsComponent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| queryRef={groupDetailsQueryRef} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onBackButtonClicked={() => setLeftPanelContent(LEFT_PANEL_CONTENT.chatRoomList)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onEditButtonClicked={() => setLeftPanelContent(LEFT_PANEL_CONTENT.editGroupChat)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {...GroupChatDetailsComponentProps} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case LEFT_PANEL_CONTENT.createChat: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <SingleChatCreateComponent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| allProfilesRef={chatRoomsQueryData} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onHeaderClick={() => setLeftPanelContent(LEFT_PANEL_CONTENT.chatRoomList)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onChatCreation={() => setLeftPanelContent(LEFT_PANEL_CONTENT.chatRoomList)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onGroupChatCreationButtonClicked={() => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setLeftPanelContent(LEFT_PANEL_CONTENT.createGroupChat) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {...SingleChatCreateComponentProps} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| default: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <AllChatRoomsListComponent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| targetRef={chatRoomsQueryData} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onHeaderClick={() => setLeftPanelContent(LEFT_PANEL_CONTENT.createChat)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {...AllChatRoomsListComponentProps} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const renderRightPanelContent = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!selectedRoom) return <div /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return <ChatRoom roomId={selectedRoom} onDisplayGroupDetailsClicked={displayGroupDetails} /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <ChatRoomsContainer themeLayout={settings.themeLayout}> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {shouldRenderLeftPanel && ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <ChatRoomsListContainer hide={!shouldRenderLeftPanel /* TODO: Why? */}> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think those "Why" comments (here and 5 lines below) are from me, don't know how they made it to master, I thought I had deleted them. Maybe you can remove them before merging? (I still don't understand why this prop is necessary, maybe someone can explain that to me.) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {renderLeftPanelContent()} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </ChatRoomsListContainer> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {shouldRenderRightPanel && ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <ChatRoomContainer hide={!shouldRenderRightPanel /* TODO: Why? */}> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {renderRightPanelContent()} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </ChatRoomContainer> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </ChatRoomsContainer> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+118
to
+132
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Remove redundant hide props and TODO comments The return (
<ChatRoomsContainer themeLayout={settings.themeLayout}>
{shouldRenderLeftPanel && (
- <ChatRoomsListContainer hide={!shouldRenderLeftPanel /* TODO: Why? */}>
+ <ChatRoomsListContainer>
{renderLeftPanelContent()}
</ChatRoomsListContainer>
)}
{shouldRenderRightPanel && (
- <ChatRoomContainer hide={!shouldRenderRightPanel /* TODO: Why? */}>
+ <ChatRoomContainer>
{renderRightPanelContent()}
</ChatRoomContainer>
)}
</ChatRoomsContainer>
)📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export default ChatRoomsComponent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.