Skip to content

Commit 32dd5ac

Browse files
committed
Fix Emoji Bugs
1 parent 7feba09 commit 32dd5ac

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

src/App/Components/Chat/Chat.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function Chat(props: any) {
2020
let messageHistory = []
2121

2222
for (const message of channel.MessageHistory) {
23-
messageHistory.push(<Message Message={message} />)
23+
messageHistory.push(<Message Message={message} key={message.Id} />)
2424
}
2525

2626
return (
@@ -29,7 +29,7 @@ function Chat(props: any) {
2929
<defs>
3030
<filter id="colorFilter">
3131
<feColorMatrix
32-
color-interpolation-filters="sRGB"
32+
colorInterpolationFilters="sRGB"
3333
type="matrix"
3434
values="0.12 0 0 0 0
3535
0 0.10 0 0 0

src/App/Components/Chat/Components/ChatInput/ChatInput.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useState } from "react";
22

33
import "./ChatInput.scss";
44
import OutsideClickHandler from "react-outside-click-handler";
5-
import { Picker, Emoji } from "emoji-mart";
5+
import { Picker, Emoji, EmojiData } from "emoji-mart";
66
import { SiteStateStore } from "../../../../../Shared/Globals";
77
import { SendMessage } from "../../../../../Shared/Actions/ServerActions";
88

@@ -19,12 +19,26 @@ function OnSubmitChatMessage(e: React.FormEvent<HTMLFormElement>) {
1919
textInput.value = "";
2020
}
2121

22+
function EmojiSelected(setState: any, emoji: EmojiData)
23+
{
24+
const textInput = document.getElementsByClassName("chatInput")[0].children[0] as HTMLInputElement;
25+
26+
setState({
27+
IsPicking: false
28+
});
29+
30+
textInput.value = textInput.value.trimEnd();
31+
textInput.value += " " + emoji.colons + " ";
32+
33+
textInput.focus();
34+
}
35+
2236
function ChatInput() {
2337
const [state, setState] = useState({
2438
IsPicking: false
2539
});
2640

27-
const picker = <Picker autoFocus={true} set="twitter" title="Select an Emoji..." />
41+
const picker = <Picker autoFocus={true} set="twitter" title="Select an Emoji..." onSelect={e => EmojiSelected(setState, e)} />
2842

2943
return (
3044
<div id="ChatInput" >

src/App/Components/Chat/Components/Message/Message.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
position: relative;
6363

6464
top: 27.5px;
65-
65+
6666
font-size: .9em;
6767
color: rgb(173, 173, 173);
6868
}

src/App/Components/Chat/Components/Message/Message.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ function Message(props: MessageProps) {
1818

1919
let lastOffset = 0;
2020
let match = regex.exec(props.Message.Message);
21-
2221
while (match) {
2322
const previousText = props.Message.Message.substring(
2423
lastOffset,
2524
match.index
2625
);
2726

2827
if (previousText.length)
29-
msg.push(<span className="msgPart">{previousText}</span>);
28+
msg.push(<span className="msgPart" key={match.index + previousText}>{previousText}</span>);
3029

3130
lastOffset = match.index + match[0].length;
3231

@@ -38,13 +37,14 @@ function Message(props: MessageProps) {
3837
return emoji ? `:${emoji.short_names[0]}:` : props.emoji
3938
}) as any}
4039
size={22}
40+
key={match.index + lastOffset}
4141
/>
4242
);
4343

4444
if (emoji) {
4545
msg.push(emoji);
4646
} else {
47-
msg.push(<span className="msgPart">{match[0]}</span>);
47+
msg.push(<span key={match.index + match[0]} className="msgPart">{match[0]}</span>);
4848
}
4949

5050
match = regex.exec(props.Message.Message);
@@ -53,7 +53,7 @@ function Message(props: MessageProps) {
5353
}
5454

5555
if (lastOffset === 0)
56-
msg.push(<span className="msgPart">{props.Message.Message}</span>);
56+
msg.push(<span className="msgPart" key={props.Message.Message}>{props.Message.Message}</span>);
5757

5858
return (
5959
<div id="Message" >

0 commit comments

Comments
 (0)