Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Kim authored and Chris Kim committed Dec 19, 2024
1 parent e76b481 commit d12b36f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
4 changes: 0 additions & 4 deletions src/lib/utils/date.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,6 @@ describe('FilterPastEvents', () => {
]
const result = filterPastEvents(datetimeRange)
expect(result).toHaveLength(1)
expect(result[0]).toHaveProperty('startTime')
expect(result[0]).toHaveProperty('endTime')
expect(result[0]).toHaveProperty('value')
expect(result[0]).toHaveProperty('endValue')
})
})

Expand Down
5 changes: 2 additions & 3 deletions src/lib/utils/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ export const formatDateObject = (datetimeRange) => {
}

export const filterPastEvents = (eventTimes) => {
if (!eventTimes) return []
const now = new Date()
const filteredEventTimes = eventTimes.filter((dateObject) => {
return eventTimes.filter((dateObject) => {
const endTime = new Date(dateObject.end_value)
return endTime > now // Keep only if end_time is in the future
})
return formatDateObject(filteredEventTimes)
}

export const deriveMostRecentDate = (
Expand Down Expand Up @@ -230,7 +230,6 @@ export const deriveFormattedTimestamp = (datetime) => {
if (!datetime) return
const startTime = new Date(datetime.startTime)
const endTime = new Date(datetime.endTime)

const formattedStartTime = startTime.toLocaleTimeString('en-US', {
weekday: 'short',
year: 'numeric',
Expand Down
12 changes: 4 additions & 8 deletions src/templates/layouts/event/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,13 @@ export const Event = ({

// Memoized because formateDateObject returns a map that will be recalculated on each render.
const formattedDates = useMemo(
() => formatDateObject(datetimeRange),
() => formatDateObject(filterPastEvents(datetimeRange)),
[datetimeRange]
)
const filteredFormattedDates = useMemo(
() => filterPastEvents(formattedDates),
[formattedDates]
)

const initialFormattedDates = filteredFormattedDates.slice(0, 5)
const initialFormattedDates = formattedDates.slice(0, 5)
const [currentFormattedDates, setCurrentFormattedDates] = useState(
filteredFormattedDates
initialFormattedDates
)

useEffect(() => {
Expand Down Expand Up @@ -281,7 +277,7 @@ export const Event = ({
{body && <div dangerouslySetInnerHTML={{ __html: body?.processed }} />}

{/* Recurring Events */}
{filteredFormattedDates.length > 1 && (
{currentFormattedDates.length > 1 && (
<div>
<va-accordion open-single id="expand-recurring-events">
<va-accordion-item
Expand Down

0 comments on commit d12b36f

Please sign in to comment.