Skip to content

Commit

Permalink
Fix: Display emoji in visual format and enable send icon on emoji sel…
Browse files Browse the repository at this point in the history
…ection (#663)

* Fix: Display emoji in visual format and enable send icon on emoji selection

* Revised code
  • Loading branch information
SinghaAnirban005 authored Nov 10, 2024
1 parent e898504 commit afa6b81
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
15 changes: 9 additions & 6 deletions packages/react/src/views/ChatInput/ChatInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import useAttachmentWindowStore from '../../store/attachmentwindow';
import MembersList from '../Mentions/MembersList';
import { TypingUsers } from '../TypingUsers';
import createPendingMessage from '../../lib/createPendingMessage';
import { parseEmoji } from '../../lib/emoji';
import { CommandsList } from '../CommandList';
import useSettingsStore from '../../store/settingsStore';
import ChannelState from '../ChannelState/ChannelState';
Expand All @@ -34,6 +33,7 @@ import { getChatInputStyles } from './ChatInput.styles';
import useShowCommands from '../../hooks/useShowCommands';
import useSearchMentionUser from '../../hooks/useSearchMentionUser';
import formatSelection from '../../lib/formatSelection';
import { parseEmoji } from '../../lib/emoji';

const ChatInput = ({ scrollToBottom }) => {
const { styleOverrides, classNames } = useComponentOverrides('ChatInput');
Expand Down Expand Up @@ -362,14 +362,16 @@ const ChatInput = ({ scrollToBottom }) => {
setData(event.target.files[0]);
};

const onTextChange = (e) => {
const onTextChange = (e, val) => {
sendTypingStart();
const message = e.target.value;
const message = val || e.target.value;
messageRef.current.value = parseEmoji(message);
setDisableButton(!messageRef.current.value.length);
handleNewLine(e, false);
searchMentionUser(message);
showCommands(e);
if (e !== null) {
handleNewLine(e, false);
searchMentionUser(message);
showCommands(e);
}
};

const handleFocus = () => {
Expand Down Expand Up @@ -532,6 +534,7 @@ const ChatInput = ({ scrollToBottom }) => {
<ChatInputFormattingToolbar
messageRef={messageRef}
inputRef={inputRef}
triggerButton={onTextChange}
/>
)}
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import formatSelection from '../../lib/formatSelection';
const ChatInputFormattingToolbar = ({
messageRef,
inputRef,
triggerButton,
optionConfig = {
surfaceItems: ['emoji', 'formatter', 'audio', 'video', 'file'],
formatters: ['bold', 'italic', 'strike', 'code', 'multiline'],
Expand Down Expand Up @@ -46,7 +47,11 @@ const ChatInputFormattingToolbar = ({

const handleEmojiClick = (emojiEvent) => {
const [emoji] = emojiEvent.names;
messageRef.current.value += ` :${emoji.replace(/[\s-]+/g, '_')}: `;
const message = `${messageRef.current.value} :${emoji.replace(
/[\s-]+/g,
'_'
)}: `;
triggerButton?.(null, message);
};

const chatToolMap = {
Expand Down

0 comments on commit afa6b81

Please sign in to comment.