Skip to content

Commit

Permalink
fix: Minor bug fixes for setting character count
Browse files Browse the repository at this point in the history
  • Loading branch information
tjtanjin committed Jan 28, 2024
1 parent e13f0da commit 20c4ead
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
22 changes: 10 additions & 12 deletions src/components/ChatBotInput/ChatBotInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,15 @@ const ChatBotInput = ({
return;
}

const characterLimit = botOptions.chatInput?.characterLimit
if (characterLimit != null && characterLimit > 0) {
if (inputRef.current && inputRef.current.value.length > characterLimit) {
inputRef.current.value = inputRef.current.value.slice(0, characterLimit);
setInputLength(inputRef.current.value.length);
return;
}
}

if (inputRef.current) {
const characterLimit = botOptions.chatInput?.characterLimit
const newInput = event.target.value.replace(/\n/g, " ");
if (characterLimit != null && characterLimit > 0 && newInput.length > characterLimit) {
inputRef.current.value = newInput.slice(0, characterLimit);
} else {
inputRef.current.value = newInput
}
setInputLength(inputRef.current.value.length);
inputRef.current.value = event.target.value.replace(/\n/g, " ");
}
};

Expand Down Expand Up @@ -181,8 +178,9 @@ const ChatBotInput = ({
/>
<div className="rcb-chat-input-button-container">
{!botOptions.voice?.disabled && isDesktop &&
<VoiceButton inputRef={inputRef} textAreaDisabled={textAreaDisabled} voiceToggledOn={voiceToggledOn}
handleToggleVoice={handleToggleVoice} triggerSendVoiceInput={triggerSendVoiceInput} setInputLength={setInputLength}
<VoiceButton inputRef={inputRef} textAreaDisabled={textAreaDisabled}
voiceToggledOn={voiceToggledOn} handleToggleVoice={handleToggleVoice}
triggerSendVoiceInput={triggerSendVoiceInput} setInputLength={setInputLength}
/>
}
<SendButton handleSubmit={handleSubmit}/>
Expand Down
13 changes: 6 additions & 7 deletions src/services/VoiceService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ let toggleOn = false;
* @param inputRef reference to textarea for input
*/
export const startVoiceRecording = (botOptions: Options, handleToggleVoice: () => void,
triggerSendVoiceInput: () => void, setInputLength: Dispatch<SetStateAction<number>>, inputRef: RefObject<HTMLTextAreaElement>) => {
triggerSendVoiceInput: () => void, setInputLength: Dispatch<SetStateAction<number>>,
inputRef: RefObject<HTMLTextAreaElement>) => {

if (recognition == null) {
return;
Expand All @@ -44,12 +45,10 @@ export const startVoiceRecording = (botOptions: Options, handleToggleVoice: () =
if (inputRef.current) {
const characterLimit = botOptions.chatInput?.characterLimit
const newInput = inputRef.current.value + voiceInput;
if (characterLimit != null && characterLimit > 0) {
if (newInput.length > characterLimit) {
inputRef.current.value = newInput.slice(0, characterLimit);
} else {
inputRef.current.value = newInput
}
if (characterLimit != null && characterLimit > 0 && newInput.length > characterLimit) {
inputRef.current.value = newInput.slice(0, characterLimit);
} else {
inputRef.current.value = newInput
}
setInputLength(inputRef.current.value.length);
}
Expand Down

0 comments on commit 20c4ead

Please sign in to comment.