mirror of
https://github.com/Qortal/qortal-ui.git
synced 2025-02-11 17:55:51 +00:00
reduce api calls on websites
This commit is contained in:
parent
0215bd0779
commit
0eca538ddd
@ -338,11 +338,7 @@ class Websites extends LitElement {
|
||||
}}>
|
||||
</vaadin-grid-column>
|
||||
<vaadin-grid-column width="11rem" flex-grow="0" header="${translate("websitespage.schange8")}" .renderer=${(root, column, data) => {
|
||||
render(html`${this.renderFollowUnfollowButton(data.item)}`, root);
|
||||
}}>
|
||||
</vaadin-grid-column>
|
||||
<vaadin-grid-column width="11rem" flex-grow="0" header="" .renderer=${(root, column, data) => {
|
||||
render(html`${this.renderBlockUnblockButton(data.item)}`, root);
|
||||
render(html`${this.renderFollowUnfollowButtonTab(data.item)}`, root);
|
||||
}}>
|
||||
</vaadin-grid-column>
|
||||
</vaadin-grid>
|
||||
@ -375,12 +371,8 @@ class Websites extends LitElement {
|
||||
render(html`${this.renderPublishedBy(data.item)}`, root)
|
||||
}}>
|
||||
</vaadin-grid-column>
|
||||
<vaadin-grid-column width="11rem" flex-grow="0" header="${translate("websitespage.schange8")}" .renderer=${(root, column, data) => {
|
||||
render(html`${this.renderFollowUnfollowButton(data.item)}`, root);
|
||||
}}>
|
||||
</vaadin-grid-column>
|
||||
<vaadin-grid-column width="11rem" flex-grow="0" header="" .renderer=${(root, column, data) => {
|
||||
render(html`${this.renderBlockUnblockButton(data.item)}`, root);
|
||||
render(html`${this.renderBlockUnblockButtonTab(data.item)}`, root);
|
||||
}}>
|
||||
</vaadin-grid-column>
|
||||
</vaadin-grid>
|
||||
@ -479,7 +471,7 @@ class Websites extends LitElement {
|
||||
setTimeout(getRelayMode, 1)
|
||||
setTimeout(this.getFollowedNamesResource, 1)
|
||||
setTimeout(this.getBlockedNamesResource, 1)
|
||||
setInterval(this.getArbitraryResources, 600000)
|
||||
setInterval(this.getArbitraryResources, 900000)
|
||||
configLoaded = true
|
||||
}
|
||||
this.config = JSON.parse(c)
|
||||
@ -522,9 +514,25 @@ class Websites extends LitElement {
|
||||
const tabBrowseContent = this.shadowRoot.getElementById('tab-browse-content')
|
||||
const tabFollowedContent = this.shadowRoot.getElementById('tab-followed-content')
|
||||
const tabBlockedContent = this.shadowRoot.getElementById('tab-blocked-content')
|
||||
tabBrowseContent.style.display = (tab === 'browse') ? 'block' : 'none'
|
||||
tabFollowedContent.style.display = (tab === 'followed') ? 'block' : 'none'
|
||||
tabBlockedContent.style.display = (tab === 'blocked') ? 'block' : 'none'
|
||||
if (tab === 'browse') {
|
||||
this.refreshWebsites()
|
||||
tabBrowseContent.style.display = 'block'
|
||||
tabFollowedContent.style.display = 'none'
|
||||
tabBlockedContent.style.display = 'none'
|
||||
} else if (tab === 'followed') {
|
||||
this.getFollowedNamesRefresh()
|
||||
this.getFollowedNamesResource()
|
||||
tabBrowseContent.style.display = 'none'
|
||||
tabFollowedContent.style.display = 'block'
|
||||
tabBlockedContent.style.display = 'none'
|
||||
} else if (tab === 'blocked') {
|
||||
this.getBlockedNamesRefresh()
|
||||
this.getBlockedNamesResource()
|
||||
tabBrowseContent.style.display = 'none'
|
||||
tabFollowedContent.style.display = 'none'
|
||||
tabBlockedContent.style.display = 'block'
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
searchListener(e) {
|
||||
@ -751,6 +759,35 @@ class Websites extends LitElement {
|
||||
body: `${namesJsonString}`
|
||||
})
|
||||
|
||||
if (ret === true) {
|
||||
// Successfully followed - add to local list
|
||||
// Remove it first by filtering the list - doing it this way ensures the UI updates
|
||||
// immediately, as apposed to only adding if it doesn't already exist
|
||||
this.followedNames = this.followedNames.filter(item => item != name)
|
||||
this.followedNames.push(name)
|
||||
} else {
|
||||
let err3string = get("websitespage.schange22")
|
||||
parentEpml.request('showSnackBar', `${err3string}`)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
async followNameTab(websiteObj) {
|
||||
let name = websiteObj.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) {
|
||||
// Successfully followed - add to local list
|
||||
// Remove it first by filtering the list - doing it this way ensures the UI updates
|
||||
@ -759,8 +796,6 @@ class Websites extends LitElement {
|
||||
this.followedNames.push(name)
|
||||
this.getFollowedNamesRefresh()
|
||||
this.getFollowedNamesResource()
|
||||
this.refreshWebsites()
|
||||
this.updateComplete.then(() => this.requestUpdate())
|
||||
} else {
|
||||
let err3string = get("websitespage.schange22")
|
||||
parentEpml.request('showSnackBar', `${err3string}`)
|
||||
@ -784,13 +819,37 @@ class Websites extends LitElement {
|
||||
body: `${namesJsonString}`
|
||||
})
|
||||
|
||||
if (ret === true) {
|
||||
// Successfully unfollowed - remove from local list
|
||||
this.followedNames = this.followedNames.filter(item => item != name)
|
||||
} else {
|
||||
let err4string = get("websitespage.schange23")
|
||||
parentEpml.request('showSnackBar', `${err4string}`)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
async unfollowNameTab(websiteObj) {
|
||||
let name = websiteObj.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) {
|
||||
// Successfully unfollowed - remove from local list
|
||||
this.followedNames = this.followedNames.filter(item => item != name)
|
||||
this.getFollowedNamesRefresh()
|
||||
this.getFollowedNamesResource()
|
||||
this.refreshWebsites()
|
||||
this.updateComplete.then(() => this.requestUpdate())
|
||||
} else {
|
||||
let err4string = get("websitespage.schange23")
|
||||
parentEpml.request('showSnackBar', `${err4string}`)
|
||||
@ -814,6 +873,35 @@ class Websites extends LitElement {
|
||||
body: `${namesJsonString}`
|
||||
})
|
||||
|
||||
if (ret === true) {
|
||||
// Successfully blocked - add to local list
|
||||
// Remove it first by filtering the list - doing it this way ensures the UI updates
|
||||
// immediately, as apposed to only adding if it doesn't already exist
|
||||
this.blockedNames = this.blockedNames.filter(item => item != name)
|
||||
this.blockedNames.push(name)
|
||||
} else {
|
||||
let err5string = get("websitespage.schange24")
|
||||
parentEpml.request('showSnackBar', `${err5string}`)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
async blockNameTab(websiteObj) {
|
||||
let name = websiteObj.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) {
|
||||
// Successfully blocked - add to local list
|
||||
// Remove it first by filtering the list - doing it this way ensures the UI updates
|
||||
@ -822,8 +910,6 @@ class Websites extends LitElement {
|
||||
this.blockedNames.push(name)
|
||||
this.getBlockedNamesRefresh()
|
||||
this.getBlockedNamesResource()
|
||||
this.refreshWebsites()
|
||||
this.updateComplete.then(() => this.requestUpdate())
|
||||
} else {
|
||||
let err5string = get("websitespage.schange24")
|
||||
parentEpml.request('showSnackBar', `${err5string}`)
|
||||
@ -847,13 +933,37 @@ class Websites extends LitElement {
|
||||
body: `${namesJsonString}`
|
||||
})
|
||||
|
||||
if (ret === true) {
|
||||
// Successfully unblocked - remove from local list
|
||||
this.blockedNames = this.blockedNames.filter(item => item != name)
|
||||
} else {
|
||||
let err6string = get("websitespage.schange25")
|
||||
parentEpml.request('showSnackBar', `${err6string}`)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
async unblockNameTab(websiteObj) {
|
||||
let name = websiteObj.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) {
|
||||
// Successfully unblocked - remove from local list
|
||||
this.blockedNames = this.blockedNames.filter(item => item != name)
|
||||
this.getBlockedNamesRefresh()
|
||||
this.getBlockedNamesResource()
|
||||
this.refreshWebsites()
|
||||
this.updateComplete.then(() => this.requestUpdate())
|
||||
} else {
|
||||
let err6string = get("websitespage.schange25")
|
||||
parentEpml.request('showSnackBar', `${err6string}`)
|
||||
@ -930,6 +1040,24 @@ class Websites extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
renderFollowUnfollowButtonTab(websiteObj) {
|
||||
let name = websiteObj.name
|
||||
|
||||
// Only show the follow/unfollow button if we have permission to modify the list on this node
|
||||
if (this.followedNames == null || !Array.isArray(this.followedNames)) {
|
||||
return html``
|
||||
}
|
||||
|
||||
if (this.followedNames.indexOf(name) === -1) {
|
||||
// render follow button
|
||||
return html`<mwc-button @click=${() => this.followNameTab(websiteObj)}><mwc-icon>add_to_queue</mwc-icon> ${translate("websitespage.schange29")}</mwc-button>`
|
||||
}
|
||||
else {
|
||||
// render unfollow button
|
||||
return html`<mwc-button @click=${() => this.unfollowNameTab(websiteObj)}><mwc-icon>remove_from_queue</mwc-icon> ${translate("websitespage.schange30")}</mwc-button>`
|
||||
}
|
||||
}
|
||||
|
||||
renderBlockUnblockButton(websiteObj) {
|
||||
let name = websiteObj.name
|
||||
|
||||
@ -948,6 +1076,24 @@ class Websites extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
renderBlockUnblockButtonTab(websiteObj) {
|
||||
let name = websiteObj.name
|
||||
|
||||
// Only show the block/unblock button if we have permission to modify the list on this node
|
||||
if (this.blockedNames == null || !Array.isArray(this.blockedNames)) {
|
||||
return html``
|
||||
}
|
||||
|
||||
if (this.blockedNames.indexOf(name) === -1) {
|
||||
// render block button
|
||||
return html`<mwc-button @click=${() => this.blockNameTab(websiteObj)}><mwc-icon>block</mwc-icon> ${translate("websitespage.schange31")}</mwc-button>`
|
||||
}
|
||||
else {
|
||||
// render unblock button
|
||||
return html`<mwc-button @click=${() => this.unblockNameTab(websiteObj)}><mwc-icon>radio_button_unchecked</mwc-icon> ${translate("websitespage.schange32")}</mwc-button>`
|
||||
}
|
||||
}
|
||||
|
||||
bytesToSize(bytes) {
|
||||
var sizes = ['bytes', 'KB', 'MB', 'GB', 'TB']
|
||||
if (bytes == 0) return '0 bytes'
|
||||
|
Loading…
x
Reference in New Issue
Block a user