Skip to content

Commit

Permalink
feat: display suggested replies after streaming is done
Browse files Browse the repository at this point in the history
  • Loading branch information
AhyoungRyu committed Jul 18, 2023
1 parent c70a9f7 commit 05da70e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/components/CustomChannelComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { SendingStatus } from '@sendbird/chat/message';
import ChannelHeader from '@sendbird/uikit-react/Channel/components/ChannelHeader';
import ChannelUI from '@sendbird/uikit-react/Channel/components/ChannelUI';
import { useChannelContext } from '@sendbird/uikit-react/Channel/context';
import { useEffect, useState } from 'react';
import { useEffect, useState, useMemo } from 'react';
// eslint-disable-next-line import/no-unresolved
import { ClientUserMessage, EveryMessage } from 'SendbirdUIKitGlobal';
import styled from 'styled-components';
Expand Down Expand Up @@ -39,6 +39,10 @@ type CustomChannelComponentProps = {
createGroupChannel?: () => void;
};

type MessageMeta = {
stream: boolean;
};

export function CustomChannelComponent(props: CustomChannelComponentProps) {
const { botUser, createGroupChannel } = props;
const { suggestedMessageContent } = useConstantState();
Expand All @@ -53,6 +57,16 @@ export function CustomChannelComponent(props: CustomChannelComponentProps) {
const startingPagePlaceHolder =
allMessages.length === 1 && lastMessage.messageType === 'admin';

const messageMeta = useMemo(() => {
let messageMeta: MessageMeta | null;
try {
messageMeta = lastMessage?.data ? JSON.parse(lastMessage.data) : null;
} catch (error) {
messageMeta = null;
}
return messageMeta;
}, [lastMessage?.data]);

/**
* If the updated last message is sent by the current user, activate spinner for the sent message.
* If the updated last message is pending or failed by the current user or sent by the bot, deactivate spinner.
Expand Down Expand Up @@ -95,6 +109,7 @@ export function CustomChannelComponent(props: CustomChannelComponentProps) {
{allMessages &&
allMessages.length > 1 &&
lastMessage.sender.userId === botUser.userId &&
!messageMeta?.stream &&
isSpecialMessage(
lastMessage.message,
suggestedMessageContent.messageFilterList
Expand Down

0 comments on commit 05da70e

Please sign in to comment.