Browse Source
* - format messages on didMount instead of didUpdate. will also prevent bad setSTate loops when message is blank; - convert message.js to functional comp - prevent extra rerenders in messages and chat with shouldComponentUpdate checks * revert chat test * more concise returns;pull/435/head
3 changed files with 75 additions and 37 deletions
@ -1,34 +1,31 @@ |
|||||||
import { h, Component } from '/js/web_modules/preact.js'; |
import { h } from '/js/web_modules/preact.js'; |
||||||
import htm from '/js/web_modules/htm.js'; |
import htm from '/js/web_modules/htm.js'; |
||||||
const html = htm.bind(h); |
const html = htm.bind(h); |
||||||
|
|
||||||
import ChatMessageView from './chat-message-view.js'; |
import ChatMessageView from './chat-message-view.js'; |
||||||
|
|
||||||
import { messageBubbleColorForString } from '../../utils/user-colors.js'; |
|
||||||
import { SOCKET_MESSAGE_TYPES } from '../../utils/websocket.js'; |
import { SOCKET_MESSAGE_TYPES } from '../../utils/websocket.js'; |
||||||
|
|
||||||
export default class Message extends Component { |
export default function Message(props) { |
||||||
render(props) { |
const { message } = props; |
||||||
const { message } = props; |
const { type } = message; |
||||||
const { type } = message; |
if (type === SOCKET_MESSAGE_TYPES.CHAT || type === SOCKET_MESSAGE_TYPES.SYSTEM) { |
||||||
if (type === SOCKET_MESSAGE_TYPES.CHAT || type === SOCKET_MESSAGE_TYPES.SYSTEM) { |
return html`<${ChatMessageView} ...${props} />`; |
||||||
return html`<${ChatMessageView} ...${props} />`; |
} else if (type === SOCKET_MESSAGE_TYPES.NAME_CHANGE) { |
||||||
} else if (type === SOCKET_MESSAGE_TYPES.NAME_CHANGE) { |
const { oldName, newName } = message; |
||||||
const { oldName, newName } = message; |
return ( |
||||||
return ( |
html` |
||||||
html` |
<div class="message message-name-change flex items-center justify-start p-3"> |
||||||
<div class="message message-name-change flex items-center justify-start p-3"> |
<div class="message-content flex flex-row items-center justify-center text-sm w-full"> |
||||||
<div class="message-content flex flex-row items-center justify-center text-sm w-full"> |
<div class="text-white text-center opacity-50 overflow-hidden break-words"> |
||||||
<div class="text-white text-center opacity-50 overflow-hidden break-words"> |
<span class="font-bold">${oldName}</span> is now known as <span class="font-bold">${newName}</span>. |
||||||
<span class="font-bold">${oldName}</span> is now known as <span class="font-bold">${newName}</span>. |
|
||||||
</div> |
|
||||||
</div> |
</div> |
||||||
</div> |
</div> |
||||||
` |
</div> |
||||||
); |
` |
||||||
} else { |
); |
||||||
console.log("Unknown message type:", type); |
} else { |
||||||
} |
console.log("Unknown message type:", type); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
|
Loading…
Reference in new issue