From 6ed2a79c27097b64aae3953d96eb3d314d04da59 Mon Sep 17 00:00:00 2001 From: Liam Hongman Cho Date: Wed, 25 Sep 2024 10:55:13 +0900 Subject: [PATCH] feat: Added pending & failed message (#363) ## Changes - Added pending and failed messages ticket: [AC-2609] [Sign in to Sendbird.webm](https://github.com/user-attachments/assets/d670a9ad-b006-448a-9157-56eceb0c7236) ## Additional Notes - Tested with localCacheEnabled false, and message input disabled false ## Checklist Before requesting a code review, please check the following: - [x] **[Required]** CI has passed all checks. - [x] **[Required]** A self-review has been conducted to ensure there are no minor mistakes. - [x] **[Required]** Unnecessary comments/debugging code have been removed. - [x] **[Required]** All requirements specified in the ticket have been accurately implemented. - [ ] Ensure the ticket has been updated with the sprint, status, and story points. [AC-2609]: https://sendbird.atlassian.net/browse/AC-2609?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ --------- Co-authored-by: Hyungu Kang | Airen --- src/components/CurrentUserMessage.tsx | 8 ++-- src/components/LoadingScreen.tsx | 2 +- src/components/MyMessageStatus.tsx | 43 +++++++++++++++++++ .../messages/OutgoingFileMessage.tsx | 6 +-- 4 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 src/components/MyMessageStatus.tsx diff --git a/src/components/CurrentUserMessage.tsx b/src/components/CurrentUserMessage.tsx index ffd159e58..53f9d222e 100644 --- a/src/components/CurrentUserMessage.tsx +++ b/src/components/CurrentUserMessage.tsx @@ -1,9 +1,9 @@ +import { styled } from '@linaria/react'; import { UserMessage } from '@sendbird/chat/message'; -import styled from 'styled-components'; -import { DefaultSentTime, BodyContainer, BodyComponent } from './MessageComponent'; +import { BodyContainer, BodyComponent } from './MessageComponent'; +import MyMessageStatus from './MyMessageStatus'; import { useConstantState } from '../context/ConstantContext'; -import { formatCreatedAtToAMPM } from '../utils/messageTimestamp'; const Root = styled.div<{ enableEmojiFeedback: boolean }>` display: flex; @@ -22,7 +22,7 @@ export default function CurrentUserMessage(props: Props) { return ( - {formatCreatedAtToAMPM(message.createdAt, dateLocale)} +
{message.message}
diff --git a/src/components/LoadingScreen.tsx b/src/components/LoadingScreen.tsx index b7b640fec..0e6a90657 100644 --- a/src/components/LoadingScreen.tsx +++ b/src/components/LoadingScreen.tsx @@ -9,7 +9,7 @@ const spinner = keyframes` 100% { transform: rotate(360deg); } -}`; +`; const Container = styled.div` width: 100%; diff --git a/src/components/MyMessageStatus.tsx b/src/components/MyMessageStatus.tsx new file mode 100644 index 000000000..fa539fbed --- /dev/null +++ b/src/components/MyMessageStatus.tsx @@ -0,0 +1,43 @@ +import { css } from '@linaria/core'; +import { SendableMessage } from '@sendbird/chat/lib/__definition'; +import { SendingStatus } from '@sendbird/chat/message'; +import { Locale } from 'date-fns'; +import { useTheme } from 'styled-components'; + +import { DefaultSentTime } from './MessageComponent'; +import { Icon } from '../foundation/components/Icon'; +import { Loader } from '../foundation/components/Loader'; +import { formatCreatedAtToAMPM } from '../utils/messageTimestamp'; + +interface MyMessageStatusProps { + message: SendableMessage; + dateLocale: Locale; +} + +export default function MyMessageStatus(props: MyMessageStatusProps) { + const { message, dateLocale } = props; + const theme = useTheme(); + + switch (message.sendingStatus) { + case SendingStatus.PENDING: + return ( + + + + ); + case SendingStatus.FAILED: + return ( +
+ +
+ ); + default: + return {formatCreatedAtToAMPM(message.createdAt, dateLocale)}; + } +} + +const sendbirdLoader = css` + margin-bottom: 2px; + width: 16px; + height: 16px; +`; diff --git a/src/components/messages/OutgoingFileMessage.tsx b/src/components/messages/OutgoingFileMessage.tsx index b02693bcf..c4ed94cbb 100644 --- a/src/components/messages/OutgoingFileMessage.tsx +++ b/src/components/messages/OutgoingFileMessage.tsx @@ -8,8 +8,8 @@ import { Icon } from '../../foundation/components/Icon'; import { Label } from '../../foundation/components/Label'; import { Loader } from '../../foundation/components/Loader'; import { META_ARRAY_ASPECT_RATIO_KEY } from '../../utils/getImageAspectRatio'; -import { formatCreatedAtToAMPM } from '../../utils/messageTimestamp'; -import { BodyComponent, BodyContainer, DefaultSentTime } from '../MessageComponent'; +import { BodyComponent, BodyContainer } from '../MessageComponent'; +import MyMessageStatus from '../MyMessageStatus'; import { FileViewer } from '../ui/FileViewer'; type Props = { @@ -36,7 +36,7 @@ export const OutgoingFileMessage = ({ message }: Props) => { const renderTimestamp = () => { return (
- {formatCreatedAtToAMPM(message.createdAt, dateLocale)} +
); };