show year in calendar if not current year
This commit is contained in:
@ -244,6 +244,16 @@ const CalendarWeek = ({ days }: { days: Record<string, SingularEvent[]> }) => {
|
||||
);
|
||||
};
|
||||
|
||||
function maybeYear(yearMonthString: string) {
|
||||
const yearMonth = new Date(yearMonthString);
|
||||
const now = new Date();
|
||||
const isCurrentYear = yearMonth.getFullYear() == now.getFullYear();
|
||||
if (isCurrentYear) {
|
||||
return <span className="sr-only"> {yearMonth.getFullYear()}</span>;
|
||||
}
|
||||
return ` ${yearMonth.getFullYear()}`;
|
||||
}
|
||||
|
||||
const EventCalendar = ({ events }: { events: EventFragment[] }) => {
|
||||
const futureSingularEvents = getSingularEvents(events).filter(
|
||||
(x) => x.occurrence?.start && isTodayOrFuture(x.occurrence.start)
|
||||
@ -275,6 +285,7 @@ const EventCalendar = ({ events }: { events: EventFragment[] }) => {
|
||||
),
|
||||
0
|
||||
);
|
||||
|
||||
return (
|
||||
<div
|
||||
key={yearMonth}
|
||||
@ -282,7 +293,8 @@ const EventCalendar = ({ events }: { events: EventFragment[] }) => {
|
||||
data-collapsed={!visibleYearMonths.includes(yearMonth)}
|
||||
>
|
||||
<h2 onClick={() => toggleYearMonth(yearMonth)}>
|
||||
{formatYearMonth(yearMonth)}{" "}
|
||||
{formatYearMonth(yearMonth)}
|
||||
{maybeYear(yearMonth)}{" "}
|
||||
<span className={styles.eventCounter}>({eventCount})</span>
|
||||
</h2>
|
||||
{eventCount === 0 && (
|
||||
|
Reference in New Issue
Block a user