From 0caa56e6187f0a82e85aa11ed9537e8be98cd850 Mon Sep 17 00:00:00 2001 From: Prospector <6166773+Prospector@users.noreply.github.com> Date: Mon, 30 Jan 2023 16:28:16 -0800 Subject: [PATCH] Recalculate changelog deduplication when the filters change (#954) --- pages/_type/_id/changelog.vue | 7 ++++--- plugins/shorthands.js | 26 ++++++++++++++------------ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/pages/_type/_id/changelog.vue b/pages/_type/_id/changelog.vue index 392a36c0..ac80f8c4 100644 --- a/pages/_type/_id/changelog.vue +++ b/pages/_type/_id/changelog.vue @@ -98,13 +98,14 @@ export default { }, data() { return { - filteredVersions: this.versions, + filteredVersions: this.$calculateDuplicates(this.versions), currentPage: 1, } }, fetch() { - if (this.$route.query.page) + if (this.$route.query.page) { this.currentPage = parseInt(this.$route.query.page) + } }, head() { const title = `${this.project.title} - Changelog` @@ -154,7 +155,7 @@ export default { } }, updateVersions(updatedVersions) { - this.filteredVersions = updatedVersions + this.filteredVersions = this.$calculateDuplicates(updatedVersions) }, }, auth: false, diff --git a/plugins/shorthands.js b/plugins/shorthands.js index 8e1a9def..461f55ae 100644 --- a/plugins/shorthands.js +++ b/plugins/shorthands.js @@ -32,6 +32,20 @@ export default (ctx, inject) => { inject('formatCategory', formatCategory) inject('formatCategoryHeader', formatCategoryHeader) inject('formatProjectStatus', formatProjectStatus) + inject('calculateDuplicates', (versions) => + versions.map((version, index) => { + const nextVersion = versions[index + 1] + if ( + nextVersion && + version.changelog && + nextVersion.changelog === version.changelog + ) { + return { duplicate: true, ...version } + } else { + return { duplicate: false, ...version } + } + }) + ) inject('computeVersions', (versions) => { const visitedVersions = [] const returnVersions = [] @@ -52,18 +66,6 @@ export default (ctx, inject) => { return returnVersions .reverse() - .map((version, index) => { - const nextVersion = returnVersions[index + 1] - if ( - nextVersion && - version.changelog && - nextVersion.changelog === version.changelog - ) { - return { duplicate: true, ...version } - } else { - return { duplicate: false, ...version } - } - }) .sort( (a, b) => ctx.$dayjs(b.date_published) - ctx.$dayjs(a.date_published) )