2019-09-18 17:32:37 +02:00
|
|
|
<template>
|
2020-02-18 08:57:00 +01:00
|
|
|
<section class="section container">
|
|
|
|
<h1 class="title">
|
|
|
|
{{ $t("My events") }}
|
|
|
|
</h1>
|
|
|
|
<b-loading :active.sync="$apollo.loading"></b-loading>
|
|
|
|
<section v-if="futureParticipations.length > 0">
|
|
|
|
<subtitle>
|
|
|
|
{{ $t("Upcoming") }}
|
|
|
|
</subtitle>
|
|
|
|
<transition-group name="list" tag="p">
|
|
|
|
<div v-for="month in monthlyFutureParticipations" :key="month[0]">
|
|
|
|
<span class="upcoming-month">{{ month[0] }}</span>
|
|
|
|
<EventListCard
|
|
|
|
v-for="participation in month[1]"
|
|
|
|
:key="participation.id"
|
|
|
|
:participation="participation"
|
|
|
|
:options="{ hideDate: false }"
|
|
|
|
@eventDeleted="eventDeleted"
|
|
|
|
class="participation"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</transition-group>
|
|
|
|
<div class="columns is-centered">
|
|
|
|
<b-button
|
|
|
|
class="column is-narrow"
|
|
|
|
v-if="hasMoreFutureParticipations && futureParticipations.length === limit"
|
|
|
|
@click="loadMoreFutureParticipations"
|
|
|
|
size="is-large"
|
|
|
|
type="is-primary"
|
|
|
|
>{{ $t("Load more") }}</b-button
|
|
|
|
>
|
|
|
|
</div>
|
2019-12-20 13:04:34 +01:00
|
|
|
</section>
|
2020-02-18 08:57:00 +01:00
|
|
|
<section v-if="drafts.length > 0">
|
|
|
|
<subtitle>
|
|
|
|
{{ $t("Drafts") }}
|
|
|
|
</subtitle>
|
|
|
|
<div class="columns is-multiline">
|
|
|
|
<EventCard
|
|
|
|
v-for="draft in drafts"
|
|
|
|
:key="draft.uuid"
|
|
|
|
:event="draft"
|
|
|
|
class="is-one-quarter-desktop column"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
<section v-if="pastParticipations.length > 0">
|
|
|
|
<subtitle>
|
|
|
|
{{ $t("Past events") }}
|
|
|
|
</subtitle>
|
|
|
|
<transition-group name="list" tag="p">
|
|
|
|
<div v-for="month in monthlyPastParticipations" :key="month[0]">
|
|
|
|
<span>{{ month[0] }}</span>
|
|
|
|
<EventListCard
|
|
|
|
v-for="participation in month[1]"
|
|
|
|
:key="participation.id"
|
|
|
|
:participation="participation"
|
|
|
|
:options="{ hideDate: false }"
|
|
|
|
@eventDeleted="eventDeleted"
|
|
|
|
class="participation"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</transition-group>
|
|
|
|
<div class="columns is-centered">
|
|
|
|
<b-button
|
|
|
|
class="column is-narrow"
|
|
|
|
v-if="hasMorePastParticipations && pastParticipations.length === limit"
|
|
|
|
@click="loadMorePastParticipations"
|
|
|
|
size="is-large"
|
|
|
|
type="is-primary"
|
|
|
|
>{{ $t("Load more") }}</b-button
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
<b-message
|
|
|
|
v-if="
|
|
|
|
futureParticipations.length === 0 &&
|
|
|
|
pastParticipations.length === 0 &&
|
|
|
|
$apollo.loading === false
|
|
|
|
"
|
|
|
|
type="is-danger"
|
|
|
|
>
|
|
|
|
{{ $t("No events found") }}
|
|
|
|
</b-message>
|
|
|
|
</section>
|
2019-09-18 17:32:37 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-02-18 08:57:00 +01:00
|
|
|
import { Component, Vue } from "vue-property-decorator";
|
|
|
|
import { LOGGED_USER_PARTICIPATIONS, LOGGED_USER_DRAFTS } from "../../graphql/actor";
|
|
|
|
import {
|
|
|
|
EventModel,
|
|
|
|
IEvent,
|
|
|
|
IParticipant,
|
|
|
|
Participant,
|
|
|
|
ParticipantRole,
|
|
|
|
} from "../../types/event.model";
|
|
|
|
import EventListCard from "../../components/Event/EventListCard.vue";
|
|
|
|
import EventCard from "../../components/Event/EventCard.vue";
|
|
|
|
import Subtitle from "../../components/Utils/Subtitle.vue";
|
2019-09-18 17:32:37 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
components: {
|
2020-02-18 08:47:41 +01:00
|
|
|
Subtitle,
|
2019-10-02 17:59:07 +02:00
|
|
|
EventCard,
|
2019-09-18 17:32:37 +02:00
|
|
|
EventListCard,
|
|
|
|
},
|
|
|
|
apollo: {
|
|
|
|
futureParticipations: {
|
|
|
|
query: LOGGED_USER_PARTICIPATIONS,
|
2020-02-18 08:57:00 +01:00
|
|
|
fetchPolicy: "network-only",
|
2019-09-18 17:32:37 +02:00
|
|
|
variables: {
|
|
|
|
page: 1,
|
|
|
|
limit: 10,
|
2020-02-18 08:57:00 +01:00
|
|
|
afterDateTime: new Date().toISOString(),
|
2019-09-18 17:32:37 +02:00
|
|
|
},
|
2020-02-18 08:57:00 +01:00
|
|
|
update: (data) =>
|
|
|
|
data.loggedUser.participations.elements.map(
|
|
|
|
(participation: IParticipant) => new Participant(participation)
|
|
|
|
),
|
2019-09-18 17:32:37 +02:00
|
|
|
},
|
2019-10-02 17:59:07 +02:00
|
|
|
drafts: {
|
|
|
|
query: LOGGED_USER_DRAFTS,
|
2020-02-18 08:57:00 +01:00
|
|
|
fetchPolicy: "network-only",
|
2019-10-02 17:59:07 +02:00
|
|
|
variables: {
|
|
|
|
page: 1,
|
|
|
|
limit: 10,
|
|
|
|
},
|
2020-02-18 08:57:00 +01:00
|
|
|
update: (data) => data.loggedUser.drafts.map((event: IEvent) => new EventModel(event)),
|
2019-10-02 17:59:07 +02:00
|
|
|
},
|
2019-09-18 17:32:37 +02:00
|
|
|
pastParticipations: {
|
|
|
|
query: LOGGED_USER_PARTICIPATIONS,
|
2020-02-18 08:57:00 +01:00
|
|
|
fetchPolicy: "network-only",
|
2019-09-18 17:32:37 +02:00
|
|
|
variables: {
|
|
|
|
page: 1,
|
|
|
|
limit: 10,
|
2020-02-18 08:57:00 +01:00
|
|
|
beforeDateTime: new Date().toISOString(),
|
2019-09-18 17:32:37 +02:00
|
|
|
},
|
2020-02-18 08:57:00 +01:00
|
|
|
update: (data) =>
|
|
|
|
data.loggedUser.participations.elements.map(
|
|
|
|
(participation: IParticipant) => new Participant(participation)
|
|
|
|
),
|
2019-09-18 17:32:37 +02:00
|
|
|
},
|
|
|
|
},
|
2019-10-10 16:47:38 +02:00
|
|
|
metaInfo() {
|
|
|
|
return {
|
2020-02-18 08:57:00 +01:00
|
|
|
// if no subcomponents specify a metaInfo.title, this title will be used
|
|
|
|
title: this.$t("My events") as string,
|
|
|
|
// all titles will be injected into this template
|
|
|
|
titleTemplate: "%s | Mobilizon",
|
2019-10-10 16:47:38 +02:00
|
|
|
};
|
|
|
|
},
|
2019-09-18 17:32:37 +02:00
|
|
|
})
|
|
|
|
export default class MyEvents extends Vue {
|
2020-02-18 08:57:00 +01:00
|
|
|
futurePage = 1;
|
|
|
|
|
|
|
|
pastPage = 1;
|
|
|
|
|
|
|
|
limit = 10;
|
2019-09-18 17:32:37 +02:00
|
|
|
|
|
|
|
futureParticipations: IParticipant[] = [];
|
2020-02-18 08:57:00 +01:00
|
|
|
|
|
|
|
hasMoreFutureParticipations = true;
|
2019-09-18 17:32:37 +02:00
|
|
|
|
|
|
|
pastParticipations: IParticipant[] = [];
|
2020-02-18 08:57:00 +01:00
|
|
|
|
|
|
|
hasMorePastParticipations = true;
|
2019-09-18 17:32:37 +02:00
|
|
|
|
2019-10-02 17:59:07 +02:00
|
|
|
drafts: IEvent[] = [];
|
|
|
|
|
2020-07-06 17:35:03 +02:00
|
|
|
static monthlyParticipations(
|
|
|
|
participations: IParticipant[],
|
2020-07-09 17:24:28 +02:00
|
|
|
revertSort = false
|
2020-07-06 17:35:03 +02:00
|
|
|
): Map<string, Participant[]> {
|
2020-02-18 08:57:00 +01:00
|
|
|
const res = participations.filter(
|
|
|
|
({ event, role }) => event.beginsOn != null && role !== ParticipantRole.REJECTED
|
|
|
|
);
|
2020-07-06 17:35:03 +02:00
|
|
|
if (revertSort) {
|
|
|
|
res.sort(
|
|
|
|
(a: IParticipant, b: IParticipant) =>
|
|
|
|
b.event.beginsOn.getTime() - a.event.beginsOn.getTime()
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
res.sort(
|
|
|
|
(a: IParticipant, b: IParticipant) =>
|
|
|
|
a.event.beginsOn.getTime() - b.event.beginsOn.getTime()
|
|
|
|
);
|
|
|
|
}
|
2019-09-18 17:32:37 +02:00
|
|
|
return res.reduce((acc: Map<string, IParticipant[]>, participation: IParticipant) => {
|
2020-02-18 08:57:00 +01:00
|
|
|
const month = new Date(participation.event.beginsOn).toLocaleDateString(undefined, {
|
|
|
|
year: "numeric",
|
|
|
|
month: "long",
|
|
|
|
});
|
|
|
|
const filteredParticipations: IParticipant[] = acc.get(month) || [];
|
|
|
|
filteredParticipations.push(participation);
|
|
|
|
acc.set(month, filteredParticipations);
|
2019-09-18 17:32:37 +02:00
|
|
|
return acc;
|
2020-02-18 08:57:00 +01:00
|
|
|
}, new Map());
|
2019-09-18 17:32:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
get monthlyFutureParticipations(): Map<string, Participant[]> {
|
2020-02-18 08:57:00 +01:00
|
|
|
return MyEvents.monthlyParticipations(this.futureParticipations);
|
2019-09-18 17:32:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
get monthlyPastParticipations(): Map<string, Participant[]> {
|
2020-07-06 17:35:03 +02:00
|
|
|
return MyEvents.monthlyParticipations(this.pastParticipations, true);
|
2019-09-18 17:32:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
loadMoreFutureParticipations() {
|
|
|
|
this.futurePage += 1;
|
|
|
|
this.$apollo.queries.futureParticipations.fetchMore({
|
|
|
|
// New variables
|
|
|
|
variables: {
|
|
|
|
page: this.futurePage,
|
|
|
|
limit: this.limit,
|
|
|
|
},
|
|
|
|
// Transform the previous result with new data
|
|
|
|
updateQuery: (previousResult, { fetchMoreResult }) => {
|
2020-07-06 17:35:03 +02:00
|
|
|
const oldParticipations = previousResult.loggedUser.participations;
|
2019-09-18 17:32:37 +02:00
|
|
|
const newParticipations = fetchMoreResult.loggedUser.participations;
|
2020-07-06 17:35:03 +02:00
|
|
|
this.hasMoreFutureParticipations =
|
|
|
|
newParticipations.total === oldParticipations.length + newParticipations.length;
|
2019-09-18 17:32:37 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
loggedUser: {
|
|
|
|
__typename: previousResult.loggedUser.__typename,
|
2020-07-06 17:35:03 +02:00
|
|
|
participations: {
|
|
|
|
__typename: newParticipations.__typename,
|
|
|
|
total: newParticipations.total,
|
|
|
|
elements: [...oldParticipations.elements, ...newParticipations.elements],
|
|
|
|
},
|
2019-09-18 17:32:37 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
loadMorePastParticipations() {
|
|
|
|
this.pastPage += 1;
|
|
|
|
this.$apollo.queries.pastParticipations.fetchMore({
|
2020-02-18 08:57:00 +01:00
|
|
|
// New variables
|
2019-09-18 17:32:37 +02:00
|
|
|
variables: {
|
|
|
|
page: this.pastPage,
|
|
|
|
limit: this.limit,
|
|
|
|
},
|
2020-02-18 08:57:00 +01:00
|
|
|
// Transform the previous result with new data
|
2019-09-18 17:32:37 +02:00
|
|
|
updateQuery: (previousResult, { fetchMoreResult }) => {
|
2020-07-06 17:35:03 +02:00
|
|
|
const oldParticipations = previousResult.loggedUser.participations;
|
2019-09-18 17:32:37 +02:00
|
|
|
const newParticipations = fetchMoreResult.loggedUser.participations;
|
2020-07-06 17:35:03 +02:00
|
|
|
this.hasMorePastParticipations =
|
|
|
|
newParticipations.total === oldParticipations.length + newParticipations.length;
|
2019-09-18 17:32:37 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
loggedUser: {
|
|
|
|
__typename: previousResult.loggedUser.__typename,
|
2020-07-06 17:35:03 +02:00
|
|
|
participations: {
|
|
|
|
__typename: newParticipations.__typename,
|
|
|
|
total: newParticipations.total,
|
|
|
|
elements: [...oldParticipations.elements, ...newParticipations.elements],
|
|
|
|
},
|
2019-09-18 17:32:37 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
eventDeleted(eventid: string) {
|
|
|
|
this.futureParticipations = this.futureParticipations.filter(
|
|
|
|
(participation) => participation.event.id !== eventid
|
|
|
|
);
|
|
|
|
this.pastParticipations = this.pastParticipations.filter(
|
|
|
|
(participation) => participation.event.id !== eventid
|
|
|
|
);
|
2019-09-18 17:32:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
|
|
|
<style lang="scss" scoped>
|
2020-02-18 08:57:00 +01:00
|
|
|
@import "../../variables";
|
2019-09-18 17:32:37 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
main > .container {
|
|
|
|
background: $white;
|
|
|
|
}
|
2019-12-20 13:04:34 +01:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
.participation {
|
|
|
|
margin: 1rem auto;
|
|
|
|
}
|
2019-09-18 17:32:37 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
section {
|
|
|
|
.upcoming-month {
|
|
|
|
text-transform: capitalize;
|
|
|
|
}
|
|
|
|
}
|
2019-09-18 17:32:37 +02:00
|
|
|
</style>
|