mirror of
https://github.com/Qortal/qortal-ui.git
synced 2025-03-27 07:45:54 +00:00
Load pages from offset
This commit is contained in:
parent
c6380dfe8a
commit
81706d923e
@ -22,6 +22,7 @@ class Websites extends LitElement {
|
|||||||
identifier: { type: String },
|
identifier: { type: String },
|
||||||
loading: { type: Boolean },
|
loading: { type: Boolean },
|
||||||
resources: { type: Array },
|
resources: { type: Array },
|
||||||
|
pageRes: { type: Array },
|
||||||
followedNames: { type: Array },
|
followedNames: { type: Array },
|
||||||
blockedNames: { type: Array },
|
blockedNames: { type: Array },
|
||||||
relayMode: { type: Boolean },
|
relayMode: { type: Boolean },
|
||||||
@ -223,6 +224,7 @@ class Websites extends LitElement {
|
|||||||
this.identifier = null
|
this.identifier = null
|
||||||
this.selectedAddress = {}
|
this.selectedAddress = {}
|
||||||
this.resources = []
|
this.resources = []
|
||||||
|
this.pageRes = []
|
||||||
this.followedNames = []
|
this.followedNames = []
|
||||||
this.blockedNames = []
|
this.blockedNames = []
|
||||||
this.relayMode = null
|
this.relayMode = null
|
||||||
@ -585,11 +587,21 @@ class Websites extends LitElement {
|
|||||||
|
|
||||||
getArbitraryResources = async () => {
|
getArbitraryResources = async () => {
|
||||||
const resources = await parentEpml.request('apiCall', {
|
const resources = await parentEpml.request('apiCall', {
|
||||||
url: `/arbitrary/resources?service=${this.service}&default=true&limit=0&reverse=false&includestatus=true&includemetadata=true`
|
url: `/arbitrary/resources?service=${this.service}&default=true&limit=0&reverse=false&includestatus=false&includemetadata=false`
|
||||||
})
|
})
|
||||||
this.resources = resources
|
this.resources = resources
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getData(offset) {
|
||||||
|
const myNode = window.parent.reduxStore.getState().app.nodeConfig.knownNodes[window.parent.reduxStore.getState().app.nodeConfig.node]
|
||||||
|
const nodeUrl = myNode.protocol + '://' + myNode.domain + ':' + myNode.port
|
||||||
|
let jsonUrl = `${nodeUrl}/arbitrary/resources?service=WEBSITE&default=true&limit=20&offset=${offset}&reverse=false&includestatus=true&includemetadata=true`;
|
||||||
|
const jsonRes = await fetch(jsonUrl);
|
||||||
|
const jsonData = await jsonRes.json();
|
||||||
|
|
||||||
|
this.pageRes = jsonData;
|
||||||
|
}
|
||||||
|
|
||||||
async updateItemsFromPage(page) {
|
async updateItemsFromPage(page) {
|
||||||
if (page === undefined) {
|
if (page === undefined) {
|
||||||
return
|
return
|
||||||
@ -611,7 +623,14 @@ class Websites extends LitElement {
|
|||||||
this.pages.forEach((pageNumber) => {
|
this.pages.forEach((pageNumber) => {
|
||||||
const pageBtn = document.createElement('button')
|
const pageBtn = document.createElement('button')
|
||||||
pageBtn.textContent = pageNumber
|
pageBtn.textContent = pageNumber
|
||||||
|
let offset = 1;
|
||||||
pageBtn.addEventListener('click', (e) => {
|
pageBtn.addEventListener('click', (e) => {
|
||||||
|
if (parseInt(e.target.textContent) > 1) {
|
||||||
|
offset = (parseInt(e.target.textContent) - 1) * 20;
|
||||||
|
} else {
|
||||||
|
offset = 0;
|
||||||
|
}
|
||||||
|
this.getData(offset);
|
||||||
this.updateItemsFromPage(parseInt(e.target.textContent))
|
this.updateItemsFromPage(parseInt(e.target.textContent))
|
||||||
})
|
})
|
||||||
if (pageNumber === page) {
|
if (pageNumber === page) {
|
||||||
@ -654,12 +673,13 @@ class Websites extends LitElement {
|
|||||||
let start = (page - 1) * this.resourcesGrid.pageSize
|
let start = (page - 1) * this.resourcesGrid.pageSize
|
||||||
let end = page * this.resourcesGrid.pageSize
|
let end = page * this.resourcesGrid.pageSize
|
||||||
|
|
||||||
this.resourcesGrid.items = this.resources.slice(start, end)
|
this.resourcesGrid.items = this.pageRes
|
||||||
}
|
}
|
||||||
|
|
||||||
async showWebsites() {
|
async showWebsites() {
|
||||||
await this.getArbitraryResources()
|
await this.getArbitraryResources()
|
||||||
await this.getResourcesGrid()
|
await this.getResourcesGrid()
|
||||||
|
await this.getData(0)
|
||||||
await this.updateItemsFromPage(1, true)
|
await this.updateItemsFromPage(1, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user