Skip to content
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

Changed the MiniCal component to gray out weekends and holidays #513

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion frontend/src/components/MiniCal/MiniCal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,35 @@ import './datepicker_override.css';
import styles from './minical.module.css';
import { useDate } from '../../context/date';

/**startDate is inclusive, endDate is exclusive */
type Holiday = {
startDate: Date;
endDate: Date;
holidayName: string;
};

const holidays: Holiday[] = [
raissaji marked this conversation as resolved.
Show resolved Hide resolved
{
startDate: new Date('2024-2-24'),
endDate: new Date('2024-2-28'),
holidayName: 'Febuaray Break',
},
{
startDate: new Date('2024-3-30'),
endDate: new Date('2024-4-8'),
holidayName: 'Spring Break',
},
];

const isHoliday = (date: Date) => {
for (const holiday of holidays) {
if (holiday.startDate <= date && date < holiday.endDate) {
return true;
}
}
return false;
};

const currentDate = new Date();
const isToday = (date: Date) =>
date.getDate() === currentDate.getDate() &&
Expand Down Expand Up @@ -77,17 +106,26 @@ const MiniCal = () => {
window.scroll(x + 1, y);
window.scroll(x, y);
};
const isWeekday = (date: Date) => {
const day = date.getDay();
return day !== 0 && day !== 6;
};

const filterDate = (date: Date) => {
return isWeekday(date) && !isHoliday(date);
};

return (
<div className={styles.root}>
<DatePicker
adjustDateOnChange
//adjustDateOnChange
selected={curDate}
onChange={updateDate}
closeOnScroll={true}
dateFormat="MMM dd, yyyy"
showPopperArrow={false}
customInput={<CustomInput />}
filterDate={filterDate}
highlightDates={[{ 'custom--today': [new Date()] }]}
renderCustomHeader={({
date,
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/MiniCal/datepicker_override.css
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
.react-datepicker__year-text--in-selecting-range,
.react-datepicker__year-text--in-range {
border-radius: 0.3rem;
background-color: #000000;
background-color: black;
color: #fff;
}

Expand All @@ -78,7 +78,7 @@
.react-datepicker__quarter-text--keyboard-selected,
.react-datepicker__year-text--keyboard-selected {
border-radius: 0.3rem;
background-color: #000000;
background-color: rgba(0, 0, 0, 0.25);
color: #fff;
}

Expand Down
Loading