-
Notifications
You must be signed in to change notification settings - Fork 0
/
holiday-list.js
29 lines (28 loc) · 887 Bytes
/
holiday-list.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { Component } from 'preact';
import HolidayCard from './holiday-card';
export default class HolidayList extends Component {
render(props, state) {
let currentDate = new Date(props.date.getTime() + 1000);
let currentHolidays = props.data.filter(holiday => {
let startDate = new Date(holiday.year, holiday.month - 1, holiday.day);
let endDate = new Date(holiday.year, holiday.month - 1, holiday.day);
let durationDays = holiday.duration;
endDate.setDate(endDate.getDate() + durationDays);
return startDate <= currentDate && currentDate <= endDate;
});
currentHolidays.sort((a, b) => {
let diff = a.duration - b.duration;
if (diff === 0) {
diff = 1 - a.food.localeCompare(b.food);
}
return diff;
});
return (
<div class="list">
{currentHolidays.map(holiday => (
<HolidayCard holidayObj={holiday} />
))}
</div>
);
}
}