simon | 26e79f7 | 2022-10-05 22:16:08 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 Savoir-faire Linux Inc. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU Affero General Public License as |
| 6 | * published by the Free Software Foundation; either version 3 of the |
| 7 | * License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU Affero General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Affero General Public |
| 15 | * License along with this program. If not, see |
| 16 | * <https://www.gnu.org/licenses/>. |
| 17 | */ |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 18 | import { |
| 19 | Box, |
| 20 | Chip, |
| 21 | Divider, |
| 22 | List, |
| 23 | ListItemButton, |
| 24 | ListItemText, |
| 25 | Stack, |
| 26 | Theme, |
| 27 | Tooltip, |
| 28 | Typography, |
| 29 | } from '@mui/material'; |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 30 | import { styled } from '@mui/material/styles'; |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 31 | import dayjs, { Dayjs } from 'dayjs'; |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 32 | import isToday from 'dayjs/plugin/isToday'; |
| 33 | import isYesterday from 'dayjs/plugin/isYesterday'; |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 34 | import { Account, ConversationMember, Message } from 'jami-web-common'; |
| 35 | import { ReactElement } from 'react'; |
| 36 | import { ReactNode, useCallback, useMemo, useState } from 'react'; |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 37 | import { useTranslation } from 'react-i18next'; |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame] | 38 | |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 39 | import { EmojiButton, MoreButton, ReplyMessageButton } from './Button'; |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 40 | import ConversationAvatar from './ConversationAvatar'; |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 41 | import { OppositeArrowsIcon, TrashBinIcon, TwoSheetsIcon } from './SvgIcon'; |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 42 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 43 | dayjs.extend(isToday); |
| 44 | dayjs.extend(isYesterday); |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 45 | |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 46 | type MessagePosition = 'start' | 'end'; |
| 47 | |
| 48 | export const MessageCall = () => { |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 49 | return <Stack alignItems="center">"Appel"</Stack>; |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 50 | }; |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 51 | |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 52 | export const MessageInitial = () => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 53 | const { t } = useTranslation(); |
| 54 | return <Stack alignItems="center">{t('message_swarm_created')}</Stack>; |
| 55 | }; |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 56 | |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 57 | interface MessageDataTransferProps { |
| 58 | position: MessagePosition; |
| 59 | isFirstOfGroup: boolean; |
| 60 | isLastOfGroup: boolean; |
| 61 | } |
| 62 | |
| 63 | export const MessageDataTransfer = ({ position, isFirstOfGroup, isLastOfGroup }: MessageDataTransferProps) => { |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 64 | return ( |
| 65 | <MessageBubble |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 66 | backgroundColor={'#E5E5E5'} |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 67 | position={position} |
| 68 | isFirstOfGroup={isFirstOfGroup} |
| 69 | isLastOfGroup={isLastOfGroup} |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 70 | > |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 71 | "data-transfer" |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 72 | </MessageBubble> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 73 | ); |
| 74 | }; |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 75 | |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 76 | interface MessageMemberProps { |
| 77 | message: Message; |
| 78 | } |
| 79 | |
| 80 | export const MessageMember = ({ message }: MessageMemberProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 81 | const { t } = useTranslation(); |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 82 | return ( |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 83 | <Stack alignItems="center"> |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 84 | <Chip |
| 85 | sx={{ |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 86 | width: 'fit-content', |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 87 | }} |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 88 | label={t('message_user_joined', { user: message.author })} |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 89 | /> |
| 90 | </Stack> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 91 | ); |
| 92 | }; |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 93 | |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 94 | export const MessageMerge = () => { |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 95 | return <Stack alignItems="center">"merge"</Stack>; |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 96 | }; |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 97 | |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 98 | interface MessageTextProps { |
| 99 | message: Message; |
| 100 | position: MessagePosition; |
| 101 | isFirstOfGroup: boolean; |
| 102 | isLastOfGroup: boolean; |
| 103 | textColor: string; |
| 104 | bubbleColor: string; |
| 105 | } |
| 106 | |
| 107 | export const MessageText = ({ |
| 108 | message, |
| 109 | position, |
| 110 | isFirstOfGroup, |
| 111 | isLastOfGroup, |
| 112 | textColor, |
| 113 | bubbleColor, |
| 114 | }: MessageTextProps) => { |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 115 | return ( |
| 116 | <MessageBubble |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 117 | backgroundColor={bubbleColor} |
| 118 | position={position} |
| 119 | isFirstOfGroup={isFirstOfGroup} |
| 120 | isLastOfGroup={isLastOfGroup} |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 121 | > |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 122 | <Typography variant="body1" color={textColor} textAlign={position}> |
| 123 | {message.body} |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 124 | </Typography> |
| 125 | </MessageBubble> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 126 | ); |
| 127 | }; |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 128 | |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 129 | interface MessageDateProps { |
| 130 | time: Dayjs; |
| 131 | } |
| 132 | |
| 133 | export const MessageDate = ({ time }: MessageDateProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 134 | let textDate; |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 135 | |
| 136 | if (time.isToday()) { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 137 | textDate = 'Today'; |
| 138 | } else if (time.isYesterday()) { |
| 139 | textDate = 'Yesterday'; |
| 140 | } else { |
| 141 | const date = time.date().toString().padStart(2, '0'); |
| 142 | const month = (time.month() + 1).toString().padStart(2, '0'); |
| 143 | textDate = `${date}/${month}/${time.year()}`; |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | return ( |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 147 | <Box marginTop="30px"> |
idillon | 04245a1 | 2022-09-01 11:12:17 -0400 | [diff] [blame] | 148 | <Divider |
| 149 | sx={{ |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 150 | '.MuiDivider-wrapper': { |
idillon | 04245a1 | 2022-09-01 11:12:17 -0400 | [diff] [blame] | 151 | margin: 0, |
| 152 | padding: 0, |
| 153 | }, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 154 | '&::before': { |
| 155 | borderTop: '1px solid #E5E5E5', |
idillon | 04245a1 | 2022-09-01 11:12:17 -0400 | [diff] [blame] | 156 | }, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 157 | '&::after': { |
| 158 | borderTop: '1px solid #E5E5E5', |
idillon | 04245a1 | 2022-09-01 11:12:17 -0400 | [diff] [blame] | 159 | }, |
| 160 | }} |
| 161 | > |
| 162 | <Typography |
| 163 | variant="caption" |
| 164 | fontWeight={700} |
| 165 | border="1px solid #E5E5E5" |
| 166 | borderRadius="5px" |
| 167 | padding="10px 16px" |
| 168 | > |
| 169 | {textDate} |
| 170 | </Typography> |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 171 | </Divider> |
| 172 | </Box> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 173 | ); |
| 174 | }; |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 175 | |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 176 | interface MessageTimeProps { |
| 177 | time: Dayjs; |
| 178 | hasDateOnTop: boolean; |
| 179 | } |
| 180 | |
| 181 | export const MessageTime = ({ time, hasDateOnTop }: MessageTimeProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 182 | const hour = time.hour().toString().padStart(2, '0'); |
| 183 | const minute = time.minute().toString().padStart(2, '0'); |
| 184 | const textTime = `${hour}:${minute}`; |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 185 | |
| 186 | return ( |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 187 | <Stack direction="row" justifyContent="center" margin="30px" marginTop={hasDateOnTop ? '20px' : '30px'}> |
| 188 | <Typography variant="caption" color="#A7A7A7" fontWeight={700}> |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 189 | {textTime} |
| 190 | </Typography> |
| 191 | </Stack> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 192 | ); |
| 193 | }; |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 194 | |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 195 | interface MessageBubblesGroupProps { |
| 196 | account: Account; |
| 197 | messages: Message[]; |
| 198 | members: ConversationMember[]; |
| 199 | } |
| 200 | |
| 201 | export const MessageBubblesGroup = ({ account, messages, members }: MessageBubblesGroupProps) => { |
| 202 | const isUser = messages[0]?.author === account.getUri(); |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 203 | const position = isUser ? 'end' : 'start'; |
| 204 | const bubbleColor = isUser ? '#005699' : '#E5E5E5'; |
| 205 | const textColor = isUser ? 'white' : 'black'; |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 206 | |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 207 | let authorName; |
| 208 | if (isUser) { |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 209 | authorName = account.getDisplayName(); |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 210 | } else { |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 211 | const member = members.find((member) => messages[0]?.author === member.contact.getUri()); |
| 212 | authorName = member?.contact?.getDisplayName() || ''; |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 213 | } |
| 214 | |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 215 | return ( |
idillon | 89720a8 | 2022-09-06 18:47:05 -0400 | [diff] [blame] | 216 | <Stack // Row for a group of message bubbles with the user's infos |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 217 | direction="row" |
| 218 | justifyContent={position} |
idillon | 89720a8 | 2022-09-06 18:47:05 -0400 | [diff] [blame] | 219 | alignItems="end" |
| 220 | spacing="10px" |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 221 | > |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 222 | {!isUser && ( |
idillon | ae655dd | 2022-10-14 18:11:02 -0400 | [diff] [blame] | 223 | <ConversationAvatar displayName={authorName} sx={{ width: '22px', height: '22px', fontSize: '15px' }} /> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 224 | )} |
idillon | 89720a8 | 2022-09-06 18:47:05 -0400 | [diff] [blame] | 225 | <Stack // Container to align the bubbles to the same side of a row |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 226 | width="66.66%" |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 227 | alignItems={position} |
| 228 | > |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 229 | <ParticipantName name={authorName} /> |
idillon | 89720a8 | 2022-09-06 18:47:05 -0400 | [diff] [blame] | 230 | <Stack // Container for a group of message bubbles |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 231 | spacing="6px" |
| 232 | alignItems={position} |
| 233 | direction="column-reverse" |
| 234 | > |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 235 | {messages.map((message, index) => { |
| 236 | let Component: typeof MessageText | typeof MessageDataTransfer; |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 237 | switch (message.type) { |
| 238 | case 'text/plain': |
| 239 | Component = MessageText; |
| 240 | break; |
| 241 | case 'application/data-transfer+json': |
| 242 | Component = MessageDataTransfer; |
| 243 | break; |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 244 | default: |
| 245 | return null; |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 246 | } |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 247 | return ( |
| 248 | <Component // Single message |
| 249 | key={message.id} |
| 250 | message={message} |
| 251 | textColor={textColor} |
| 252 | position={position} |
| 253 | bubbleColor={bubbleColor} |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 254 | isFirstOfGroup={index === messages.length - 1} |
| 255 | isLastOfGroup={index === 0} |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 256 | /> |
| 257 | ); |
| 258 | })} |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 259 | </Stack> |
| 260 | </Stack> |
| 261 | </Stack> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 262 | ); |
| 263 | }; |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 264 | |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 265 | interface MessageTooltipProps { |
| 266 | className?: string; |
| 267 | position: MessagePosition; |
| 268 | children: ReactElement; |
| 269 | } |
| 270 | |
| 271 | const MessageTooltip = styled(({ className, position, children }: MessageTooltipProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 272 | const [open, setOpen] = useState(false); |
| 273 | const emojis = ['😎', '😄', '😍']; // Should be last three used emojis |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 274 | const additionalOptions = [ |
| 275 | { |
| 276 | Icon: TwoSheetsIcon, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 277 | text: 'Copy', |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 278 | action: () => {}, |
| 279 | }, |
| 280 | { |
| 281 | Icon: OppositeArrowsIcon, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 282 | text: 'Transfer', |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 283 | action: () => {}, |
| 284 | }, |
| 285 | { |
| 286 | Icon: TrashBinIcon, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 287 | text: 'Delete message', |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 288 | action: () => {}, |
| 289 | }, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 290 | ]; |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 291 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 292 | const toggleMoreMenu = useCallback(() => setOpen((open) => !open), [setOpen]); |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 293 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 294 | const onClose = useCallback(() => { |
| 295 | setOpen(false); |
| 296 | }, [setOpen]); |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 297 | |
| 298 | return ( |
| 299 | <Tooltip |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 300 | classes={{ tooltip: className }} // Required for styles. Don't know why |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 301 | placement={position === 'start' ? 'right-start' : 'left-start'} |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 302 | PopperProps={{ |
| 303 | modifiers: [ |
| 304 | { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 305 | name: 'offset', |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 306 | options: { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 307 | offset: [-2, -30], |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 308 | }, |
| 309 | }, |
| 310 | ], |
| 311 | }} |
| 312 | onClose={onClose} |
| 313 | title={ |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 314 | <Stack> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 315 | {/* Whole tooltip's content */} |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 316 | <Stack // Main options |
| 317 | direction="row" |
| 318 | spacing="16px" |
| 319 | > |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 320 | {emojis.map((emoji) => ( |
| 321 | <EmojiButton key={emoji} emoji={emoji} /> |
| 322 | ))} |
| 323 | <ReplyMessageButton /> |
| 324 | <MoreButton onClick={toggleMoreMenu} /> |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 325 | </Stack> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 326 | {open && ( // Additional menu options |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 327 | <> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 328 | <Divider sx={{ paddingTop: '16px' }} /> |
| 329 | <List sx={{ padding: 0, paddingTop: '8px', marginBottom: '-8px' }}> |
| 330 | {additionalOptions.map((option) => ( |
| 331 | <ListItemButton |
| 332 | key={option.text} |
| 333 | sx={{ |
| 334 | padding: '8px', |
| 335 | }} |
| 336 | > |
| 337 | <Stack // Could not find proper way to set spacing between ListItemIcon and ListItemText |
| 338 | direction="row" |
| 339 | spacing="16px" |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 340 | > |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 341 | <option.Icon |
| 342 | sx={{ |
| 343 | height: '16px', |
| 344 | margin: 0, |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 345 | color: (theme: Theme) => theme?.palette?.primary?.dark, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 346 | }} |
| 347 | /> |
| 348 | <ListItemText |
| 349 | primary={option.text} |
| 350 | primaryTypographyProps={{ |
| 351 | fontSize: '12px', |
| 352 | lineHeight: '16px', |
| 353 | }} |
| 354 | sx={{ |
| 355 | height: '16px', |
| 356 | margin: 0, |
| 357 | }} |
| 358 | /> |
| 359 | </Stack> |
| 360 | </ListItemButton> |
| 361 | ))} |
| 362 | </List> |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 363 | </> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 364 | )} |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 365 | </Stack> |
| 366 | } |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 367 | > |
| 368 | {children} |
| 369 | </Tooltip> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 370 | ); |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 371 | })(({ position }) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 372 | const largeRadius = '20px'; |
| 373 | const smallRadius = '5px'; |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 374 | return { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 375 | backgroundColor: 'white', |
| 376 | padding: '16px', |
| 377 | boxShadow: '3px 3px 7px #00000029', |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 378 | borderRadius: largeRadius, |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 379 | borderStartStartRadius: position === 'start' ? smallRadius : largeRadius, |
| 380 | borderStartEndRadius: position === 'end' ? smallRadius : largeRadius, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 381 | }; |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 382 | }); |
| 383 | |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 384 | interface MessageBubbleProps { |
| 385 | position: MessagePosition; |
| 386 | isFirstOfGroup: boolean; |
| 387 | isLastOfGroup: boolean; |
| 388 | backgroundColor: string; |
| 389 | children: ReactNode; |
| 390 | } |
| 391 | |
| 392 | const MessageBubble = ({ position, isFirstOfGroup, isLastOfGroup, backgroundColor, children }: MessageBubbleProps) => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 393 | const largeRadius = '20px'; |
| 394 | const smallRadius = '5px'; |
Adrien Béraud | 023f7cf | 2022-09-18 14:57:53 -0400 | [diff] [blame] | 395 | const radius = useMemo(() => { |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 396 | if (position === 'start') { |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 397 | return { |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 398 | borderStartStartRadius: isFirstOfGroup ? largeRadius : smallRadius, |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 399 | borderStartEndRadius: largeRadius, |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 400 | borderEndStartRadius: isLastOfGroup ? largeRadius : smallRadius, |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 401 | borderEndEndRadius: largeRadius, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 402 | }; |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 403 | } |
| 404 | return { |
| 405 | borderStartStartRadius: largeRadius, |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 406 | borderStartEndRadius: isFirstOfGroup ? largeRadius : smallRadius, |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 407 | borderEndStartRadius: largeRadius, |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 408 | borderEndEndRadius: isLastOfGroup ? largeRadius : smallRadius, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 409 | }; |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 410 | }, [isFirstOfGroup, isLastOfGroup, position]); |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 411 | |
| 412 | return ( |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 413 | <MessageTooltip position={position}> |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 414 | <Box |
| 415 | sx={{ |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 416 | width: 'fit-content', |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 417 | backgroundColor: backgroundColor, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 418 | padding: '16px', |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 419 | ...radius, |
| 420 | }} |
| 421 | > |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 422 | {children} |
idillon | 927b759 | 2022-09-15 12:56:45 -0400 | [diff] [blame] | 423 | </Box> |
| 424 | </MessageTooltip> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 425 | ); |
| 426 | }; |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 427 | |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 428 | interface ParticipantNameProps { |
| 429 | name: string; |
| 430 | } |
| 431 | |
| 432 | const ParticipantName = ({ name }: ParticipantNameProps) => { |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 433 | return ( |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 434 | <Box marginBottom="6px" marginLeft="16px" marginRight="16px"> |
| 435 | <Typography variant="caption" color="#A7A7A7" fontWeight={700}> |
idillon-sfl | 9d956ab | 2022-10-20 16:33:24 -0400 | [diff] [blame^] | 436 | {name} |
idillon | bef18a5 | 2022-09-01 01:51:40 -0400 | [diff] [blame] | 437 | </Typography> |
| 438 | </Box> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 439 | ); |
| 440 | }; |