idsToFetch.includes(item.$pk))
.forEach(item => {
this.templateCache[this.cacheKey(item)] = html[item.$pk]
})
this.saveTemplateCache()
}
items.forEach(item => {
item.renderedTemplate = this.templateCache[this.cacheKey(item)]
})
},
async loadMoreItems() {
if (this.isLoading || !this.hasMore) {
return
}
if (this.pageQuerySet === null) {
await this.resetAndLoad()
return
}
const generation = this.loadGeneration
const pageQuerySet = this.pageQuerySet
this.isLoading = true
try {
await pageQuerySet.loadMore()
const loadedItems = pageQuerySet.items
await this.hydrateTemplates(loadedItems)
if (generation !== this.loadGeneration) {
return
}
this.items = loadedItems
this.hasMore = pageQuerySet.hasNext
}
finally {
if (generation === this.loadGeneration) {
this.isLoading = false
}
}
},
async resetAndLoad() {
const generation = ++this.loadGeneration
this.isLoading = true
this.hasMore = true
this.items = []
let pageQuerySet = this.scrollQuerySet
if (this.filterField !== '') {
pageQuerySet = pageQuerySet.filter({
[this.filterField + '__icontains']: this.searchQuery
})
}
if (this.orderBy !== '') {
pageQuerySet = pageQuerySet.orderBy(this.orderBy)
}
this.pageQuerySet = pageQuerySet
try {
await pageQuerySet.refresh()
const loadedItems = pageQuerySet.items
await this.hydrateTemplates(loadedItems)
if (generation !== this.loadGeneration) {
return
}
this.items = loadedItems
this.hasMore = pageQuerySet.hasNext
}
finally {
if (generation === this.loadGeneration) {
this.isLoading = false
}
}
},
async updateItem(pk, removed = false) {
if (!pk) {
return
}
if (removed) {
await this.resetAndLoad()
return
}
const item = await this.scrollQuerySet.get(pk)
await this.hydrateTemplates([item])
// TODO: delete this, should happen inside .get()
item.$collection = this.scrollQuerySet
const itemIndex = this.items.findIndex(existingItem => existingItem.$pk === item.$pk)
if (itemIndex === -1) {
this.items.unshift(item)
}
else {
this.items[itemIndex] = item
}
},
toggleOrder() {
this.orderBy = this.orderBy.startsWith('-') ? this.orderBy.slice(1) : '-' + this.orderBy
},
}"
@updated-item.window="
if (!$event.detail?.querysetName || $event.detail.querysetName === scrollQuerySet._name) {
updateItem($event.detail.pk, $event.detail.removed)
}
"
class="{% block scroll_container_class %}{% endblock %}"
>
{% block scroll_header %}
{% endblock %}
{% block scroll_content %}
{% block scroll_template_item %}
{% endblock %}
You have no notifications...
{% endblock %}
Loading items...
Loading items...
{% block scroll_footer %}
{% endblock %}