From 4dde2e3dfa60e2eed5646c3510901e1b29ee9462 Mon Sep 17 00:00:00 2001 From: Amit Sharma <46066481+amit-s19@users.noreply.github.com> Date: Tue, 27 Feb 2024 17:55:42 +0530 Subject: [PATCH] small ui fixes (#232) * small ui fixes * added or support --- .../components/chat-message-item/index.tsx | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/apps/amakrushi/src/components/chat-message-item/index.tsx b/apps/amakrushi/src/components/chat-message-item/index.tsx index a3079f6..8c8900d 100644 --- a/apps/amakrushi/src/components/chat-message-item/index.tsx +++ b/apps/amakrushi/src/components/chat-message-item/index.tsx @@ -51,6 +51,10 @@ import { import { useIntl } from 'react-intl'; import BlinkingSpinner from '../blinking-spinner/index'; +interface FormattedTextProps { + content: string; +} + const getToastMessage = (t: any, reaction: number): string => { if (reaction === 1) return t('toast.reaction_like'); return t('toast.reaction_reset'); @@ -308,6 +312,37 @@ const ChatMessageItem: FC = ({ message, onSend }) => { } }, [handleAudio, message.content?.data, message.content?.text, t]); + const FormattedText = ({ content }: FormattedTextProps) => { + let words = content.split(' '); + if (words?.[words?.length - 1] == '' || words?.[words?.length - 1] == " ") { + words = words.slice(0, words?.length - 1); + } + + if (words?.[0] == ":") { + words = words.slice(1) + } + + if (words?.[0]?.includes('null')) { + words[0] = words[0].replace('null', localStorage.getItem('locale') == 'en' ? "I'm here to help with any agriculture-related questions you might have. Feel free to ask!" : "ଆପଣଙ୍କ ପାଖରେ ଥିବା କୃଷି ସମ୍ବନ୍ଧୀୟ ପ୍ରଶ୍ନଗୁଡ଼ିକରେ ସାହାଯ୍ୟ କରିବାକୁ ମୁଁ ଏଠାରେ ଅଛି | ପଚାରିବାକୁ ମୁକ୍ତ ହୁଅନ୍ତୁ!"); + } + + if (words?.[1]?.includes('null')) { + words[1] = words[1].replace('null', localStorage.getItem('locale') == 'en' ? "I'm here to help with any agriculture-related questions you might have. Feel free to ask!" : "ଆପଣଙ୍କ ପାଖରେ ଥିବା କୃଷି ସମ୍ବନ୍ଧୀୟ ପ୍ରଶ୍ନଗୁଡ଼ିକରେ ସାହାଯ୍ୟ କରିବାକୁ ମୁଁ ଏଠାରେ ଅଛି | ପଚାରିବାକୁ ମୁକ୍ତ ହୁଅନ୍ତୁ!"); + } + + if (words?.[words?.length - 2]?.includes('Thank') && words?.[words?.length - 1]?.includes('you')) { + words[words.length - 2] = words[words.length - 2].replace('Thank', '\nThank') + } + + return ( +

+ {words.map((word) => { + return word + ' ' + })} +

+ ); + } + switch (type) { case 'loader': return ; @@ -335,7 +370,7 @@ const ChatMessageItem: FC = ({ message, onSend }) => { color: content?.data?.position === 'right' ? 'white' : 'var(--font)', }}> - {content.text}{' '} + {' '} {content?.data?.position === 'right' ? null : !content?.data?.isEnd && }