aboutsummaryrefslogtreecommitdiff
path: root/src/Chat.js
diff options
context:
space:
mode:
authorLibravatar Renard 2020-03-11 22:40:41 -0300
committerLibravatar Renard 2020-03-11 22:40:41 -0300
commit4f073c7e5c0df8e8a3ac3c474b07bf2a8f1a0a2f (patch)
tree3d249f86dafa7423e1bd3f6917e723dae217dee3 /src/Chat.js
parent524a30b69d5853878200fa41af55020f76b65f1b (diff)
downloadbairadio-app-4f073c7e5c0df8e8a3ac3c474b07bf2a8f1a0a2f.tar.gz
bairadio-app-4f073c7e5c0df8e8a3ac3c474b07bf2a8f1a0a2f.tar.xz
bairadio-app-4f073c7e5c0df8e8a3ac3c474b07bf2a8f1a0a2f.zip
Filtro de mensajes por stream
Diffstat (limited to 'src/Chat.js')
-rw-r--r--src/Chat.js57
1 files changed, 44 insertions, 13 deletions
diff --git a/src/Chat.js b/src/Chat.js
index 7f74a27..4117183 100644
--- a/src/Chat.js
+++ b/src/Chat.js
@@ -1,6 +1,6 @@
import React, { Component } from "react";
import { w3cwebsocket as W3CWebSocket } from "websocket";
-import { Header, List, Input } from "semantic-ui-react";
+import { Header, List, Input, Checkbox } from "semantic-ui-react";
import Moment from "react-moment";
import "moment/locale/es";
@@ -11,7 +11,8 @@ class Chat extends Component {
chat: [],
chatMessage: "",
chatUserCount: 0,
- isChatOnline: false
+ isChatOnline: false,
+ filterMessages: false
};
this.client = {};
this.chatColors = [
@@ -124,7 +125,28 @@ class Chat extends Component {
}
render() {
- const { chat, chatMessage, chatUserCount, isChatOnline } = this.state;
+ const {
+ chat,
+ chatMessage,
+ chatUserCount,
+ isChatOnline,
+ filterMessages
+ } = this.state;
+ const { stream } = this.props;
+
+ const MessageItem = ({ message, index }) => {
+ return (
+ <List.Item key={index}>
+ [<Moment format="HH:mm:ss" date={message.timestamp} />]{" "}
+ <span className={`ui text ${message.color}`}>
+ {`${message.stream && "[" + message.stream + "]"} ${
+ message.content
+ }`}
+ </span>
+ </List.Item>
+ );
+ };
+
return (
<>
<Header as="h3">
@@ -133,16 +155,15 @@ class Chat extends Component {
</Header>
<div id="chatContainer">
<List>
- {chat.map((message, i) => (
- <List.Item key={i}>
- [<Moment format="HH:mm:ss" date={message.timestamp} />]{" "}
- <span className={`ui text ${message.color}`}>
- {`${message.stream && "[" + message.stream + "]"} ${
- message.content
- }`}
- </span>
- </List.Item>
- ))}
+ {chat.map((message, i) =>
+ filterMessages ? (
+ message.stream === stream.server_name && (
+ <MessageItem message={message} index={i} />
+ )
+ ) : (
+ <MessageItem message={message} index={i} />
+ )
+ )}
</List>
</div>
<Input
@@ -168,6 +189,16 @@ class Chat extends Component {
}}
disabled={!isChatOnline}
/>
+ <Checkbox
+ checked={filterMessages}
+ label="Filtrar mensajes de usuarios escuchando stream actual"
+ onClick={() => {
+ this.setState(prevState => ({
+ filterMessages: !prevState.filterMessages
+ }));
+ }}
+ style={{ marginTop: "0.5em" }}
+ />
</>
);
}