From e1e43656921c2f6c60928e20b3bfbe08aefd4455 Mon Sep 17 00:00:00 2001 From: Ginger Wong Date: Thu, 13 Aug 2020 02:08:14 -0700 Subject: [PATCH] integrate message comp --- webroot/js/chat/chat.js | 38 +++++-------------- webroot/js/chat/message.js | 2 +- ...essageTypes.js => socket-message-types.js} | 0 3 files changed, 11 insertions(+), 29 deletions(-) rename webroot/js/utils/{socketMessageTypes.js => socket-message-types.js} (100%) diff --git a/webroot/js/chat/chat.js b/webroot/js/chat/chat.js index 280abafef..bc000bade 100644 --- a/webroot/js/chat/chat.js +++ b/webroot/js/chat/chat.js @@ -3,8 +3,8 @@ import htm from 'https://unpkg.com/htm?module'; // Initialize htm with Preact const html = htm.bind(h); -import SOCKET_MESSAGE_TYPES from '../utils/socketMessageTypes.js'; - +import SOCKET_MESSAGE_TYPES from '../utils/socket-message-types.js'; +import Message from './message.js'; export default class Chat extends Component { constructor(props, context) { @@ -47,37 +47,19 @@ export default class Chat extends Component { this.send(nameChange); } - render() { - const { username, userAvatarImage } = this.state; + render(props, state) { + const { username, userAvatarImage } = props; + const { messages } = state; + return ( html`
- messages... - + ${ + messages.map(message => (html`<${Message} message=${message} />`)) + } + messages..
diff --git a/webroot/js/chat/message.js b/webroot/js/chat/message.js index e3f38dda2..90105091a 100644 --- a/webroot/js/chat/message.js +++ b/webroot/js/chat/message.js @@ -6,7 +6,7 @@ const html = htm.bind(h); import { messageBubbleColorForString } from '../utils/user-colors.js'; import { formatMessageText } from '../utils/chat.js'; import { generateAvatar } from '../utils.js'; -import SOCKET_MESSAGE_TYPES from './chat/socket-message-types.js'; +import SOCKET_MESSAGE_TYPES from '../utils/socket-message-types.js'; export default class Message extends Component { render(props) { diff --git a/webroot/js/utils/socketMessageTypes.js b/webroot/js/utils/socket-message-types.js similarity index 100% rename from webroot/js/utils/socketMessageTypes.js rename to webroot/js/utils/socket-message-types.js