From 667676d520d3b490587b8474ed12b7fcab78f847 Mon Sep 17 00:00:00 2001 From: Garvit Singhal Date: Sun, 23 Mar 2025 13:37:30 +0530 Subject: [PATCH 1/5] fix: trash page sorting and show more --- .../channelEdit/views/trash/TrashModal.vue | 45 +++++++++++++------ .../channelEdit/vuex/contentNode/actions.js | 4 +- .../frontend/shared/data/resources.js | 11 ++++- 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/contentcuration/contentcuration/frontend/channelEdit/views/trash/TrashModal.vue b/contentcuration/contentcuration/frontend/channelEdit/views/trash/TrashModal.vue index e1ba3e3625..15fe783d2a 100644 --- a/contentcuration/contentcuration/frontend/channelEdit/views/trash/TrashModal.vue +++ b/contentcuration/contentcuration/frontend/channelEdit/views/trash/TrashModal.vue @@ -67,7 +67,7 @@
- + {{ showMoreLabel }}
@@ -201,7 +201,7 @@ ]; }, items() { - return sortBy(this.getContentNodeChildren(this.trashId), 'modified'); + return sortBy(this.getContentNodeChildren(this.trashId), 'modified').reverse(); }, backLink() { return { @@ -216,6 +216,10 @@ // eslint-disable-next-line kolibri/vue-no-undefined-string-uses return showMoreTranslator.$tr('showMore'); }, + // "hasMore" returns true only if "more" is a nonempty plain object. + hasMore() { + return this.more && Object.keys(this.more).length > 0; + }, }, watch: { dialog(newValue) { @@ -225,9 +229,9 @@ }, }, created() { - this.loadContentNodes({ parent__in: [this.rootId] }), - this.loadAncestors({ id: this.nodeId }), - this.loadNodes(); + this.loadContentNodes({ parent__in: [this.rootId] }); + this.loadAncestors({ id: this.nodeId }); + this.loadNodes(); }, mounted() { this.updateTabTitle(this.$store.getters.appendChannelName(this.$tr('trashModalTitle'))); @@ -246,7 +250,7 @@ this.loading = false; return; } - this.loadChildren({ parent: this.trashId }).then(childrenResponse => { + this.loadChildren({ parent: this.trashId, ordering: '-modified' }).then(childrenResponse => { this.loading = false; this.more = childrenResponse.more || null; }); @@ -284,13 +288,26 @@ return this.previewNodeId === id ? this.$vuetify.theme.greyBackground : 'transparent'; }, loadMore() { - if (this.more && !this.moreLoading) { - this.moreLoading = true; - this.loadContentNodes(this.more).then(response => { - this.more = response.more || null; - this.moreLoading = false; - }); - } + // Prevent further calls if "more" is falsy or already loading. + if (!this.more || this.moreLoading) return; + this.moreLoading = true; + // Capture current item count and clone "more" parameters. + const currentItemsLength = this.items.length; + const currentMore = JSON.stringify(this.more); + // Call loadContentNodes with a deep clone of the "more" object. + this.loadContentNodes(JSON.parse(JSON.stringify(this.more))).then(response => { + // If no new "more" is returned or item count hasn't increased, clear "more" + if ( + !response.more || + JSON.stringify(response.more) === currentMore || + this.items.length === currentItemsLength + ) { + this.more = null; + } else { + this.more = response.more; + } + this.moreLoading = false; + }); }, }, $trs: { @@ -311,7 +328,7 @@ }; -