Skip to content

Commit

Permalink
Fix the date range format, fix ongoing story
Browse files Browse the repository at this point in the history
  • Loading branch information
jendiamond committed Nov 19, 2024
1 parent bd82445 commit 6119f0b
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 151 deletions.
17 changes: 8 additions & 9 deletions src/lib-components/BlockStaffArticleList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import format from 'date-fns/format'
// UTILITY FUNCTIONS
import removeHtmlTruncate from '@/utils/removeHtmlTruncate'
import formatDates from '@/utils/formatEventDates'
import formatSeriesDates from '@/utils/formatEventSeriesDates'
// THEME
import { useTheme } from '@/composables/useTheme'
Expand All @@ -24,7 +24,7 @@ import type { ArticleStaffItemType, MediaItemType } from '@/types/types'
// CHILD COMPONENTS
import ResponsiveImage from '@/lib-components/ResponsiveImage.vue'
import SmartLink from '@/lib-components/SmartLink.vue'

Check failure on line 26 in src/lib-components/BlockStaffArticleList.vue

View workflow job for this annotation

GitHub Actions / eslint

Expected 1 empty line after import statement not followed by another import
//import Date from '@/lib-components/Date.vue'
// import Date from '@/lib-components/Date.vue'
// PROPS & DATA
const props = defineProps({
Expand Down Expand Up @@ -102,12 +102,12 @@ const parsedTextAll = computed(() => {
// Display date based on which data is provided
const parsedDateDisplay = computed(() => {
if (props.ongoing == true)
if (props.ongoing === true)
return 'Ongoing'
else if (props.endDate)
return formatDates(props.startDate, props.endDate, 'shortWithYear')
return formatSeriesDates(props.startDate, props.endDate, 'shortWithYear')
else if (props.startDate)
return formatDates(props.startDate, props.startDate)
return formatSeriesDates(props.startDate, props.startDate)
else
return null
})
Expand Down Expand Up @@ -141,7 +141,6 @@ isMobile.value = newWidth <=
object-fit="cover"
class="image"
/>
<div
v-else
class="molecule-no-image"
Expand Down Expand Up @@ -208,9 +207,9 @@ isMobile.value = newWidth <=
</div>
<!-- <Date
:startDate="startDate"
:endDate="endDate"
:ongoing="ongoing"
:startDate="props.startDate"
:endDate="props.endDate"
:ongoing="props.ongoing"
/> -->
</div>
</li>
Expand Down
51 changes: 0 additions & 51 deletions src/lib-components/Date.vue

This file was deleted.

18 changes: 14 additions & 4 deletions src/stories/BlockStaffArticleList.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ const mockDateRange2 = {
ongoing: false
}

const mockOngoing = {
to: "series/a-film-series-for-you-celebrating-giant-robot-äôs-30th-anniversary",
title: "An Ongoing Film Series for You",
image: API.image,
description: "This deep into the post-print era it may be hard for some to understand.",
startDate: "2024-11-01T19:30:00",
endDate: null,
ongoing: true
}

// Variations of stories below
export function Default() {
return {
Expand Down Expand Up @@ -240,7 +250,7 @@ export function FtvaStartEndDateSame() {
export function FtvaOngoing() {
return {
data() {
return { ...mockDateRange }
return { ...mockOngoing }
},
provide() {
return {
Expand All @@ -254,9 +264,9 @@ export function FtvaOngoing() {
:to="to"
:title="title"
:description="description"
startDate="2024-11-01T19:30:00"
endDate=null
ongoing=true
:startDate="startDate"
:endDate="endDate"
:ongoing="ongoing"
/>
`,
}
Expand Down
75 changes: 0 additions & 75 deletions src/stories/Date.stories.js

This file was deleted.

24 changes: 12 additions & 12 deletions src/styles/ftva/_block-staff-article-item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
margin-bottom: 0;
padding-bottom: 0;

.image {
max-width: 284px;
height: 213px;
width: 33%;
aspect-ratio: 4/3;
margin-right: var(--space-xl);
}

.meta {
width: unset;
height: 213px;
}
// .image {
// max-width: 284px;
// height: 213px;
// width: 33%;
// aspect-ratio: 4/3;
// margin-right: var(--space-xl);
// }

// .meta {
// width: unset;
// height: 213px;
// }

.title {
@include ftva-card-title-1;
Expand Down
52 changes: 52 additions & 0 deletions src/utils/formatEventSeriesDates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import format from 'date-fns/format'

/**
* Take two date strings, and return them in human readable date formats for Events
*
* @param {string} startDate
* @param {string} endDate
* @param {string} dateFormat - 'long', 'short', or 'shortWithYear'
* @returns {string}
*/

function formatDates(startDate = '', endDate = '', dateFormat = 'long') {
const start = format(new Date(startDate), 'MMMM d, Y')
// console.log(start)
const end = format(new Date(endDate), 'MMMM d, Y')

// "February 11 2020 – May 31 2021"
let output = `${start} - ${end}`

if (start === end) {
// Thursday, January 28
output = format(new Date(startDate), 'MMMM d, Y')
}

if (!endDate) {
// February 11 2020
output = start
}

if (dateFormat === 'short' || dateFormat === 'shortWithYear') {
// "Feb 11 2020"
const day = output.slice(0, 3)
const dateYear = output.split(' ').slice(1).join(' ')
if (endDate && endDate !== startDate) {
// Feb 11 – May 31
const shortFormatStartDate = format(new Date(startDate), 'MMM d, Y')
const shortFormatEndDate = format(new Date(endDate), 'MMM d, Y')
// if 'shortWithYear' is selected, add the year to the end date
// Feb 11 – May 31 2020
if (dateFormat === 'shortWithYear') {
const shortFormatEndDateYear = format(new Date(endDate), 'MMM d, Y')
return `${shortFormatStartDate} - ${shortFormatEndDateYear}`
}
return `${shortFormatStartDate} - ${shortFormatEndDate}`
}
return `${day} ${dateYear}`
}

return output
}

export default formatDates

0 comments on commit 6119f0b

Please sign in to comment.