From d8464855b68de7b5d96fc58e257158edefcc4244 Mon Sep 17 00:00:00 2001 From: AlphaX-Projects <77661270+AlphaX-Projects@users.noreply.github.com> Date: Tue, 5 Apr 2022 07:54:26 -0700 Subject: [PATCH] Add files via upload --- .../plugins/core/components/BlockAddress.js | 103 ++++++++++++++++++ .../plugins/core/components/ChatMessage.js | 2 +- .../plugins/core/components/ChatPage.js | 19 +++- .../plugins/core/components/ChatScroller.js | 70 +++++++----- .../core/components/ChatWelcomePage.js | 15 ++- .../plugins/core/components/snackbar.js | 84 ++++++++++++++ 6 files changed, 260 insertions(+), 33 deletions(-) create mode 100644 qortal-ui-plugins/plugins/core/components/BlockAddress.js create mode 100644 qortal-ui-plugins/plugins/core/components/snackbar.js diff --git a/qortal-ui-plugins/plugins/core/components/BlockAddress.js b/qortal-ui-plugins/plugins/core/components/BlockAddress.js new file mode 100644 index 00000000..006ad246 --- /dev/null +++ b/qortal-ui-plugins/plugins/core/components/BlockAddress.js @@ -0,0 +1,103 @@ +import { LitElement, html, css } from 'lit' +import { render } from 'lit/html.js' +import { Epml } from '../../../epml.js' +import snackbar from './snackbar.js' + +import '@material/mwc-button' +import '@material/mwc-dialog' +import '@material/mwc-icon' +import '@material/mwc-snackbar' + +const parentEpml = new Epml({ type: 'WINDOW', source: window.parent }) + +class BlockAddress extends LitElement { + static get properties() { + return { + toblockaddress: { type: String, attribute: true }, + chatBlockedAdresses: { type: Array } + } + } + + static get styles() { + return css` + * { + --mdc-theme-primary: rgb(3, 169, 244); + --mdc-theme-secondary: var(--mdc-theme-primary); + --mdc-dialog-content-ink-color: var(--black); + --mdc-theme-surface: var(--white); + --mdc-theme-text-primary-on-background: var(--black); + } + ` + } + + constructor() { + super() + this.chatBlockedAdresses = [] + } + + render() { + return html` + + ` + } + + firstUpdated() { + this.getChatBlockedAdresses() + + setInterval(() => { + this.getChatBlockedAdresses(); + }, 60000) + } + + updated(changedProps) { + } + + async getChatBlockedAdresses() { + const chatBlockedAdresses = await parentEpml.request('apiCall', { + url: `/lists/blockedAddresses?apiKey=${this.getApiKey()}` + }) + this.chatBlockedAdresses = chatBlockedAdresses + } + + async chatBlockAddress() { + let address = this.toblockaddress + + let items = [ + address + ] + + let addressJsonString = JSON.stringify({ "items": items }) + + let ret = await parentEpml.request('apiCall', { + url: `/lists/blockedAddresses?apiKey=${this.getApiKey()}`, + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: `${addressJsonString}` + }) + + if (ret === true) { + this.chatBlockedAdresses = this.chatBlockedAdresses.filter(item => item != address) + this.chatBlockedAdresses.push(address) + snackbar.add({ + labelText: `Success blocked this user.`, + dismiss: true + }) + } else { + snackbar.add({ + labelText: `Error occurred when trying to block this user. Please try again.`, + dismiss: true + }) + } + return ret + } + + getApiKey() { + const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node]; + let apiKey = myNode.apiKey; + return apiKey; + } +} + +window.customElements.define('block-address', BlockAddress) diff --git a/qortal-ui-plugins/plugins/core/components/ChatMessage.js b/qortal-ui-plugins/plugins/core/components/ChatMessage.js index 774daade..502ee87e 100644 --- a/qortal-ui-plugins/plugins/core/components/ChatMessage.js +++ b/qortal-ui-plugins/plugins/core/components/ChatMessage.js @@ -99,7 +99,7 @@ class ChatMessage extends LitElement { ${this.message.sender}   10:10 AM, Today -
+
${this.message.decodedMessage}
diff --git a/qortal-ui-plugins/plugins/core/components/ChatPage.js b/qortal-ui-plugins/plugins/core/components/ChatPage.js index 486c8f11..6e609b51 100644 --- a/qortal-ui-plugins/plugins/core/components/ChatPage.js +++ b/qortal-ui-plugins/plugins/core/components/ChatPage.js @@ -1,13 +1,19 @@ import { LitElement, html, css } from 'lit' +import { render } from 'lit/html.js' import { Epml } from '../../../epml.js' import { escape, unescape } from 'html-escaper'; import { inputKeyCodes } from '../../utils/keyCodes.js' import './ChatScroller.js' +import './BlockAddress.js' import './TimeAgo.js' import { EmojiPicker } from 'emoji-picker-js'; import '@polymer/paper-spinner/paper-spinner-lite.js' +import '@material/mwc-button' +import '@material/mwc-dialog' +import '@material/mwc-icon' + const parentEpml = new Epml({ type: 'WINDOW', source: window.parent }) class ChatPage extends LitElement { @@ -120,15 +126,11 @@ class ChatPage extends LitElement { } render() { - - // TODO: Build a nice preloader for loading messages... return html` ${this.isLoadingMessages ? html`

Loading Messages...

` : this.renderChatScroller(this._initialMessages)} -
-
- +
@@ -292,7 +293,6 @@ class ChatWelcomePage extends LitElement { } _sendMessage() { - this.isLoading = true const recipient = this.shadowRoot.getElementById('sendTo').value @@ -465,6 +465,17 @@ class ChatWelcomePage extends LitElement { _textArea(e) { if (e.keyCode === 13 && !e.shiftKey) this._sendMessage() } + + isEmptyArray(arr) { + if (!arr) { return true } + return arr.length === 0 + } + + getApiKey() { + const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node]; + let apiKey = myNode.apiKey; + return apiKey; + } } window.customElements.define('chat-welcome-page', ChatWelcomePage) diff --git a/qortal-ui-plugins/plugins/core/components/snackbar.js b/qortal-ui-plugins/plugins/core/components/snackbar.js new file mode 100644 index 00000000..6604d72c --- /dev/null +++ b/qortal-ui-plugins/plugins/core/components/snackbar.js @@ -0,0 +1,84 @@ +import { LitElement, html, css } from 'lit' +import '@material/mwc-snackbar' + +let queueElement + +class SnackQueue extends LitElement { + static get properties() { + return { + busy: { + type: Boolean, + attribute: 'busy', + reflectToAttribute: true + }, + currentSnack: { + type: Object, + attribute: 'current-snack', + reflectToAttribute: true + }, + _queue: { + type: Array + }, + _labelText: { type: String }, + _stacked: { type: Boolean }, + _leading: { type: Boolean }, + _closeOnEscape: { type: Boolean }, + _timeoutMs: { type: Number }, + action: {}, + _dismiss: {}, + _dismissIcon: { type: String } + } + } + + static get styles() { + return css`` + } + + constructor() { + super() + this._queue = [] + this.busy = false + this._timeoutMs = 5000 + } + + render() { + return html` + + ${this._action} + ${this._dismiss ? html` + + ` : ''} + + ` + } + + firstUpdated() { + this._snackbar = this.shadowRoot.getElementById('snack') + } + + _shift() { + if (this.busy || this._queue.length === 0) return + const item = this._queue.shift() + this._labelText = item.labelText || '' + this._action = item.action || '' + this._dismiss = item.dismiss || false + this._dismissIcon = item.dismissIcon || 'close' + this._leading = !!item.leading + this._closeOnEscape = (item.closeOnEscape && item.closeOnEscape !== false) // JSON.parse maybe needs to be compared to 'false'...in which case no need for complex expression + this._timeoutMs = (item.timeoutMs >= 4000 && item.timeoutMs <= 10000) ? item.timeoutMs : 5000 + this._snackbar.show() + } + + add(item) { + this._queue.push(item) + this._shift() + } +} + +window.customElements.define('snack-queue', SnackQueue) + +const queueNode = document.createElement('snack-queue') +queueNode.id = 'queue-node' +queueNode.loadingMessage = '' +queueElement = document.body.appendChild(queueNode) +export default queueElement