From 8456d321380940c42a23e8f6368e2e015493b236 Mon Sep 17 00:00:00 2001 From: Jess Date: Thu, 21 Nov 2024 20:17:43 -0700 Subject: [PATCH 1/2] fix: APPS-3074 add watchers for pagination reactivity (#658) * fix: add watchers for pagination reactivity * fix: unused variables --------- Co-authored-by: Jess Divers --- src/lib-components/SectionPagination.vue | 11 +++++++++++ src/stories/SectionPagination.stories.js | 25 ++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/lib-components/SectionPagination.vue b/src/lib-components/SectionPagination.vue index 2f4a585a7..b3bfad222 100644 --- a/src/lib-components/SectionPagination.vue +++ b/src/lib-components/SectionPagination.vue @@ -116,6 +116,17 @@ const isNotLastPage = computed(() => { return (initialCurrentPage && pages) && currPage?.value !== pages }) +// WATCHERS - we use watch instead of computed because we are using variables derived from props during render +// note: this ensures the component will update when props change +watch(() => pages, () => { + // regenerate pages when pages change + generateLeftPages() +}, { immediate: true }) +watch(() => initialCurrentPage, (newVal) => { + // set current page when initialCurrentPage changes + currPage.value = newVal as number +}, { immediate: true }) + onMounted(() => { // legacy implementation does not require any onMounted logic if (!initialCurrentPage || !pages) diff --git a/src/stories/SectionPagination.stories.js b/src/stories/SectionPagination.stories.js index 27fdf03bd..4e3ce1806 100644 --- a/src/stories/SectionPagination.stories.js +++ b/src/stories/SectionPagination.stories.js @@ -1,4 +1,4 @@ -import { computed } from 'vue' +import { computed, ref } from 'vue' import SectionPagination from '@/lib-components/SectionPagination' /** @@ -49,6 +49,8 @@ export function WithPagesAndCurrentPage() { } } +// this story uses an async fetch to get the total number of pages +// like the FTVA event listing page export function FTVA() { return { components: { SectionPagination }, @@ -57,6 +59,25 @@ export function FTVA() { theme: computed(() => 'ftva'), } }, - template: '', + setup() { + // similar to ftva event listing page logic + const totalPages = ref(0) + + // Set totalPages.value asynchronously + const fetchTotalPages = async () => { + // Mocking an async fetch call + const response = await new Promise((resolve) => { + setTimeout(() => { + resolve(20) + }, 1000) + }) + totalPages.value = response + } + + fetchTotalPages() + + return { totalPages } + }, + template: '' } } From 4d4714c02a00b07c3e82484b136eddf5f1c614b7 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Fri, 22 Nov 2024 03:18:30 +0000 Subject: [PATCH 2/2] chore(release): set `package.json` to 3.35.1 [skip ci] ## [3.35.1](https://github.com/UCLALibrary/ucla-library-website-components/compare/v3.35.0...v3.35.1) (2024-11-22) ### Bug Fixes * APPS-3074 add watchers for pagination reactivity ([#658](https://github.com/UCLALibrary/ucla-library-website-components/issues/658)) ([8456d32](https://github.com/UCLALibrary/ucla-library-website-components/commit/8456d321380940c42a23e8f6368e2e015493b236)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 271cad1c4..c01f04976 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [3.35.1](https://github.com/UCLALibrary/ucla-library-website-components/compare/v3.35.0...v3.35.1) (2024-11-22) + + +### Bug Fixes + +* APPS-3074 add watchers for pagination reactivity ([#658](https://github.com/UCLALibrary/ucla-library-website-components/issues/658)) ([8456d32](https://github.com/UCLALibrary/ucla-library-website-components/commit/8456d321380940c42a23e8f6368e2e015493b236)) + # [3.35.0](https://github.com/UCLALibrary/ucla-library-website-components/compare/v3.34.0...v3.35.0) (2024-11-21) diff --git a/package.json b/package.json index 735f62da6..b41083996 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "ucla-library-website-components", "type": "module", "private": false, - "version": "3.35.0", + "version": "3.35.1", "main": "./dist/ucla-library-website-components.umd.cjs", "module": "./dist/ucla-library-website-components.js", "style": "./dist/style.css",