Skip to content

Commit

Permalink
Merge pull request #64 from sendbird/feat/AC-596/enable-mention
Browse files Browse the repository at this point in the history
feat: enable user(bot) mention
  • Loading branch information
AhyoungRyu authored Oct 18, 2023
2 parents f14da12 + a097651 commit 5bb4f72
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 17 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ const customConstants = {
replacementTextList: [['the Text extracts', 'ChatBot Knowledge Base']],
enableSourceMessage: false,
enableEmojiFeedback: true,
enableMention: true,
};

const App = () => {
Expand All @@ -205,6 +206,7 @@ const App = () => {
replacementTextList={customConstants.replacementTextList}
enableSourceMessage={customConstants.enableSourceMessage}
enableEmojiFeedback={customConstants.enableEmojiFeedback}
enableMention={customConstants.enableMention}
/>
);
};
Expand Down
1 change: 1 addition & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const App = (props: Props) => {
configureSession={props.configureSession}
enableSourceMessage={props.enableSourceMessage}
enableEmojiFeedback={props.enableEmojiFeedback}
enableMention={props.enableMention}
/>
);
};
Expand Down
10 changes: 10 additions & 0 deletions src/components/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const SBComponent = () => {
userNickName,
configureSession,
enableEmojiFeedback,
enableMention,
} = useConstantState();

assert(
Expand Down Expand Up @@ -61,6 +62,15 @@ const SBComponent = () => {
customExtensionParams={userAgentCustomParams.current}
breakPoint={isMobile}
isReactionEnabled={enableEmojiFeedback}
isMentionEnabled={enableMention}
uikitOptions={{
groupChannel: {
input: {
// To hide the file upload icon from the message input
enableDocument: false,
},
},
}}
>
<>
<CustomChannel />
Expand Down
89 changes: 72 additions & 17 deletions src/components/CustomChannelComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import ChannelHeader from '@sendbird/uikit-react/Channel/components/ChannelHeade
import ChannelUI from '@sendbird/uikit-react/Channel/components/ChannelUI';
import { useChannelContext } from '@sendbird/uikit-react/Channel/context';
import { useEffect, useState, useMemo, useRef } from 'react';
import ReactDOM from 'react-dom';
// eslint-disable-next-line import/no-unresolved
import { ClientUserMessage, EveryMessage } from 'SendbirdUIKitGlobal';
import styled from 'styled-components';

import ChatBottom from './ChatBottom';
import CustomChannelHeader from './CustomChannelHeader';
import CustomMessage from './CustomMessage';
import CustomMessageInput from './CustomMessageInput';
import DynamicRepliesPanel from './DynamicRepliesPanel';
import { useConstantState } from '../context/ConstantContext';
import { useScrollOnStreaming } from '../hooks/useScrollOnStreaming';
Expand All @@ -22,7 +22,12 @@ import {
getBotWelcomeMessages,
} from '../utils/messages';

const Root = styled.div<{ hidePlaceholder: boolean; height: string }>`
interface RootStyleProps {
hidePlaceholder: boolean;
height: string;
isInputActive: boolean;
}
const Root = styled.div<RootStyleProps>`
height: ${({ height }) => height};
font-family: 'Roboto', sans-serif;
z-index: 0;
Expand All @@ -31,6 +36,59 @@ const Root = styled.div<{ hidePlaceholder: boolean; height: string }>`
.sendbird-place-holder__body {
display: ${({ hidePlaceholder }) => (hidePlaceholder ? 'none' : 'block')};
}
.sendbird-message-input-wrapper {
width: 100%;
}
.sendbird-message-input-wrapper__message-input {
padding: 12px 16px;
display: flex;
-webkit-box-pack: justify;
justify-content: space-between;
-webkit-box-align: center;
align-items: center;
}
.sendbird-message-input {
display: flex;
align-items: center;
.sendbird-message-input-text-field {
transition: ${(props: RootStyleProps) =>
props.isInputActive ? 'none' : 'width 0.5s'};
transition-timing-function: ease;
padding: 8px 16px;
font-size: 14px;
font-family: 'Roboto', sans-serif;
line-height: 20px;
color: rgba(0, 0, 0, 0.88);
resize: none;
border: none;
outline: none;
max-height: 116px;
background-color: #eeeeee;
border-radius: 20px;
height: auto;
::placeholder {
color: rgba(0, 0, 0, 0.38);
}
:focus {
border: none;
box-shadow: none;
}
}
.sendbird-message-input--send {
position: relative;
right: 0;
bottom: 0;
:hover {
background-color: transparent;
}
}
.sendbird-message-input--placeholder {
top: 9px;
}
}
`;

export interface StartingPageAnimatorProps {
Expand Down Expand Up @@ -146,21 +204,6 @@ export function CustomChannelComponent(props: CustomChannelComponentProps) {
<ChannelHeader />
);
}}
renderMessageInput={() => {
return (
<div
style={{
position: 'relative',
zIndex: 50,
backgroundColor: 'white',
}}
>
{/* {isStaticReplyVisible && <StaticRepliesPanel botUser={botUser} />} */}
<CustomMessageInput />
<ChatBottom />
</div>
);
}}
renderMessage={({ message }: { message: EveryMessage }) => {
const grouppedMessage = grouppedMessages.find(
(m) => m.messageId == message.messageId
Expand Down Expand Up @@ -189,6 +232,18 @@ export function CustomChannelComponent(props: CustomChannelComponentProps) {
}}
renderTypingIndicator={() => <></>}
/>
<Banner />
</Root>
);
}

function Banner() {
const inputElement = document.querySelector(
'.sendbird-message-input-wrapper'
);

if (inputElement) {
return ReactDOM.createPortal(<ChatBottom />, inputElement);
}
return null;
}
2 changes: 2 additions & 0 deletions src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export const DEFAULT_CONSTANT: Constant = {
},
enableSourceMessage: true,
enableEmojiFeedback: true,
enableMention: true,
};

type ConfigureSession = (
Expand Down Expand Up @@ -141,6 +142,7 @@ export interface Constant {
configureSession: ConfigureSession;
enableSourceMessage: boolean;
enableEmojiFeedback: boolean;
enableMention: boolean;
firstMessageData: FirstMessageItem[];
}

Expand Down
1 change: 1 addition & 0 deletions src/context/ConstantContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const ConstantStateProvider = (props: ProviderProps) => {
props.enableSourceMessage ?? initialState.enableSourceMessage,
enableEmojiFeedback:
props.enableEmojiFeedback ?? initialState.enableEmojiFeedback,
enableMention: props.enableMention ?? initialState.enableMention,
}),
[props]
);
Expand Down

0 comments on commit 5bb4f72

Please sign in to comment.