Continued UI Edit Message

This commit is contained in:
Justin Ferrari 2022-10-29 22:11:40 -05:00
parent 8f2f6caa8e
commit 02119d51d2
2 changed files with 34 additions and 18 deletions

View File

@ -53,7 +53,8 @@ class ChatPage extends LitElement {
messagesRendered: { type: Array }, messagesRendered: { type: Array },
repliedToMessageObj: { type: Object }, repliedToMessageObj: { type: Object },
editedMessageObj: { type: Object }, editedMessageObj: { type: Object },
chatMessageSize: { type: String} chatMessageSize: { type: String },
iframeHeight: { type: Number }
} }
} }
@ -63,6 +64,12 @@ class ChatPage extends LitElement {
scroll-behavior: smooth; scroll-behavior: smooth;
} }
.chat-container {
display: grid;
grid-template-rows: minmax(66%, 92vh) minmax(40px, auto);
max-height: 100%;
}
.chat-text-area { .chat-text-area {
display: flex; display: flex;
justify-content: center; justify-content: center;
@ -72,8 +79,6 @@ class ChatPage extends LitElement {
.chat-text-area .typing-area { .chat-text-area .typing-area {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
position: absolute;
bottom: 0;
width: 98%; width: 98%;
box-sizing: border-box; box-sizing: border-box;
margin-bottom: 8px; margin-bottom: 8px;
@ -90,8 +95,6 @@ class ChatPage extends LitElement {
.chat-text-area .typing-area .chat-editor { .chat-text-area .typing-area .chat-editor {
border-color: transparent; border-color: transparent;
flex: 1; flex: 1;
max-height: 40px;
height: 40px;
margin: 0; margin: 0;
padding: 0; padding: 0;
border: none; border: none;
@ -210,11 +213,12 @@ class ChatPage extends LitElement {
this.messagesRendered = [] this.messagesRendered = []
this.repliedToMessageObj = null this.repliedToMessageObj = null
this.editedMessageObj = null this.editedMessageObj = null
this.iframeHeight = 40;
} }
render() { render() {
return html` return html`
<div> <div class="chat-container">
<div> <div>
${this.isLoadingMessages ? html`<h1>${translate("chatpage.cchange22")}</h1>` : this.renderChatScroller(this._initialMessages)} ${this.isLoadingMessages ? html`<h1>${translate("chatpage.cchange22")}</h1>` : this.renderChatScroller(this._initialMessages)}
</div> </div>
@ -256,7 +260,8 @@ class ChatPage extends LitElement {
`} `}
<div class="chatbar"> <div class="chatbar">
<textarea style="color: var(--black);" tabindex='1' ?autofocus=${true} ?disabled=${this.isLoading || this.isLoadingMessages} id="messageBox" rows="1"></textarea> <textarea style="color: var(--black);" tabindex='1' ?autofocus=${true} ?disabled=${this.isLoading || this.isLoadingMessages} id="messageBox" rows="1"></textarea>
<iframe class="chat-editor" id="_chatEditorDOM" tabindex="-1"></iframe> <iframe style="${`height: ${this.iframeHeight}px`}" class="chat-editor" id="_chatEditorDOM" tabindex="-1" height=${this.iframeHeight}>
</iframe>
<button class="emoji-button" ?disabled=${this.isLoading || this.isLoadingMessages}> <button class="emoji-button" ?disabled=${this.isLoading || this.isLoadingMessages}>
${this.isLoading === false ? html`<img class="emoji" draggable="false" alt="😀" src="/emoji/svg/1f600.svg">` : html`<paper-spinner-lite active></paper-spinner-lite>`} ${this.isLoading === false ? html`<img class="emoji" draggable="false" alt="😀" src="/emoji/svg/1f600.svg">` : html`<paper-spinner-lite active></paper-spinner-lite>`}
</button> </button>
@ -281,7 +286,6 @@ class ChatPage extends LitElement {
async firstUpdated() { async firstUpdated() {
// TODO: Load and fetch messages from localstorage (maybe save messages to localstorage...) // TODO: Load and fetch messages from localstorage (maybe save messages to localstorage...)
// this.changeLanguage(); // this.changeLanguage();
this.emojiPickerHandler = this.shadowRoot.querySelector('.emoji-button'); this.emojiPickerHandler = this.shadowRoot.querySelector('.emoji-button');
this.mirrorChatInput = this.shadowRoot.getElementById('messageBox'); this.mirrorChatInput = this.shadowRoot.getElementById('messageBox');
@ -403,6 +407,16 @@ class ChatPage extends LitElement {
this.chatEditor.insertText(this.editedMessageObj.message) this.chatEditor.insertText(this.editedMessageObj.message)
} }
if (changedProperties && changedProperties.has('iframeHeight')) {
console.log({iframeHeight: this.iframeHeight})
}
}
calculateIFrameHeight(height) {
console.log(height, "height here")
this.iframeHeight = height;
this.requestUpdate();
} }
changeLanguage() { changeLanguage() {
@ -446,9 +460,6 @@ class ChatPage extends LitElement {
async getOldMessage(scrollElement) { async getOldMessage(scrollElement) {
if (this.isReceipient) { if (this.isReceipient) {
const getInitialMessages = await parentEpml.request('apiCall', { const getInitialMessages = await parentEpml.request('apiCall', {
type: 'api', type: 'api',
@ -575,9 +586,6 @@ class ChatPage extends LitElement {
} }
} }
// set replied to message in chat editor
getMessageSize(message){ getMessageSize(message){
try { try {
@ -643,6 +651,8 @@ class ChatPage extends LitElement {
} }
// set replied to message in chat editor
setRepliedToMessageObj(messageObj) { setRepliedToMessageObj(messageObj) {
this.repliedToMessageObj = {...messageObj}; this.repliedToMessageObj = {...messageObj};
this.editedMessageObj = null; this.editedMessageObj = null;
@ -821,9 +831,6 @@ class ChatPage extends LitElement {
directSocketLink = `ws://${nodeUrl}/websockets/chat/messages?involving=${window.parent.reduxStore.getState().app.selectedAddress.address}&involving=${cid}`; directSocketLink = `ws://${nodeUrl}/websockets/chat/messages?involving=${window.parent.reduxStore.getState().app.selectedAddress.address}&involving=${cid}`;
} }
const directSocket = new WebSocket(directSocketLink); const directSocket = new WebSocket(directSocketLink);
// Open Connection // Open Connection
@ -1404,6 +1411,14 @@ class ChatPage extends LitElement {
if (e.type === 'keydown') { if (e.type === 'keydown') {
console.log(editorConfig.editableElement.contentDocument.body.scrollHeight);
if (editorConfig.editableElement.contentDocument.body.scrollHeight > 40) {
editorConfig.calculateIFrameHeight(editorConfig.editableElement.contentDocument.body.scrollHeight);
} else {
editorConfig.calculateIFrameHeight(40);
};
// Handle Enter // Handle Enter
if (e.keyCode === 13 && !e.shiftKey) { if (e.keyCode === 13 && !e.shiftKey) {
@ -1484,6 +1499,7 @@ class ChatPage extends LitElement {
const editorConfig = { const editorConfig = {
getMessageSize: this.getMessageSize, getMessageSize: this.getMessageSize,
calculateIFrameHeight: this.calculateIFrameHeight,
mirrorElement: this.mirrorChatInput, mirrorElement: this.mirrorChatInput,
editableElement: this.chatMessageInput, editableElement: this.chatMessageInput,
sendFunc: this._sendMessage, sendFunc: this._sendMessage,

View File

@ -65,7 +65,7 @@ export const chatStyles = css`
.chat-list { .chat-list {
overflow-y: auto; overflow-y: auto;
overflow-x: hidden; overflow-x: hidden;
height: 92vh; height: 100%;
box-sizing: border-box; box-sizing: border-box;
} }