Skip to content
Merged
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 packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @baseapp-frontend/components

## 1.0.5

### Patch Changes

- Clean up the three dot menu in the chat header (do not display the option to leave a non-group chat, implement archiving chats from there)

## 1.0.4

### Patch Changes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { useCurrentProfile } from '@baseapp-frontend/authentication'
import { useNotification } from '@baseapp-frontend/utils'

import { Disposable, UseMutationConfig, graphql, useMutation } from 'react-relay'
import { ConnectionHandler, Disposable, UseMutationConfig, graphql, useMutation } from 'react-relay'

import { ArchiveChatRoomMutation } from '../../../../../__generated__/ArchiveChatRoomMutation.graphql'
import { getChatRoomConnections } from '../../utils'

export const ArchiveChatRoomMutationQuery = graphql`
mutation ArchiveChatRoomMutation($input: ChatRoomArchiveInput!) {
chatRoomArchive(input: $input) {
room {
id
isArchived
}
errors {
field
Expand All @@ -26,6 +29,7 @@ export const useArchiveChatRoomMutation = (): [
const [commitMutation, isMutationInFlight] = useMutation<ArchiveChatRoomMutation>(
ArchiveChatRoomMutationQuery,
)
const { currentProfile } = useCurrentProfile()

const commit = (config: UseMutationConfig<ArchiveChatRoomMutation>) =>
commitMutation({
Expand All @@ -40,6 +44,19 @@ export const useArchiveChatRoomMutation = (): [
sendToast(error.message, { type: 'error' })
config?.onError?.(error)
},
updater: (store, data) => {
if (!data?.chatRoomArchive?.errors && currentProfile?.id) {
getChatRoomConnections(
store,
currentProfile.id,
({ archived }) => archived === !data?.chatRoomArchive?.room?.isArchived,
).forEach((connectionRecord) => {
if (data?.chatRoomArchive?.room?.id)
ConnectionHandler.deleteNode(connectionRecord, data?.chatRoomArchive?.room?.id)
})
}
config?.updater?.(store, data)
},
})

return [commit, isMutationInFlight]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const ChatRoomQuery = graphql`
query ChatRoomQuery($roomId: ID!) {
chatRoom(id: $roomId) {
id
isArchived
participantsCount
...TitleFragment
...MessagesListFragment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,29 @@ import { MenuItem, MenuList, Typography } from '@mui/material'
import { ChatRoomOptionsProps } from './types'

const ChatRoomOptions: FC<ChatRoomOptionsProps> = ({
isArchived,
isArchiveMutationInFlight,
isGroup,
onArchiveClicked,
onDetailsClicked,
onLeaveClicked,
}) => (
<MenuList>
{/* TODO: Implement archive room functionality */}
<MenuItem onClick={onArchiveClicked}>
<Typography variant="body2">Archive Chat</Typography>
</MenuItem>
<MenuItem onClick={onDetailsClicked}>
<Typography variant="body2">Group Details</Typography>
</MenuItem>
<MenuItem onClick={onLeaveClicked}>
<Typography variant="body2" color="error">
Leave Group
</Typography>
<MenuItem onClick={onArchiveClicked} disabled={isArchiveMutationInFlight}>
<Typography variant="body2">{isArchived ? 'Unarchive Chat' : 'Archive Chat'}</Typography>
</MenuItem>
{isGroup ? (
<>
<MenuItem onClick={onDetailsClicked}>
<Typography variant="body2">Group Details</Typography>
</MenuItem>
<MenuItem onClick={onLeaveClicked}>
<Typography variant="body2" color="error">
Leave Group
</Typography>
</MenuItem>
</>
) : null}
</MenuList>
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export interface ChatRoomOptionsProps {
isArchived: boolean
isArchiveMutationInFlight: boolean
isGroup: boolean
onArchiveClicked: () => void
onDetailsClicked: () => void
onLeaveClicked: () => void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useFragment } from 'react-relay'
import {
TitleFragment,
getParticipantCountString,
useArchiveChatRoomMutation,
useChatRoom,
useNameAndAvatar,
} from '../../../common'
Expand All @@ -24,6 +25,7 @@ import { BackButtonContainer, ChatHeaderContainer, ChatTitleContainer } from './
import { ChatRoomHeaderProps } from './types'

const ChatRoomHeader: FC<ChatRoomHeaderProps> = ({
isArchived,
participantsCount,
roomTitleRef,
onDisplayGroupDetailsClicked,
Expand All @@ -35,10 +37,27 @@ const ChatRoomHeader: FC<ChatRoomHeaderProps> = ({
const isUpToMd = useResponsive('up', 'md')
const { resetChatRoom } = useChatRoom()

const { isGroup } = roomHeader
const { title, avatar } = useNameAndAvatar(roomHeader)
const members = getParticipantCountString(participantsCount)
const popover = usePopover()
const { currentProfile } = useCurrentProfile()
const [commit, isMutationInFlight] = useArchiveChatRoomMutation()

const toggleArchiveChatroom = () => {
popover.onClose()
if (currentProfile?.id && roomId) {
commit({
variables: {
input: {
roomId,
profileId: currentProfile.id,
archive: !isArchived,
},
},
})
}
}

const onChatRoomOptionsClicked = (e: React.MouseEvent<HTMLButtonElement>) => {
e.stopPropagation()
Expand Down Expand Up @@ -68,8 +87,8 @@ const ChatRoomHeader: FC<ChatRoomHeaderProps> = ({
</BackButtonContainer>
)}
<ChatTitleContainer
onClick={roomHeader.isGroup ? onDisplayGroupDetailsClicked : undefined}
isClickable={roomHeader.isGroup}
onClick={isGroup ? onDisplayGroupDetailsClicked : undefined}
isClickable={isGroup}
>
<AvatarWithPlaceholder
className="self-start justify-self-center"
Expand All @@ -82,7 +101,7 @@ const ChatRoomHeader: FC<ChatRoomHeaderProps> = ({
<Typography component="span" variant="subtitle2" sx={{ float: 'left', clear: 'left' }}>
{title}
</Typography>
{roomHeader.isGroup && (
{isGroup && (
<Typography component="span" variant="caption" sx={{ float: 'left', clear: 'left' }}>
{members}
</Typography>
Expand All @@ -100,11 +119,18 @@ const ChatRoomHeader: FC<ChatRoomHeaderProps> = ({
}}
>
<ChatRoomOptions
onArchiveClicked={() => {}}
onDetailsClicked={() =>
roomHeader.isGroup ? onDisplayGroupDetailsClicked() : undefined
}
onLeaveClicked={() => setOpen(true)}
isArchived={isArchived}
isArchiveMutationInFlight={isMutationInFlight}
isGroup={isGroup}
onArchiveClicked={toggleArchiveChatroom}
onDetailsClicked={() => {
popover.onClose()
onDisplayGroupDetailsClicked()
}}
onLeaveClicked={() => {
popover.onClose()
setOpen(true)
}}
/>
</Popover>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { BoxProps } from '@mui/material'
import { TitleFragment$key } from '../../../../../__generated__/TitleFragment.graphql'

export interface ChatRoomHeaderProps {
isArchived: boolean
participantsCount: number
roomTitleRef: TitleFragment$key
onDisplayGroupDetailsClicked: VoidFunction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const ChatRoom: FC<ChatRoomProps> = ({
return (
<ChatRoomContainer>
<ChatRoomHeader
isArchived={!!chatRoom.isArchived}
participantsCount={chatRoom.participantsCount}
roomTitleRef={chatRoom}
onDisplayGroupDetailsClicked={onDisplayGroupDetailsClicked}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import {
} from '@baseapp-frontend/design-system/components/web/icons'

import { Box, Badge as DefaultBadge, Typography } from '@mui/material'
import { ConnectionHandler, useFragment } from 'react-relay'
import { RecordSourceSelectorProxy } from 'relay-runtime'

import { useFragment } from 'react-relay'
import { LastMessageFragment$key } from '../../../../../__generated__/LastMessageFragment.graphql'
import { TitleFragment$key } from '../../../../../__generated__/TitleFragment.graphql'
import { UnreadMessagesCountFragment$key } from '../../../../../__generated__/UnreadMessagesCountFragment.graphql'
Expand All @@ -20,7 +18,6 @@ import {
LastMessageFragment,
TitleFragment,
UnreadMessagesCountFragment,
getChatRoomConnections,
useArchiveChatRoomMutation,
useNameAndAvatar,
useUnreadChatMutation,
Expand Down Expand Up @@ -94,13 +91,6 @@ const ChatRoomItem: FC<ChatRoomItemProps> = ({
archive: !isInArchivedTab,
},
},
updater: (store: RecordSourceSelectorProxy<unknown>, data: any) => {
if (!data?.errors) {
getChatRoomConnections(store, currentProfile.id).forEach((connectionRecord) =>
ConnectionHandler.deleteNode(connectionRecord, roomRef.id),
)
}
},
})
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@baseapp-frontend/components",
"description": "BaseApp components modules such as comments, notifications, messages, and more.",
"version": "1.0.4",
"version": "1.0.5",
"sideEffects": false,
"scripts": {
"babel:bundle": "babel modules -d tmp-babel --extensions .ts,.tsx --ignore '**/__tests__/**','**/__storybook__/**'",
Expand Down
Loading