From a935944bebe7f0dcdf49d3264330572616c3f581 Mon Sep 17 00:00:00 2001
From: AlphaX-Projects <77661270+AlphaX-Projects@users.noreply.github.com>
Date: Sat, 26 Feb 2022 14:47:03 +0100
Subject: [PATCH] Seperate grid for followed websites
---
.../plugins/core/qdn/websites.src.js | 224 +++++++++++++++++-
1 file changed, 223 insertions(+), 1 deletion(-)
diff --git a/qortal-ui-plugins/plugins/core/qdn/websites.src.js b/qortal-ui-plugins/plugins/core/qdn/websites.src.js
index 644bdf67..0c44ef99 100644
--- a/qortal-ui-plugins/plugins/core/qdn/websites.src.js
+++ b/qortal-ui-plugins/plugins/core/qdn/websites.src.js
@@ -28,7 +28,10 @@ class Websites extends LitElement {
searchName: { type: String },
searchResources: { type: Array },
searchFollowedNames: { type: Array },
- searchBlockedNames: { type: Array }
+ searchBlockedNames: { type: Array },
+ webResources: { type: Array },
+ webFollowedNames: { type: Array },
+ webBlockedNames: { type: Array }
}
}
@@ -177,6 +180,9 @@ class Websites extends LitElement {
this.searchResources = []
this.searchFollowedNames = []
this.searchBlockedNames = []
+ this.webResources = []
+ this.webFollowedNames = []
+ this.webBlockedNames = []
}
render() {
@@ -224,6 +230,38 @@ class Websites extends LitElement {
+
+
Followed Websites
+
+ {
+ render(html`${this.renderWebAvatar(data.item)}`, root)
+ }}>
+
+ {
+ render(html`${this.renderWebName(data.item)}`, root)
+ }}>
+
+ {
+ render(html`${this.renderWebStatus(data.item)}`, root)
+ }}>
+
+ {
+ render(html`${this.renderWebSize(data.item)}`, root)
+ }}>
+
+ {
+ render(html`${this.renderWebFollowUnfollowButton(data.item)}`, root);
+ }}>
+
+ {
+ render(html`${this.renderWebBlockUnblockButton(data.item)}`, root);
+ }}>
+
+
+ ${this.isEmptyArray(this.webResources) ? html`
+ You not follow any website
+ `: ''}
+
Websites
@@ -284,6 +322,24 @@ class Websites extends LitElement {
setTimeout(getBlockedNames, 60000)
}
+ const getWebFollowedNames = async () => {
+ let webFollowedNames = await parentEpml.request('apiCall', {
+ url: `/lists/followedNames?apiKey=${this.getApiKey()}`
+ })
+
+ this.webFollowedNames = webFollowedNames
+ setTimeout(getWebFollowedNames, 60000)
+ }
+
+ const getWebBlockedNames = async () => {
+ let webBlockedNames = await parentEpml.request('apiCall', {
+ url: `/lists/blockedNames?apiKey=${this.getApiKey()}`
+ })
+
+ this.webBlockedNames = webBlockedNames
+ setTimeout(getWebBlockedNames, 60000)
+ }
+
const getSearchFollowedNames = async () => {
let searchFollowedNames = await parentEpml.request('apiCall', {
url: `/lists/followedNames?apiKey=${this.getApiKey()}`
@@ -338,12 +394,16 @@ class Websites extends LitElement {
parentEpml.subscribe('config', c => {
if (!configLoaded) {
setTimeout(this.getArbitraryResources, 1)
+ setTimeout(this.getFollowedWebsites, 1)
setTimeout(getFollowedNames, 1)
setTimeout(getBlockedNames, 1)
+ setTimeout(getWebFollowedNames, 1)
+ setTimeout(getWebBlockedNames, 1)
setTimeout(getSearchFollowedNames, 1)
setTimeout(getSearchBlockedNames, 1)
setTimeout(getRelayMode, 1)
setInterval(this.getArbitraryResources, 120000)
+ setInterval(this.getFollowedWebsites, 60000)
configLoaded = true
}
this.config = JSON.parse(c)
@@ -453,6 +513,168 @@ class Websites extends LitElement {
this.searchResult()
}
+ getFollowedWebsites = async () => {
+ let data = [];
+ const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node];
+ const nodeUrl = myNode.protocol + '://' + myNode.domain + ':' + myNode.port;
+ const namesUrl = `${nodeUrl}/lists/followedNames?apiKey=${this.getApiKey()}`;
+ const jsonUrl = `${nodeUrl}/arbitrary/resources?service=WEBSITE&default=true&limit=0&reverse=false&includestatus=true`;
+
+ const jsonRes = await fetch(jsonUrl);
+ const jsonData = await jsonRes.json();
+ const response = await fetch(namesUrl);
+ const names = await response.json();
+
+ let webres = jsonData.filter((elm) => names.includes(elm.name));
+
+ this.webResources = webres;
+ }
+
+ renderWebAvatar(webObj) {
+ let name = webObj.name
+ const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node]
+ const nodeUrl = myNode.protocol + '://' + myNode.domain + ':' + myNode.port
+ const url = `${nodeUrl}/arbitrary/THUMBNAIL/${name}/qortal_avatar?async=true&apiKey=${this.getApiKey()}`;
+ return html`
`
+ }
+
+ renderWebName(webObj) {
+ let name = webObj.name
+ return html`${name}`
+ }
+
+ renderWebStatus(webObj) {
+ return html`${webObj.status.title}`
+ }
+
+ renderWebSize(webObj) {
+ if (webObj.size === null) {
+ return html``
+ }
+ let sizeWebReadable = this.bytesToSize(webObj.size);
+ return html`${sizeWebReadable}`
+ }
+
+ renderWebFollowUnfollowButton(webObj) {
+ let name = webObj.name
+ if (this.webFollowedNames == null || !Array.isArray(this.webFollowedNames)) {
+ return html``
+ }
+ if (this.webFollowedNames.indexOf(name) === -1) {
+ return html` this.webFollowName(webObj)}>add_to_queue Follow`
+ }
+ else {
+ return html` this.webUnfollowName(webObj)}>remove_from_queue Unfollow`
+ }
+ }
+
+ async webFollowName(webObj) {
+ let name = webObj.name
+ let items = [
+ name
+ ]
+ let namesJsonString = JSON.stringify({ "items": items })
+ let ret = await parentEpml.request('apiCall', {
+ url: `/lists/followedNames?apiKey=${this.getApiKey()}`,
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ body: `${namesJsonString}`
+ })
+ if (ret === true) {
+ this.webFollowedNames = this.webFollowedNames.filter(item => item != name);
+ this.webFollowedNames.push(name)
+ }
+ else {
+ parentEpml.request('showSnackBar', 'Error occurred when trying to follow this registered name. Please try again')
+ }
+ return ret
+ }
+
+ async webUnfollowName(webObj) {
+ let name = webObj.name
+ let items = [
+ name
+ ]
+ let namesJsonString = JSON.stringify({ "items": items })
+ let ret = await parentEpml.request('apiCall', {
+ url: `/lists/followedNames?apiKey=${this.getApiKey()}`,
+ method: 'DELETE',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ body: `${namesJsonString}`
+ })
+ if (ret === true) {
+ this.webFollowedNames = this.webFollowedNames.filter(item => item != name);
+ }
+ else {
+ parentEpml.request('showSnackBar', 'Error occurred when trying to unfollow this registered name. Please try again')
+ }
+ return ret
+ }
+
+ renderWebBlockUnblockButton(webObj) {
+ let name = webObj.name
+ if (this.webBlockedNames == null || !Array.isArray(this.webBlockedNames)) {
+ return html``
+ }
+ if (this.webBlockedNames.indexOf(name) === -1) {
+ return html` this.webBlockName(webObj)}>block Block`
+ }
+ else {
+ return html` this.webUnblockName(webObj)}>radio_button_unchecked Unblock`
+ }
+ }
+
+ async webBlockName(webObj) {
+ let name = webObj.name
+ let items = [
+ name
+ ]
+ let namesJsonString = JSON.stringify({ "items": items })
+ let ret = await parentEpml.request('apiCall', {
+ url: `/lists/blockedNames?apiKey=${this.getApiKey()}`,
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ body: `${namesJsonString}`
+ })
+ if (ret === true) {
+ this.webBlockedNames = this.webBlockedNames.filter(item => item != name);
+ this.webBlockedNames.push(name)
+ }
+ else {
+ parentEpml.request('showSnackBar', 'Error occurred when trying to block this registered name. Please try again')
+ }
+ return ret
+ }
+
+ async webUnblockName(webObj) {
+ let name = webObj.name
+ let items = [
+ name
+ ]
+ let namesJsonString = JSON.stringify({ "items": items })
+ let ret = await parentEpml.request('apiCall', {
+ url: `/lists/blockedNames?apiKey=${this.getApiKey()}`,
+ method: 'DELETE',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ body: `${namesJsonString}`
+ })
+ if (ret === true) {
+ this.webBlockedNames = this.webBlockedNames.filter(item => item != name);
+ }
+ else {
+ parentEpml.request('showSnackBar', 'Error occurred when trying to unblock this registered name. Please try again')
+ }
+ return ret
+ }
+
async searchResult() {
let searchName = this.shadowRoot.getElementById('searchName').value
if (searchName.length === 0) {