Skip to content

Commit f232a46

Browse files
committed
Fix missing dependency error in ChatInput.js
1 parent b6fd133 commit f232a46

File tree

1 file changed

+41
-41
lines changed

1 file changed

+41
-41
lines changed

streams-react/src/components/ChatInput/ChatInput.js

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,53 @@ const ChatInput = () => {
2222
});
2323

2424
useEffect(() => {
25+
const convertInputToEmoji = (userText) => {
26+
if(!userText.length) return;
27+
const textArray = userText.split(" ");
28+
let newValues = [];
29+
30+
for(let value of textArray) {
31+
if(value[0] !== ":") {
32+
newValues.push(value);
33+
continue;
34+
}
35+
36+
let emojiArray = [];
37+
let isEmojiCode = value[value.length - 1] === ":" && value.length > 1;
38+
39+
if(isEmojiCode) value = value.replaceAll(":", "");
40+
41+
emojiArray = emojiIndex.search(value).filter(emoji => {
42+
if(!isEmojiCode && emoji.emoticons.length) {
43+
for(let emoticon of emoji.emoticons) {
44+
if(emoticon === value) return emoji.native;
45+
}
46+
}
47+
if(value === emoji.id) return emoji.native;
48+
return false
49+
});
50+
51+
if(emojiArray.length) newValues.push(emojiArray[0].native);
52+
else {
53+
newValues.push(value);
54+
}
55+
}
56+
57+
let newText = newValues.join(" ");
58+
if(newText !== userText) {
59+
const pseudoTarget = {target : {value: newText, name: "message"}};
60+
hasConvertedRef.current = true;
61+
handleChange(pseudoTarget);
62+
}
63+
};
64+
2565
if(!hasConvertedRef.current) {
2666
convertInputToEmoji(values.message);
2767
}
2868
else {
2969
hasConvertedRef.current = false;
3070
}
31-
}, [values]);
71+
}, [values, handleChange]);
3272

3373
useEffect(() => {
3474
if(showEmojis) {
@@ -66,46 +106,6 @@ const ChatInput = () => {
66106
handleAdd(pseudoTarget);
67107
};
68108

69-
const convertInputToEmoji = (userText) => {
70-
if(!userText.length) return;
71-
const textArray = userText.split(" ");
72-
let newValues = [];
73-
74-
for(let value of textArray) {
75-
if(value[0] !== ":") {
76-
newValues.push(value);
77-
continue;
78-
}
79-
80-
let emojiArray = [];
81-
let isEmojiCode = value[value.length - 1] === ":" && value.length > 1;
82-
83-
if(isEmojiCode) value = value.replaceAll(":", "");
84-
85-
emojiArray = emojiIndex.search(value).filter(emoji => {
86-
if(!isEmojiCode && emoji.emoticons.length) {
87-
for(let emoticon of emoji.emoticons) {
88-
if(emoticon === value) return emoji.native;
89-
}
90-
}
91-
if(value === emoji.id) return emoji.native;
92-
return false
93-
});
94-
95-
if(emojiArray.length) newValues.push(emojiArray[0].native);
96-
else {
97-
newValues.push(value);
98-
}
99-
}
100-
101-
let newText = newValues.join(" ");
102-
if(newText !== userText) {
103-
const pseudoTarget = {target : {value: newText, name: "message"}};
104-
hasConvertedRef.current = true;
105-
handleChange(pseudoTarget);
106-
}
107-
};
108-
109109
return(
110110
<div className={styles.container}>
111111
<div className={styles.input__container}>

0 commit comments

Comments
 (0)