From e6dfa5dc35c4245ffe9f3ea6b6554689090fe7e1 Mon Sep 17 00:00:00 2001 From: Phillip Lang Martinez Date: Thu, 3 Nov 2022 18:13:24 +0200 Subject: [PATCH] file picker logic --- qortal-ui-core/language/us.json | 3 +- .../plugins/core/components/ChatPage.js | 48 ++++++++++++++++--- .../core/components/ChatScroller-css.js | 1 + .../plugins/core/components/ChatScroller.js | 10 ++-- 4 files changed, 51 insertions(+), 11 deletions(-) diff --git a/qortal-ui-core/language/us.json b/qortal-ui-core/language/us.json index a26d6f21..3e32d857 100644 --- a/qortal-ui-core/language/us.json +++ b/qortal-ui-core/language/us.json @@ -486,7 +486,8 @@ "cchange24": "Maximum Characters per message is 255", "cchange25": "Edit Message", "cchange26": "File size exceeds 5 MB", - "cchange27": "A registered name is required to send images" + "cchange27": "A registered name is required to send images", + "cchange28": "This file is not an image" }, "welcomepage": { "wcchange1": "Welcome to Q-Chat", diff --git a/qortal-ui-plugins/plugins/core/components/ChatPage.js b/qortal-ui-plugins/plugins/core/components/ChatPage.js index 382dad01..d25b29f4 100644 --- a/qortal-ui-plugins/plugins/core/components/ChatPage.js +++ b/qortal-ui-plugins/plugins/core/components/ChatPage.js @@ -210,10 +210,28 @@ class ChatPage extends LitElement { } .send-icon:hover { - cursor: pointer; filter: brightness(1.1); } + .file-picker-container { + position: relative; + height: 25px; + width: 25px; + } + .file-picker-input-container { + position: absolute; + top: 0px; + bottom: 0px; + left: 0px; + right: 0px; + z-index: 10; + opacity: 0; + overflow: hidden; + } + input[type=file]::-webkit-file-upload-button { + cursor: pointer; +} + ` } @@ -256,11 +274,12 @@ class ChatPage extends LitElement {
${this.isLoadingMessages ? html`

${translate("chatpage.cchange22")}

` : this.renderChatScroller(this._initialMessages)} - + { + this.imageFile = null + }}>
- hello ${this.imageFile && html` `} @@ -330,12 +349,23 @@ class ChatPage extends LitElement {
`}
+
this.closeEditMessageContainer()} - > + > + +
+ +
+ +
+ @@ -376,13 +406,19 @@ class ChatPage extends LitElement { insertImage(file){ - this.imageFile = file + if(file.type.includes('image')){ + this.imageFile = file + + return + } + + parentEpml.request('showSnackBar', get("chatpage.cchange28")) } - + async firstUpdated() { // TODO: Load and fetch messages from localstorage (maybe save messages to localstorage...) diff --git a/qortal-ui-plugins/plugins/core/components/ChatScroller-css.js b/qortal-ui-plugins/plugins/core/components/ChatScroller-css.js index c8b45432..463c6469 100644 --- a/qortal-ui-plugins/plugins/core/components/ChatScroller-css.js +++ b/qortal-ui-plugins/plugins/core/components/ChatScroller-css.js @@ -371,5 +371,6 @@ export const chatStyles = css` display: flex; justify-content: center; align-items: center; + height: 80vh; } ` diff --git a/qortal-ui-plugins/plugins/core/components/ChatScroller.js b/qortal-ui-plugins/plugins/core/components/ChatScroller.js index b9870e10..00f83554 100644 --- a/qortal-ui-plugins/plugins/core/components/ChatScroller.js +++ b/qortal-ui-plugins/plugins/core/components/ChatScroller.js @@ -256,7 +256,6 @@ class MessageTemplate extends LitElement { imageHTMLRes.onclick= ()=> { this.openDialogImage = true } - let p = 0 imageHTMLRes.onerror = ()=> { console.log('inputRef', this.imageFetches) @@ -270,8 +269,10 @@ class MessageTemplate extends LitElement { } else { imageHTMLRes.src = '/img/chain.png' - imageHTMLRes.style= "max-width:45vh; max-height:40vh; border-radius: 5px; filter: opacity(0.5)" - ; + imageHTMLRes.style= "max-width:45vh; max-height:20vh; border-radius: 5px; filter: opacity(0.5)"; + imageHTMLRes.onclick= ()=> { + + } } } @@ -287,8 +288,9 @@ class MessageTemplate extends LitElement { imageUrl = `${nodeUrl}/arbitrary/${image.service}/${image.name}/${image.identifier}?async=true&apiKey=${myNode.apiKey}` imageHTML = createImage(imageUrl) imageHTMLDialog = createImage(imageUrl) - imageHTMLDialog.style= "height: 80vh ; width: auto; max-width: 80vw; object-fit: contain; border-radius: 5px" + imageHTMLDialog.style= "height: auto; max-height: 80vh; width: auto; max-width: 80vw; object-fit: contain; border-radius: 5px" } + if (this.messageObj.sender === this.myAddress) {