Skip to content

Commit

Permalink
Merge pull request #99 from Elizabethhub/fix-bug-calendar
Browse files Browse the repository at this point in the history
Fix bug calendar
  • Loading branch information
Elizabethhub authored Mar 25, 2024
2 parents e5f2978 + adab055 commit 5e3e6ef
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions src/components/CalendarElement/CalendarElement.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ const CalendarElement = () => {
closeDayStat(event);
});

//
const spans = document.querySelectorAll('li > .day');

for (const span of spans) {
Expand All @@ -97,8 +96,8 @@ const CalendarElement = () => {
setChosenDay(Number(value));
});
}
//
console.log(monthWaterData);

// console.log(monthWaterData);
useEffect(() => {
const date = new Date();
const month = date.getMonth() + 1;
Expand All @@ -107,14 +106,41 @@ const CalendarElement = () => {
dispatch(fetchMonthWaterThunk({ year, month }));
}, [dispatch]);

const [month, setMonth] = useState(new Date().getMonth() + 1);
const [year, setYear] = useState(new Date().getFullYear());

useEffect(() => {
dispatch(fetchMonthWaterThunk({ year, month }));
}, [dispatch, month, year]);

function changeMonthQuery(direction) {
changeMonth(direction);

if (direction === 'forward') {
if (month >= 12) {
setMonth(1);
setYear(year + 1);
} else {
setMonth(month + 1);
}
} else {
if (month <= 1) {
setMonth(12);
setYear(year - 1);
} else {
setMonth(month - 1);
}
}
}

return (
<ContentWrapperCalendar>
<HeadingWrapper>
<MonthHeading>{t('month')}</MonthHeading>
<MonthSwitcher>
<button
className="arrow"
onClick={() => changeMonth('back')}
onClick={() => changeMonthQuery('back')}
type="button"
>
<ArrowLeftCalendarSvg />
Expand All @@ -125,7 +151,7 @@ const CalendarElement = () => {
</p>
<button
className="arrow"
onClick={() => changeMonth('forward')}
onClick={() => changeMonthQuery('forward')}
type="button"
>
<ArrowRightCalendarSvg />
Expand Down

0 comments on commit 5e3e6ef

Please sign in to comment.