From b753af631d213b73ffb9e58982f3e77a8073f1d4 Mon Sep 17 00:00:00 2001 From: Jess Divers Date: Thu, 26 Sep 2024 12:38:43 -0700 Subject: [PATCH 01/11] feat: blog article page sidebar, data parsing --- cypress/e2e/blogArticlePage.cy.js | 8 ++ gql/queries/FTVAArticleDetail.gql | 3 +- pages/blog/[slug].vue | 208 ++++++++++-------------------- pages/events/[slug].vue | 9 +- 4 files changed, 82 insertions(+), 146 deletions(-) create mode 100644 cypress/e2e/blogArticlePage.cy.js diff --git a/cypress/e2e/blogArticlePage.cy.js b/cypress/e2e/blogArticlePage.cy.js new file mode 100644 index 0000000..2d01fca --- /dev/null +++ b/cypress/e2e/blogArticlePage.cy.js @@ -0,0 +1,8 @@ +describe('Blog Article Page', () => { + it('Visits a Blog Article Page', () => { + cy.visit('/blog/test-tom-reeds-for-members-only-black-perspectives-on-local-l-a-tv') + cy.getByData('breadcrumb').should('be.visible') + cy.getByData('recent-posts').should('be.visible') + cy.percySnapshot('blogarticlepage', { widths: [768, 992, 1200] }) + }) +}) diff --git a/gql/queries/FTVAArticleDetail.gql b/gql/queries/FTVAArticleDetail.gql index 73c644d..d5081f0 100644 --- a/gql/queries/FTVAArticleDetail.gql +++ b/gql/queries/FTVAArticleDetail.gql @@ -40,7 +40,8 @@ query FTVAArticleDetail($slug: [String!]) { ...AllFtvaFpb } # SectionTeaserCard (Recent posts) - ftvaRecentPosts: entries( section: "ftvaArticle", limit: 3, orderBy: "postDate ASC") { + # page only displays 3 but we query 4 in case the list includes the current article + ftvaRecentPosts: entries( section: "ftvaArticle", limit: 4, orderBy: "postDate ASC") { id title to: slug diff --git a/pages/blog/[slug].vue b/pages/blog/[slug].vue index 503be36..217a74e 100644 --- a/pages/blog/[slug].vue +++ b/pages/blog/[slug].vue @@ -2,7 +2,9 @@ // COMPONENT RE-IMPORTS // TODO: remove when we have implemented component library as a module // https://nuxt.com/docs/guide/directory-structure/components#library-authors -import { BlockTag, CardMeta, DividerWayFinder, FlexibleMediaGalleryNewLightbox, FlexibleBlocks, NavBreadcrumb, ResponsiveImage, RichText, SectionTeaserCard, SectionWrapper } from 'ucla-library-website-components' +import { + BlockTag, CardMeta, DividerWayFinder, FlexibleMediaGalleryNewLightbox, FlexibleBlocks, NavBreadcrumb, ResponsiveImage, RichText, SectionTeaserCard, SectionWrapper, TwoColLayoutWStickySideBar +} from 'ucla-library-website-components' // HELPERS import _get from 'lodash/get' @@ -37,7 +39,7 @@ const page = ref(_get(data.value, 'ftvaArticle', {})) const ftvaRecentPosts = ref(_get(data.value, 'ftvaRecentPosts', {})) watch(data, (newVal, oldVal) => { - console.log('In watch preview enabled, newVal, oldVal', newVal, oldVal) + // console.log('In watch preview enabled, newVal, oldVal', newVal, oldVal) page.value = _get(newVal, 'ftvaArticle', {}) ftvaRecentPosts.value = _get(newVal, 'ftvaRecentPosts', {}) }) @@ -55,21 +57,26 @@ const parsedCarouselData = computed(() => { return { item: [{ ...rawItem.image[0], kind: 'image' }], // Carousels on this page are always images, no videos credit: rawItem?.creditText, - captionTitle: 'dfdsfs', // TODO do we need these? test without - captionText: 'dfsdfsd', + // captionTitle: 'dfdsfs', // TODO do we need these? test without + // captionText: 'dfsdfsd', } }) }) // Combine the categories into a String const parsedArticleCategories = computed(() => { - const categoryList = page.value.articleCategories - const categories = [] - - for (const category of categoryList) { - categories.push(category.title) + if (page.value.articleCategories) { + return page.value.articleCategories.map(category => category.title).join(', ') } - return categories.join(', ') + return '' +}) + +// Recent Posts: Filter out the current post and then return the first 3 max +const parsedRecentPosts = computed(() => { + // fail gracefully if no recent posts + if (!ftvaRecentPosts.value) + return [] + return ftvaRecentPosts.value.filter(item => !item.to.includes(route.params.slug)).slice(0, 3) }) @@ -117,66 +124,40 @@ const parsedArticleCategories = computed(() => { -
-
- - - - - - -
-
- - - - - - + + + - -

ftvaRecentPosts

-
{{ ftvaRecentPosts }}
+ + - -