Skip to content

Commit

Permalink
fix: timetable default index (#31)
Browse files Browse the repository at this point in the history
* fix: timetable default index

* fix: compare start dates correctly

* fix: code style

---------

Co-authored-by: Samu Kupiainen <[email protected]>
  • Loading branch information
antoKeinanen and Adventune authored Jul 28, 2024
1 parent e2a6b14 commit 1ad91a8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions api/eventService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Colors } from '@/styles';
import dayjs from 'dayjs';

type ApiEventLocation = {
term_id: number;
Expand Down Expand Up @@ -105,15 +106,14 @@ export const determineStartDayIndex = (events: AssemblyEvent[]): number => {
}

const days = [...new Set(events.map((event) => event.start))];
const start_day_index = days.findIndex((day) => doorsOpen.start === day);
const startDayIndex = days.findIndex((day) => dayjs(doorsOpen.start).isSame(day, 'day'));

if (start_day_index === -1) {
if (startDayIndex === -1) {
console.error("Failed to find matching day for 'Doors Open' event");
return 0;
}

// the index returned by findIndex if off by one
return start_day_index - 1;
return startDayIndex;
};

const API_BASE_PATH = `https://wp.assembly.org/${determineEvent()}/index.php?rest_route=/api/v1`;
Expand Down

0 comments on commit 1ad91a8

Please sign in to comment.