make edits for a messages-only view of the chat module

This commit is contained in:
Ginger Wong
2020-08-19 00:16:35 -07:00
parent ebc852b430
commit d7b8058264
5 changed files with 135 additions and 101 deletions

View File

@@ -18,6 +18,7 @@ export default class ChatInput extends Component {
constructor(props, context) { constructor(props, context) {
super(props, context); super(props, context);
this.formMessageInput = createRef(); this.formMessageInput = createRef();
this.emojiPickerButton = createRef();
this.messageCharCount = 0; this.messageCharCount = 0;
this.maxMessageLength = 500; this.maxMessageLength = 500;
@@ -65,10 +66,7 @@ export default class ChatInput extends Component {
custom: json, custom: json,
initialCategory: 'custom', initialCategory: 'custom',
showPreview: false, showPreview: false,
position: { position: 'top'
top: '50%',
right: '100'
},
}); });
this.emojiPicker.on('emoji', emoji => { this.emojiPicker.on('emoji', emoji => {
this.handleEmojiSelected(emoji); this.handleEmojiSelected(emoji);
@@ -81,7 +79,7 @@ export default class ChatInput extends Component {
handleEmojiButtonClick() { handleEmojiButtonClick() {
if (this.emojiPicker) { if (this.emojiPicker) {
this.emojiPicker.togglePicker(this.emojiPicker); this.emojiPicker.togglePicker(this.emojiPickerButton.current);
} }
} }
@@ -253,20 +251,26 @@ export default class ChatInput extends Component {
onPaste=${this.handlePaste} onPaste=${this.handlePaste}
/> />
<button
type="button"
style=${emojiButtonStyle}
onclick=${this.handleEmojiButtonClick}
>😏</button>
<div id="message-form-actions" class="flex"> <div id="message-form-actions" class="flex">
<span id="message-form-warning" class="text-red-600 text-xs">${inputWarning}</span> <span id="message-form-warning" class="text-red-600 text-xs">${inputWarning}</span>
<button
onclick=${this.handleSubmitChatButton} <div id="message-form-actions-buttons" class="flex">
type="button" <button
id="button-submit-message" ref=${this.emojiPickerButton}
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-1 px-2 rounded" id="emoji-button"
> Chat type="button"
</button> style=${emojiButtonStyle}
onclick=${this.handleEmojiButtonClick}
>😏</button>
<button
onclick=${this.handleSubmitChatButton}
type="button"
id="button-submit-message"
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-1 px-2 rounded"
> Chat
</button>
</div>
</div> </div>
</div> </div>
`); `);

View File

@@ -128,18 +128,6 @@ export default class Chat extends Component {
this.disableChat() this.disableChat()
} }
// handleSubmitChatButton(event) {
// const { inputValue } = this.state;
// var value = inputValue.trim();
// if (value) {
// this.submitChat(value);
// event.preventDefault();
// return false;
// }
// event.preventDefault();
// return false;
// }
submitChat(content) { submitChat(content) {
if (!content) { if (!content) {
return; return;
@@ -186,18 +174,26 @@ export default class Chat extends Component {
render(props, state) { render(props, state) {
const { username } = props; const { username, messagesOnly } = props;
const { messages, inputEnabled, chatUserNames } = state; const { messages, inputEnabled, chatUserNames } = state;
const messageList = messages.map((message) => (html`<${Message} message=${message} username=${username} key=${message.id} />`));
if (messagesOnly) {
return (
html`
<div id="messages-container">
${messageList}
</div>
`);
}
return ( return (
html` html`
<section id="chat-container-wrap" class="flex"> <section id="chat-container-wrap" class="flex">
<div id="chat-container" class="bg-gray-800"> <div id="chat-container" class="bg-gray-800">
<div id="messages-container"> <div id="messages-container">
${ ${messageList}
messages.map(message => (html`<${Message} message=${message} username=${username} />`))
}
messages..
</div> </div>
<${ChatInput} <${ChatInput}
chatUserNames=${chatUserNames} chatUserNames=${chatUserNames}

View File

@@ -1,4 +1,8 @@
import { html, Component } from "https://unpkg.com/htm/preact/index.mjs?module"; import { h, Component, Fragment } from 'https://unpkg.com/preact?module';
import htm from 'https://unpkg.com/htm?module';
const html = htm.bind(h);
import UsernameForm from './username.js'; import UsernameForm from './username.js';
import Chat from './chat.js'; import Chat from './chat.js';
import Websocket from '../websocket.js'; import Websocket from '../websocket.js';
@@ -33,10 +37,26 @@ export default class StandaloneChat extends Component {
} }
render(props, state) { render(props, state) {
const { messagesOnly } = props;
const { username, userAvatarImage, websocket } = state; const { username, userAvatarImage, websocket } = state;
if (messagesOnly) {
return (
html`
<${Chat}
websocket=${websocket}
username=${username}
userAvatarImage=${userAvatarImage}
chatEnabled
messagesOnly
/>
`);
}
return ( return (
html` html`
<div class="flex"> <${Fragment}>
<${UsernameForm} <${UsernameForm}
username=${username} username=${username}
userAvatarImage=${userAvatarImage} userAvatarImage=${userAvatarImage}
@@ -50,7 +70,7 @@ export default class StandaloneChat extends Component {
userAvatarImage=${userAvatarImage} userAvatarImage=${userAvatarImage}
chatEnabled chatEnabled
/> />
</div> </${Fragment}>
`); `);
} }

View File

@@ -4,7 +4,7 @@
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"/> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"/>
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet" /> <link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet" />
<link href="./styles/layout.css" rel="stylesheet" /> <!-- <link href="./styles/layout.css" rel="stylesheet" /> -->
<link href="./styles/chat.css" rel="stylesheet" /> <link href="./styles/chat.css" rel="stylesheet" />
<link href="./styles/standalone-chat.css" rel="stylesheet" /> <link href="./styles/standalone-chat.css" rel="stylesheet" />
@@ -20,8 +20,11 @@
<script type="module"> <script type="module">
import { render, html } from "https://unpkg.com/htm/preact/index.mjs?module"; import { render, html } from "https://unpkg.com/htm/preact/index.mjs?module";
import StandaloneChat from './js/chat/standalone.js'; import StandaloneChat from './js/chat/standalone.js';
const messagesOnly = true;
(function () { (function () {
render(html`<${StandaloneChat} />`, document.getElementById("chat-container")); render(html`<${StandaloneChat} messagesOnly=${messagesOnly} />`, document.getElementById("chat-container"));
})(); })();
</script> </script>
</body> </body>

View File

@@ -3,6 +3,7 @@
overflow: auto; overflow: auto;
padding: 1em 0; padding: 1em 0;
} }
#message-input-container { #message-input-container {
width: 100%; width: 100%;
padding: 1em; padding: 1em;
@@ -13,22 +14,8 @@
align-items: flex-end; align-items: flex-end;
margin-bottom: 0; margin-bottom: 0;
} }
#message-body-form {
font-size: 1em;
height: 60px;
}
#message-body-form:disabled{
opacity: .5;
}
#message-body-form img {
display: inline;
padding-left: 5px;
padding-right: 5px;
}
#message-body-form .emoji {
width: 40px;
}
#message-form-actions { #message-form-actions {
flex-direction: row; flex-direction: row;
@@ -37,16 +24,22 @@
width: 100%; width: 100%;
} }
.message-text img { #message-form-actions-buttons {
display: inline; flex-direction: row;
padding-left: 5px; justify-content: flex-end;
padding-right: 5px; align-items: center;
} }
.message-text .emoji { /* Emoji picker button */
width: 60px; #emoji-button {
font-size: 1.75em;
cursor: pointer;
margin-right: .5em;
} }
.emoji-picker__wrapper {}
.message { .message {
@@ -68,13 +61,37 @@
max-width: 85%; max-width: 85%;
word-wrap: break-word; word-wrap: break-word;
} }
.message-content a {
/* MESSAGE TEXT CONTENT */
/* MESSAGE TEXT CONTENT */
/* MESSAGE TEXT CONTENT */
.message-text a {
color: #7F9CF5; /* indigo-400 */ color: #7F9CF5; /* indigo-400 */
} }
.message-content a:hover { .message-text a:hover {
text-decoration: underline; text-decoration: underline;
} }
.message-text img {
display: inline;
padding-left: 5px;
padding-right: 5px;
}
.message-text code {
background-color:darkslategrey;
padding: 3px;
}
.message-text .emoji {
width: 60px;
}
.message-text iframe { .message-text iframe {
width: 100%; width: 100%;
@@ -86,57 +103,27 @@
height: 314px; height: 314px;
} }
.message-text code {
background-color:darkslategrey;
padding: 3px;
}
/* Emoji picker */
#emoji-button {
position: relative;
top: -65px;
right: 10px;
cursor: pointer;
}
.message-text .embedded-image { .message-text .embedded-image {
width: 100%; width: 100%;
height: 170px; height: 170px;
border-radius: 15px; border-radius: 15px;
} }
.message-text code {
background-color:darkslategrey;
padding: 3px;
}
/* Emoji picker */
#emoji-button {
position: relative;
top: -65px;
right: 10px;
cursor: pointer;
}
.message-text .embedded-image {
width: 100%;
height: 170px;
border-radius: 15px;
}
.message-text code {
background-color:darkslategrey;
padding: 3px;
}
.message-text .highlighted { .message-text .highlighted {
color: orange; color: orange;
font-weight: 400; font-weight: 400;
font-size: 14px; font-size: 14px;
} }
/* MESSAGE TEXT CONTENT */
/* MESSAGE TEXT CONTENT */
/* MESSAGE TEXT CONTENT */
/* MESSAGE TEXT CONTENT */
.message-text code {
background-color:darkslategrey;
padding: 3px;
}
/* /*
The chat input has a fake placeholder that is styled below. The chat input has a fake placeholder that is styled below.
@@ -144,6 +131,30 @@ It pulls the placeholder text from the div's placeholder attribute.
But really it's just the innerHTML content. But really it's just the innerHTML content.
*/ */
#message-body-form {
font-size: 1em;
height: 60px;
}
#message-body-form:disabled{
opacity: .5;
}
#message-body-form img {
display: inline;
padding-left: 5px;
padding-right: 5px;
}
#message-body-form .emoji {
width: 40px;
}
/* If the div is empty then show the placeholder */ /* If the div is empty then show the placeholder */
#message-body-form:empty:before{ #message-body-form:empty:before{
content: attr(placeholder); content: attr(placeholder);