-
Notifications
You must be signed in to change notification settings - Fork 5
Meetup-Übersicht: Teaser aus intro, kommende Termine chronologisch #255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d5510ed
Meetup-Übersicht: Teaser aus intro, kommende Termine chronologisch
claude 816d86d
Review-Anmerkungen: Prop-Typ vervollständigen, Zeitpunkt einmal besti…
claude a3880aa
Auswahl der kommenden Meetups in einen gemeinsamen Helper ziehen
claude 7409d85
Meetup am Referenzzeitpunkt zählt als kommend
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import type { DirectusMeetupItem } from '~/types/directus' | ||
|
|
||
| /** | ||
| * Selects and orders meetups by their date, so the meetup overview and the | ||
| * homepage derive their lists the same way. | ||
| * | ||
| * `getMeetups` sorts newest first, which is what a list of past meetups wants: | ||
| * the most recent one on top. Upcoming meetups have to run the other way | ||
| * round, otherwise the date furthest out is shown first and the next one sits | ||
| * at the bottom of the section. | ||
| * | ||
| * Both selections take `now` as an argument rather than reading the clock | ||
| * themselves, so a page that renders a past *and* an upcoming list compares | ||
| * every meetup against a single reference time. | ||
| * | ||
| * The boundary belongs to the upcoming side: a meetup whose `start_on` is | ||
| * exactly `now` has not happened yet, so it counts as upcoming and not as | ||
| * past. The two selections therefore partition the meetups completely — every | ||
| * meetup lands in exactly one of the lists, and one starting at the very | ||
| * moment the page renders cannot fall out of both. | ||
| */ | ||
| type ScheduledMeetup = Pick<DirectusMeetupItem, 'start_on'> | ||
|
|
||
| /** | ||
| * Upcoming meetups, soonest first. | ||
| * | ||
| * @param meetups The meetups to select from, in any order. | ||
| * @param now The reference time a meetup's `start_on` is compared against. | ||
| * | ||
| * @returns A new array holding the meetups that start at or after `now`, sorted ascending. | ||
| */ | ||
| export function getUpcomingMeetups<T extends ScheduledMeetup>(meetups: T[], now: Date): T[] { | ||
| return meetups | ||
| .filter((meetup) => new Date(meetup.start_on) >= now) | ||
| .sort((a, b) => new Date(a.start_on).getTime() - new Date(b.start_on).getTime()) | ||
| } | ||
|
|
||
| /** | ||
| * Past meetups, in the order they came in — the CMS query already sorts them | ||
| * newest first, which is the order the past list is shown in. | ||
| * | ||
| * Strictly before `now`: a meetup starting exactly at the reference time is | ||
| * upcoming, not past. | ||
| * | ||
| * @param meetups The meetups to select from. | ||
| * @param now The reference time a meetup's `start_on` is compared against. | ||
| * | ||
| * @returns A new array holding the meetups that started before `now`. | ||
| */ | ||
| export function getPastMeetups<T extends ScheduledMeetup>(meetups: T[], now: Date): T[] { | ||
| return meetups.filter((meetup) => new Date(meetup.start_on) < now) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
| import { getPastMeetups, getUpcomingMeetups } from '../helpers/meetupSchedule' | ||
|
|
||
| // The ordering is the reason this exists. `getMeetups` sorts newest first, which put the meetup | ||
| // furthest out at the top of the upcoming section and the next one at the bottom. | ||
|
|
||
| const NOW = new Date('2026-06-15T12:00:00Z') | ||
|
|
||
| // Newest first, the order the CMS query returns. | ||
| const MEETUPS = [ | ||
| { slug: 'in-three-months', start_on: '2026-09-01T18:00:00Z' }, | ||
| { slug: 'next-week', start_on: '2026-06-22T18:00:00Z' }, | ||
| { slug: 'tomorrow', start_on: '2026-06-16T18:00:00Z' }, | ||
| { slug: 'last-month', start_on: '2026-05-10T18:00:00Z' }, | ||
| { slug: 'last-year', start_on: '2025-06-10T18:00:00Z' }, | ||
| ] | ||
|
|
||
| // A meetup starting at the exact reference time. Both selections used a strict comparison once, so | ||
| // this one fell out of the upcoming *and* the past list — invisible on the page for that one moment. | ||
| const STARTING_NOW = { slug: 'starting-now', start_on: NOW.toISOString() } | ||
|
|
||
| describe('getUpcomingMeetups', () => { | ||
| it('returns only meetups that start after the reference time', () => { | ||
| expect(getUpcomingMeetups(MEETUPS, NOW).map((meetup) => meetup.slug)).toEqual([ | ||
| 'tomorrow', | ||
| 'next-week', | ||
| 'in-three-months', | ||
| ]) | ||
| }) | ||
|
|
||
| it('sorts soonest first, whatever order it is given', () => { | ||
| const reversed = [...MEETUPS].reverse() | ||
|
|
||
| expect(getUpcomingMeetups(reversed, NOW).map((meetup) => meetup.slug)).toEqual([ | ||
| 'tomorrow', | ||
| 'next-week', | ||
| 'in-three-months', | ||
| ]) | ||
| }) | ||
|
claude[bot] marked this conversation as resolved.
|
||
|
|
||
| it('leaves the input array untouched', () => { | ||
| const meetups = [...MEETUPS] | ||
|
|
||
| getUpcomingMeetups(meetups, NOW) | ||
|
|
||
| expect(meetups).toEqual(MEETUPS) | ||
| }) | ||
|
|
||
| it('returns nothing when every meetup is in the past', () => { | ||
| expect(getUpcomingMeetups(MEETUPS, new Date('2027-01-01T00:00:00Z'))).toEqual([]) | ||
| }) | ||
|
|
||
| it('counts a meetup starting exactly at the reference time as upcoming', () => { | ||
| expect(getUpcomingMeetups([...MEETUPS, STARTING_NOW], NOW).map((meetup) => meetup.slug)).toEqual([ | ||
| 'starting-now', | ||
| 'tomorrow', | ||
| 'next-week', | ||
| 'in-three-months', | ||
| ]) | ||
| }) | ||
| }) | ||
|
|
||
| describe('getPastMeetups', () => { | ||
| it('returns only meetups that started before the reference time', () => { | ||
| expect(getPastMeetups(MEETUPS, NOW).map((meetup) => meetup.slug)).toEqual(['last-month', 'last-year']) | ||
| }) | ||
|
|
||
| it('does not count a meetup starting exactly at the reference time as past', () => { | ||
| expect(getPastMeetups([...MEETUPS, STARTING_NOW], NOW).map((meetup) => meetup.slug)).toEqual([ | ||
| 'last-month', | ||
| 'last-year', | ||
| ]) | ||
| }) | ||
|
|
||
| it('keeps the incoming order, which the CMS query already sorts newest first', () => { | ||
| expect(getPastMeetups(MEETUPS, new Date('2027-01-01T00:00:00Z')).map((meetup) => meetup.slug)).toEqual([ | ||
| 'in-three-months', | ||
| 'next-week', | ||
| 'tomorrow', | ||
| 'last-month', | ||
| 'last-year', | ||
| ]) | ||
| }) | ||
| }) | ||
|
|
||
| describe('the two selections together', () => { | ||
| it('split the meetups without dropping or duplicating one', () => { | ||
| const upcoming = getUpcomingMeetups(MEETUPS, NOW) | ||
| const past = getPastMeetups(MEETUPS, NOW) | ||
|
|
||
| expect(upcoming.length + past.length).toBe(MEETUPS.length) | ||
| expect([...upcoming, ...past].map((meetup) => meetup.slug).sort()).toEqual( | ||
| MEETUPS.map((meetup) => meetup.slug).sort() | ||
| ) | ||
| }) | ||
|
|
||
| it('still split cleanly when a meetup starts exactly at the reference time', () => { | ||
| // The regression: with a strict comparison on both sides, `starting-now` was in neither list. | ||
| const meetups = [...MEETUPS, STARTING_NOW] | ||
| const upcoming = getUpcomingMeetups(meetups, NOW) | ||
| const past = getPastMeetups(meetups, NOW) | ||
|
|
||
| expect(upcoming.length + past.length).toBe(meetups.length) | ||
| expect([...upcoming, ...past].map((meetup) => meetup.slug).sort()).toEqual( | ||
| meetups.map((meetup) => meetup.slug).sort() | ||
| ) | ||
| expect(upcoming.map((meetup) => meetup.slug)).toContain('starting-now') | ||
| expect(past.map((meetup) => meetup.slug)).not.toContain('starting-now') | ||
| }) | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.