collapse yearmonths that are two months ahead by default in event calendar
This commit is contained in:
@ -118,7 +118,11 @@ export const EventContainer = ({
|
|||||||
<div className={styles.events}>
|
<div className={styles.events}>
|
||||||
<div className={styles.eventWrapper}>
|
<div className={styles.eventWrapper}>
|
||||||
<div className={styles.displayOptions}>
|
<div className={styles.displayOptions}>
|
||||||
<button onClick={() => setMode(null)} className="button toggler hasIcon" data-active={mode === "list"}>
|
<button
|
||||||
|
onClick={() => setMode(null)}
|
||||||
|
className="button toggler hasIcon"
|
||||||
|
data-active={mode === "list"}
|
||||||
|
>
|
||||||
<span>Vis liste</span>
|
<span>Vis liste</span>
|
||||||
<Icon type="list" />
|
<Icon type="list" />
|
||||||
</button>
|
</button>
|
||||||
@ -194,22 +198,33 @@ const CalendarDay = ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
const EventCalendar = ({ events }: { events: EventFragment[] }) => {
|
const EventCalendar = ({ events }: { events: EventFragment[] }) => {
|
||||||
const [showAll, setShowAll] = useState(false);
|
|
||||||
|
|
||||||
const futureSingularEvents = getSingularEvents(events).filter(
|
const futureSingularEvents = getSingularEvents(events).filter(
|
||||||
(x) => x.occurrence?.start && isTodayOrFuture(x.occurrence.start)
|
(x) => x.occurrence?.start && isTodayOrFuture(x.occurrence.start)
|
||||||
);
|
);
|
||||||
const eventsByDate = organizeEventsInCalendar(futureSingularEvents);
|
const eventsByDate = organizeEventsInCalendar(futureSingularEvents);
|
||||||
const yearMonths = Object.keys(eventsByDate);
|
const yearMonths = Object.keys(eventsByDate);
|
||||||
const visibleYearMonths = showAll ? yearMonths : yearMonths.slice(0, 2);
|
const [visibleYearMonths, setVisibleYearMonths] = useState(
|
||||||
|
yearMonths.slice(0, 2)
|
||||||
|
);
|
||||||
|
|
||||||
|
const toggleYearMonth = (yearMonth: string) => {
|
||||||
|
if (visibleYearMonths.includes(yearMonth)) {
|
||||||
|
setVisibleYearMonths(visibleYearMonths.filter((x) => x != yearMonth));
|
||||||
|
} else {
|
||||||
|
setVisibleYearMonths([...visibleYearMonths, yearMonth]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className={styles.eventCalendar}>
|
<div className={styles.eventCalendar}>
|
||||||
{Object.keys(eventsByDate)
|
{Object.keys(eventsByDate).map((yearMonth) => (
|
||||||
.filter((yearMonth) => visibleYearMonths.includes(yearMonth))
|
<div
|
||||||
.map((yearMonth) => (
|
key={yearMonth}
|
||||||
<div key={yearMonth} className={styles.calendarYearMonth}>
|
className={styles.calendarYearMonth}
|
||||||
|
data-collapsed={!visibleYearMonths.includes(yearMonth)}
|
||||||
|
onClick={() => toggleYearMonth(yearMonth)}
|
||||||
|
>
|
||||||
<h2>{formatYearMonth(yearMonth)}</h2>
|
<h2>{formatYearMonth(yearMonth)}</h2>
|
||||||
{Object.keys(eventsByDate[yearMonth]).map((week) => (
|
{Object.keys(eventsByDate[yearMonth]).map((week) => (
|
||||||
<div key={week} className={styles.calendarWeek}>
|
<div key={week} className={styles.calendarWeek}>
|
||||||
@ -225,12 +240,6 @@ const EventCalendar = ({ events }: { events: EventFragment[] }) => {
|
|||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
{!showAll && yearMonths.length > 2 && (
|
|
||||||
<button onClick={() => setShowAll(true)} className="button">
|
|
||||||
<span>Vis alt</span>
|
|
||||||
<Icon />
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -50,6 +50,10 @@
|
|||||||
text-transform: capitalize;
|
text-transform: capitalize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&[data-collapsed=true] > .calendarWeek {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.calendarWeek {
|
.calendarWeek {
|
||||||
|
Reference in New Issue
Block a user