From 4f073c7e5c0df8e8a3ac3c474b07bf2a8f1a0a2f Mon Sep 17 00:00:00 2001 From: Renard Date: Wed, 11 Mar 2020 22:40:41 -0300 Subject: Filtro de mensajes por stream --- src/Chat.js | 57 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 file 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 ( + + []{" "} + + {`${message.stream && "[" + message.stream + "]"} ${ + message.content + }`} + + + ); + }; + return ( <>
@@ -133,16 +155,15 @@ class Chat extends Component {
- {chat.map((message, i) => ( - - []{" "} - - {`${message.stream && "[" + message.stream + "]"} ${ - message.content - }`} - - - ))} + {chat.map((message, i) => + filterMessages ? ( + message.stream === stream.server_name && ( + + ) + ) : ( + + ) + )}
+ { + this.setState(prevState => ({ + filterMessages: !prevState.filterMessages + })); + }} + style={{ marginTop: "0.5em" }} + /> ); } -- cgit v1.2.1-18-gbd029