2019-09-18 17:32:37 +02:00
|
|
|
<template>
|
2019-12-20 13:04:34 +01:00
|
|
|
<section class="section container">
|
2019-09-18 17:32:37 +02:00
|
|
|
<h1 class="title">
|
|
|
|
{{ $t('My events') }}
|
|
|
|
</h1>
|
|
|
|
<b-loading :active.sync="$apollo.loading"></b-loading>
|
|
|
|
<section v-if="futureParticipations.length > 0">
|
2020-02-18 08:47:41 +01:00
|
|
|
<subtitle>
|
2019-09-18 17:32:37 +02:00
|
|
|
{{ $t('Upcoming') }}
|
2020-02-18 08:47:41 +01:00
|
|
|
</subtitle>
|
2019-09-18 17:32:37 +02:00
|
|
|
<transition-group name="list" tag="p">
|
|
|
|
<div v-for="month in monthlyFutureParticipations" :key="month[0]">
|
2019-12-20 13:04:34 +01:00
|
|
|
<h3 class="upcoming-month">{{ month[0] }}</h3>
|
2019-09-18 17:32:37 +02:00
|
|
|
<EventListCard
|
|
|
|
v-for="participation in month[1]"
|
2019-10-13 16:24:43 +02:00
|
|
|
:key="participation.id"
|
2019-09-18 17:32:37 +02:00
|
|
|
: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>
|
|
|
|
</section>
|
2019-10-02 17:59:07 +02:00
|
|
|
<section v-if="drafts.length > 0">
|
2020-02-18 08:47:41 +01:00
|
|
|
<subtitle>
|
2019-10-02 17:59:07 +02:00
|
|
|
{{ $t('Drafts') }}
|
2020-02-18 08:47:41 +01:00
|
|
|
</subtitle>
|
2019-10-02 17:59:07 +02:00
|
|
|
<div class="columns is-multiline">
|
|
|
|
<EventCard
|
|
|
|
v-for="draft in drafts"
|
|
|
|
:key="draft.uuid"
|
|
|
|
:event="draft"
|
|
|
|
class="is-one-quarter-desktop column"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</section>
|
2019-09-18 17:32:37 +02:00
|
|
|
<section v-if="pastParticipations.length > 0">
|
2020-02-18 08:47:41 +01:00
|
|
|
<subtitle>
|
2019-09-18 17:32:37 +02:00
|
|
|
{{ $t('Past events') }}
|
2020-02-18 08:47:41 +01:00
|
|
|
</subtitle>
|
2019-09-18 17:32:37 +02:00
|
|
|
<transition-group name="list" tag="p">
|
|
|
|
<div v-for="month in monthlyPastParticipations" :key="month[0]">
|
|
|
|
<h3>{{ month[0] }}</h3>
|
|
|
|
<EventListCard
|
|
|
|
v-for="participation in month[1]"
|
2019-10-13 16:24:43 +02:00
|
|
|
:key="participation.id"
|
2019-09-18 17:32:37 +02:00
|
|
|
: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>
|
2019-12-20 13:04:34 +01:00
|
|
|
</section>
|
2019-09-18 17:32:37 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import { Component, Prop, Vue } from 'vue-property-decorator';
|
2019-10-02 17:59:07 +02:00
|
|
|
import { LOGGED_USER_PARTICIPATIONS, LOGGED_USER_DRAFTS } from '@/graphql/actor';
|
2019-10-11 16:11:39 +02:00
|
|
|
import { EventModel, IEvent, IParticipant, Participant, ParticipantRole } from '@/types/event.model';
|
2019-09-18 17:32:37 +02:00
|
|
|
import EventListCard from '@/components/Event/EventListCard.vue';
|
2019-10-02 17:59:07 +02:00
|
|
|
import EventCard from '@/components/Event/EventCard.vue';
|
2020-02-18 08:47:41 +01:00
|
|
|
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,
|
2019-10-03 16:54:56 +02:00
|
|
|
fetchPolicy: 'network-only',
|
2019-09-18 17:32:37 +02:00
|
|
|
variables: {
|
|
|
|
page: 1,
|
|
|
|
limit: 10,
|
|
|
|
afterDateTime: (new Date()).toISOString(),
|
|
|
|
},
|
|
|
|
update: data => data.loggedUser.participations.map(participation => new Participant(participation)),
|
|
|
|
},
|
2019-10-02 17:59:07 +02:00
|
|
|
drafts: {
|
|
|
|
query: LOGGED_USER_DRAFTS,
|
2019-10-03 16:54:56 +02:00
|
|
|
fetchPolicy: 'network-only',
|
2019-10-02 17:59:07 +02:00
|
|
|
variables: {
|
|
|
|
page: 1,
|
|
|
|
limit: 10,
|
|
|
|
},
|
|
|
|
update: data => data.loggedUser.drafts.map(event => new EventModel(event)),
|
|
|
|
},
|
2019-09-18 17:32:37 +02:00
|
|
|
pastParticipations: {
|
|
|
|
query: LOGGED_USER_PARTICIPATIONS,
|
2019-10-03 16:54:56 +02:00
|
|
|
fetchPolicy: 'network-only',
|
2019-09-18 17:32:37 +02:00
|
|
|
variables: {
|
|
|
|
page: 1,
|
|
|
|
limit: 10,
|
|
|
|
beforeDateTime: (new Date()).toISOString(),
|
|
|
|
},
|
|
|
|
update: data => data.loggedUser.participations.map(participation => new Participant(participation)),
|
|
|
|
},
|
|
|
|
},
|
2019-10-10 16:47:38 +02:00
|
|
|
metaInfo() {
|
|
|
|
return {
|
|
|
|
// 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-09-18 17:32:37 +02:00
|
|
|
})
|
|
|
|
export default class MyEvents extends Vue {
|
|
|
|
futurePage: number = 1;
|
|
|
|
pastPage: number = 1;
|
|
|
|
limit: number = 10;
|
|
|
|
|
|
|
|
futureParticipations: IParticipant[] = [];
|
|
|
|
hasMoreFutureParticipations: boolean = true;
|
|
|
|
|
|
|
|
pastParticipations: IParticipant[] = [];
|
|
|
|
hasMorePastParticipations: boolean = true;
|
|
|
|
|
2019-10-02 17:59:07 +02:00
|
|
|
drafts: IEvent[] = [];
|
|
|
|
|
2019-09-18 17:32:37 +02:00
|
|
|
private monthlyParticipations(participations: IParticipant[]): Map<string, Participant[]> {
|
2019-10-11 16:11:39 +02:00
|
|
|
const res = participations.filter(({ event, role }) => event.beginsOn != null && role !== ParticipantRole.REJECTED);
|
2019-09-18 17:32:37 +02:00
|
|
|
res.sort(
|
|
|
|
(a: IParticipant, b: IParticipant) => a.event.beginsOn.getTime() - b.event.beginsOn.getTime(),
|
|
|
|
);
|
|
|
|
return res.reduce((acc: Map<string, IParticipant[]>, participation: IParticipant) => {
|
|
|
|
const month = (new Date(participation.event.beginsOn)).toLocaleDateString(undefined, { year: 'numeric', month: 'long' });
|
|
|
|
const participations: IParticipant[] = acc.get(month) || [];
|
|
|
|
participations.push(participation);
|
|
|
|
acc.set(month, participations);
|
|
|
|
return acc;
|
|
|
|
}, new Map());
|
|
|
|
}
|
|
|
|
|
|
|
|
get monthlyFutureParticipations(): Map<string, Participant[]> {
|
|
|
|
return this.monthlyParticipations(this.futureParticipations);
|
|
|
|
}
|
|
|
|
|
|
|
|
get monthlyPastParticipations(): Map<string, Participant[]> {
|
|
|
|
return this.monthlyParticipations(this.pastParticipations);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 }) => {
|
|
|
|
const newParticipations = fetchMoreResult.loggedUser.participations;
|
|
|
|
this.hasMoreFutureParticipations = newParticipations.length === this.limit;
|
|
|
|
|
|
|
|
return {
|
|
|
|
loggedUser: {
|
|
|
|
__typename: previousResult.loggedUser.__typename,
|
|
|
|
participations: [...previousResult.loggedUser.participations, ...newParticipations],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
loadMorePastParticipations() {
|
|
|
|
this.pastPage += 1;
|
|
|
|
this.$apollo.queries.pastParticipations.fetchMore({
|
|
|
|
// New variables
|
|
|
|
variables: {
|
|
|
|
page: this.pastPage,
|
|
|
|
limit: this.limit,
|
|
|
|
},
|
|
|
|
// Transform the previous result with new data
|
|
|
|
updateQuery: (previousResult, { fetchMoreResult }) => {
|
|
|
|
const newParticipations = fetchMoreResult.loggedUser.participations;
|
|
|
|
this.hasMorePastParticipations = newParticipations.length === this.limit;
|
|
|
|
|
|
|
|
return {
|
|
|
|
loggedUser: {
|
|
|
|
__typename: previousResult.loggedUser.__typename,
|
|
|
|
participations: [...previousResult.loggedUser.participations, ...newParticipations],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
eventDeleted(eventid) {
|
|
|
|
this.futureParticipations = this.futureParticipations.filter(participation => participation.event.id !== eventid);
|
|
|
|
this.pastParticipations = this.pastParticipations.filter(participation => participation.event.id !== eventid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
@import "../../variables";
|
|
|
|
|
2019-12-20 13:04:34 +01:00
|
|
|
main > .container {
|
|
|
|
background: $white;
|
|
|
|
}
|
|
|
|
|
2019-09-18 17:32:37 +02:00
|
|
|
.participation {
|
|
|
|
margin: 1rem auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
section {
|
2019-12-20 13:04:34 +01:00
|
|
|
.upcoming-month {
|
|
|
|
text-transform: capitalize;
|
|
|
|
}
|
2019-09-18 17:32:37 +02:00
|
|
|
}
|
|
|
|
</style>
|