Skip to content
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

feat: Added pending & failed message #363

Merged
merged 20 commits into from
Sep 25, 2024
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
8 changes: 4 additions & 4 deletions src/components/CurrentUserMessage.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -22,7 +22,7 @@ export default function CurrentUserMessage(props: Props) {

return (
<Root enableEmojiFeedback={enableEmojiFeedback}>
<DefaultSentTime>{formatCreatedAtToAMPM(message.createdAt, dateLocale)}</DefaultSentTime>
<MyMessageStatus message={message} dateLocale={dateLocale} />
<BodyContainer>
<BodyComponent>
<div className="sendbird-word">{message.message}</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/LoadingScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const spinner = keyframes`
100% {
transform: rotate(360deg);
}
}`;
`;

const Container = styled.div`
width: 100%;
Expand Down
43 changes: 43 additions & 0 deletions src/components/MyMessageStatus.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<Loader className={sendbirdLoader} size={16}>
<Icon type={'spinner'} color={theme.bgColor.outgoingMessage} size={16} />
</Loader>
);
case SendingStatus.FAILED:
return (
<div className={sendbirdLoader}>
<Icon type={'error'} color={'error'} size={16} />
</div>
);
default:
return <DefaultSentTime>{formatCreatedAtToAMPM(message.createdAt, dateLocale)}</DefaultSentTime>;
}
}

const sendbirdLoader = css`
margin-bottom: 2px;
width: 16px;
height: 16px;
`;
6 changes: 3 additions & 3 deletions src/components/messages/OutgoingFileMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -36,7 +36,7 @@ export const OutgoingFileMessage = ({ message }: Props) => {
const renderTimestamp = () => {
return (
<div className={timestampContainer}>
<DefaultSentTime>{formatCreatedAtToAMPM(message.createdAt, dateLocale)}</DefaultSentTime>
<MyMessageStatus message={message} dateLocale={dateLocale} />
</div>
);
};
Expand Down