Basic log styling (#4634)

* basic log styling

* fixed mobile wrap and changed default event icon

* add group by test
This commit is contained in:
brendanlaschke
2024-03-25 10:15:39 +01:00
committed by GitHub
parent 0a15994695
commit 922d632607
10 changed files with 505 additions and 20 deletions

View File

@ -0,0 +1,33 @@
import { Event } from '@/activities/events/types/Event';
import { isDefined } from '~/utils/isDefined';
export type EventGroup = {
month: number;
year: number;
items: Event[];
};
export const groupEventsByMonth = (events: Event[]) => {
const acitivityGroups: EventGroup[] = [];
for (const event of events) {
const d = new Date(event.createdAt);
const month = d.getMonth();
const year = d.getFullYear();
const matchingGroup = acitivityGroups.find(
(x) => x.year === year && x.month === month,
);
if (isDefined(matchingGroup)) {
matchingGroup.items.push(event);
} else {
acitivityGroups.push({
year,
month,
items: [event],
});
}
}
return acitivityGroups.sort((a, b) => b.year - a.year || b.month - a.month);
};