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 10 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
11 changes: 7 additions & 4 deletions src/components/CurrentUserMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { styled } from '@linaria/react';
import { UserMessage } from '@sendbird/chat/message';
import styled from 'styled-components';
import { useTheme } from 'styled-components';
liamcho marked this conversation as resolved.
Show resolved Hide resolved

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 @@ -18,11 +19,13 @@ type Props = {

export default function CurrentUserMessage(props: Props) {
const { enableEmojiFeedback, dateLocale } = useConstantState();
const theme = useTheme();

liamcho marked this conversation as resolved.
Show resolved Hide resolved
const { message } = props;

return (
<Root enableEmojiFeedback={enableEmojiFeedback}>
<DefaultSentTime>{formatCreatedAtToAMPM(message.createdAt, dateLocale)}</DefaultSentTime>
<MyMessageStatus message={message} dateLocale={dateLocale} theme={theme} />
liamcho marked this conversation as resolved.
Show resolved Hide resolved
<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
49 changes: 49 additions & 0 deletions src/components/MyMessageStatus.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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 { CommonTheme } from '../theme';
import { formatCreatedAtToAMPM } from '../utils/messageTimestamp';

interface MyMessageStatusProps {
message: SendableMessage;
dateLocale: Locale;
theme: CommonTheme;
liamcho marked this conversation as resolved.
Show resolved Hide resolved
}

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
style={{
display: 'inline-block',
width: '16px',
height: '16px',
}}
bang9 marked this conversation as resolved.
Show resolved Hide resolved
>
<Icon type={'error'} color={'error'} size={16} />
</div>
);
default:
return <DefaultSentTime>{formatCreatedAtToAMPM(message.createdAt, dateLocale)}</DefaultSentTime>;
}
}

const sendbirdLoader = css`
margin-bottom: 2px;
`;
8 changes: 5 additions & 3 deletions src/components/messages/OutgoingFileMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { css } from '@linaria/core';
import { styled } from '@linaria/react';
import { FileMessage } from '@sendbird/chat/message';
import { useState } from 'react';
import { useTheme } from 'styled-components';

import { useConstantState } from '../../context/ConstantContext';
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 @@ -18,6 +19,7 @@ type Props = {

export const OutgoingFileMessage = ({ message }: Props) => {
const { dateLocale } = useConstantState();
const theme = useTheme();

const hasMessageBubble = !!message.message;
const type = (() => {
Expand All @@ -36,7 +38,7 @@ export const OutgoingFileMessage = ({ message }: Props) => {
const renderTimestamp = () => {
return (
<div className={timestampContainer}>
<DefaultSentTime>{formatCreatedAtToAMPM(message.createdAt, dateLocale)}</DefaultSentTime>
<MyMessageStatus message={message} dateLocale={dateLocale} theme={theme} />
</div>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/foundation/components/Loader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const Loader = ({ className, children, size = 26, testId = 'sendbird-load
);
};

const Container = styled.div<{ size: string | number }>`
export const Container = styled.div<{ size: string | number }>`
liamcho marked this conversation as resolved.
Show resolved Hide resolved
display: inline-block;
animation: 1s infinite linear;
animation-name: rotate;
Expand Down