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(reset = false) {
if (this.isLoading || !this.hasMore) {
return
}
this.isLoading = true
const start = this.sliceStart
const stop = this.sliceStop
try {
if (this.filterField !== '') {
this.scrollQuerySet = this.scrollQuerySet.filter({
[this.filterField + '__icontains']: this.searchQuery
})
}
if (this.orderBy !== '') {
this.scrollQuerySet = this.scrollQuerySet.orderBy(this.orderBy)
}
this.scrollQuerySet = this.scrollQuerySet.slice(start, stop)
await this.scrollQuerySet.all()
const nextItems = this.scrollQuerySet.items
await this.hydrateTemplates(nextItems)
if (reset) {
this.items = nextItems
} else {
this.items = [...this.items, ...nextItems]
}
this.hasMore = nextItems.length >= this.increment
this.sliceStart = stop
this.sliceStop = stop + this.increment
}
finally {
this.isLoading = false
}
},
async resetAndLoad() {
this.sliceStart = 0
this.sliceStop = this.increment
this.hasMore = true
this.items = []
await this.loadMoreItems(true)
},
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 %}