Skip to content

Commit

Permalink
fix: details display for multi-day events
Browse files Browse the repository at this point in the history
  • Loading branch information
Eidenz committed Jun 25, 2024
1 parent 6f0cfee commit 1c6749e
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ function App() {
const selectToday = (eventsData) => {
const today = new Date();
const todayEvents = eventsData.filter(
(event) => new Date(event.startDate).toDateString() === today.toDateString()
(event) =>
new Date(event.startDate).toDateString() === today.toDateString() ||
isEventOngoing(event, today)
);
setSelectedEvents(todayEvents);
setActiveStartDate(today);
Expand Down Expand Up @@ -144,15 +146,23 @@ function App() {

const handleSelectEvent = (event) => {
const eventDate = new Date(event.startDate);
const dayEvents = events.filter(
(e) => new Date(e.startDate).toDateString() === eventDate.toDateString()
const relevantEvents = events.filter(
(e) =>
new Date(e.startDate).toDateString() === eventDate.toDateString() ||
isEventOngoing(e, eventDate)
);
setSelectedEvents(dayEvents);
setSelectedEvents(relevantEvents);
setActiveStartDate(eventDate);
setSelectedDate(eventDate);
setResetPage((prev) => !prev);
};

const isEventOngoing = (event, date) => {
const eventStart = new Date(event.startDate);
const eventEnd = new Date(event.endDate);
return date >= eventStart && date <= eventEnd;
};

const handleActiveStartDateChange = ({ activeStartDate }) => {
setActiveStartDate(activeStartDate);
};
Expand Down Expand Up @@ -202,10 +212,12 @@ function App() {

const handleDateClick = (date) => {
const clickedDate = new Date(date);
const dayEvents = events.filter(
(e) => new Date(e.startDate).toDateString() === clickedDate.toDateString()
const relevantEvents = events.filter(
(event) =>
new Date(event.startDate).toDateString() === clickedDate.toDateString() ||
isEventOngoing(event, clickedDate)
);
setSelectedEvents(dayEvents);
setSelectedEvents(relevantEvents);
setActiveStartDate(clickedDate);
setSelectedDate(clickedDate);
setResetPage((prev) => !prev);
Expand Down

0 comments on commit 1c6749e

Please sign in to comment.