2021-11-02 19:47:54 +01:00
|
|
|
<template>
|
|
|
|
<div class="events-wrapper">
|
2022-07-12 10:55:28 +02:00
|
|
|
<div class="flex flex-col gap-4" v-for="key of keys" :key="key">
|
2022-08-26 16:08:58 +02:00
|
|
|
<h2 class="month-name">
|
2021-11-02 19:47:54 +01:00
|
|
|
{{ monthName(groupEvents(key)[0]) }}
|
|
|
|
</h2>
|
|
|
|
<event-minimalist-card
|
|
|
|
v-for="event in groupEvents(key)"
|
|
|
|
:key="event.id"
|
|
|
|
:event="event"
|
|
|
|
:isCurrentActorMember="isCurrentActorMember"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
2022-07-12 10:55:28 +02:00
|
|
|
<script lang="ts" setup>
|
2021-11-02 19:47:54 +01:00
|
|
|
import { IEvent } from "@/types/event.model";
|
2022-07-12 10:55:28 +02:00
|
|
|
import { computed } from "vue";
|
2021-11-02 19:47:54 +01:00
|
|
|
import EventMinimalistCard from "./EventMinimalistCard.vue";
|
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const props = withDefaults(
|
|
|
|
defineProps<{
|
|
|
|
events: IEvent[];
|
|
|
|
isCurrentActorMember?: boolean;
|
|
|
|
}>(),
|
|
|
|
{ isCurrentActorMember: false }
|
|
|
|
);
|
2021-11-02 19:47:54 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const monthlyGroupedEvents = computed((): Map<string, IEvent[]> => {
|
|
|
|
return props.events.reduce((acc: Map<string, IEvent[]>, event: IEvent) => {
|
|
|
|
const beginsOn = new Date(event.beginsOn);
|
|
|
|
const month = `${beginsOn.getUTCMonth()}-${beginsOn.getUTCFullYear()}`;
|
|
|
|
const monthEvents = acc.get(month) || [];
|
|
|
|
acc.set(month, [...monthEvents, event]);
|
|
|
|
return acc;
|
|
|
|
}, new Map());
|
|
|
|
});
|
2021-11-02 19:47:54 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const keys = computed((): string[] => {
|
|
|
|
return Array.from(monthlyGroupedEvents.value.keys()).sort((a, b) =>
|
|
|
|
b.localeCompare(a)
|
|
|
|
);
|
|
|
|
});
|
2021-11-02 19:47:54 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const groupEvents = (key: string): IEvent[] => {
|
|
|
|
return monthlyGroupedEvents.value.get(key) || [];
|
|
|
|
};
|
2021-11-02 19:47:54 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const monthName = (event: IEvent): string => {
|
|
|
|
const beginsOn = new Date(event.beginsOn);
|
|
|
|
return new Intl.DateTimeFormat(undefined, {
|
|
|
|
month: "long",
|
|
|
|
year: "numeric",
|
|
|
|
}).format(beginsOn);
|
|
|
|
};
|
2021-11-02 19:47:54 +01:00
|
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.events-wrapper {
|
|
|
|
display: grid;
|
|
|
|
grid-gap: 20px;
|
|
|
|
grid-template: 1fr;
|
|
|
|
}
|
|
|
|
.month-group {
|
|
|
|
.month-name {
|
|
|
|
text-transform: capitalize;
|
|
|
|
text-transform: capitalize;
|
|
|
|
display: inline-block;
|
|
|
|
position: relative;
|
|
|
|
font-size: 1.3rem;
|
|
|
|
|
|
|
|
&::after {
|
|
|
|
position: absolute;
|
|
|
|
left: 0;
|
|
|
|
right: 0;
|
|
|
|
top: 100%;
|
|
|
|
content: "";
|
|
|
|
width: calc(100% + 30px);
|
|
|
|
height: 3px;
|
|
|
|
max-width: 150px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|