2019-01-21 14:08:22 +00:00
|
|
|
<template>
|
2019-10-05 17:07:50 +00:00
|
|
|
<div>
|
2019-10-07 14:48:13 +00:00
|
|
|
<section class="hero is-medium is-light is-bold" v-if="config && (!currentUser.id || !currentActor.id)">
|
2019-10-05 17:07:50 +00:00
|
|
|
<div class="hero-body">
|
|
|
|
<div class="container">
|
2019-10-07 14:48:13 +00:00
|
|
|
<h1 class="title">{{ $t('Gather ⋅ Organize ⋅ Mobilize') }}</h1>
|
|
|
|
<p class="subtitle">{{ $t('Join {instance}, a Mobilizon instance', { instance: config.name }) }}
|
|
|
|
<p>{{ config.description }}</p>
|
|
|
|
<!-- We don't invite to find other instances yet -->
|
|
|
|
<!-- <p v-if="!config.registrationsOpen">
|
|
|
|
{{ $t("This instance isn't opened to registrations, but you can register on other instances.") }}
|
|
|
|
</p> -->
|
|
|
|
<b-message type="is-danger" v-if="!config.registrationsOpen">
|
|
|
|
{{ $t("Unfortunately, this instance isn't opened to registrations") }}
|
|
|
|
</b-message>
|
|
|
|
<div class="buttons">
|
|
|
|
<b-button type="is-primary" tag="router-link" :to="{ name: RouteName.REGISTER }" v-if="config.registrationsOpen">
|
|
|
|
{{ $t('Sign up') }}
|
|
|
|
</b-button>
|
|
|
|
<!-- We don't invite to find other instances yet -->
|
|
|
|
<!-- <b-button v-else type="is-link" tag="a" href="https://joinmastodon.org">{{ $t('Find an instance') }}</b-button> -->
|
|
|
|
<b-button type="is-text" tag="router-link" :to="{ name: RouteName.ABOUT }">{{ $t('Learn more about Mobilizon')}}</b-button>
|
2019-10-05 17:07:50 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
<div class="container" v-if="config">
|
|
|
|
<section v-if="currentActor.id">
|
|
|
|
<b-message type="is-info">
|
|
|
|
{{ $t('Welcome back {username}', { username: currentActor.displayName() }) }}
|
|
|
|
</b-message>
|
|
|
|
</section>
|
2019-10-08 17:41:14 +00:00
|
|
|
<section v-if="currentActor.id && goingToEvents.size > 0" class="container">
|
2019-10-05 17:07:50 +00:00
|
|
|
<h3 class="title">
|
|
|
|
{{ $t("Upcoming") }}
|
|
|
|
</h3>
|
|
|
|
<b-loading :active.sync="$apollo.loading"></b-loading>
|
2019-10-07 14:48:13 +00:00
|
|
|
<div v-for="row of goingToEvents" class="upcoming-events" :key="row[0]">
|
2019-10-05 17:07:50 +00:00
|
|
|
<span class="date-component-container" v-if="isInLessThanSevenDays(row[0])">
|
|
|
|
<date-component :date="row[0]"></date-component>
|
|
|
|
<h3 class="subtitle"
|
|
|
|
v-if="isToday(row[0])">
|
|
|
|
{{ $tc('You have one event today.', row[1].length, {count: row[1].length}) }}
|
|
|
|
</h3>
|
|
|
|
<h3 class="subtitle"
|
|
|
|
v-else-if="isTomorrow(row[0])">
|
|
|
|
{{ $tc('You have one event tomorrow.', row[1].length, {count: row[1].length}) }}
|
|
|
|
</h3>
|
|
|
|
<h3 class="subtitle"
|
|
|
|
v-else-if="isInLessThanSevenDays(row[0])">
|
|
|
|
{{ $tc('You have one event in {days} days.', row[1].length, {count: row[1].length, days: calculateDiffDays(row[0])}) }}
|
|
|
|
</h3>
|
|
|
|
</span>
|
|
|
|
<div>
|
|
|
|
<EventListCard
|
|
|
|
v-for="participation in row[1]"
|
|
|
|
v-if="isInLessThanSevenDays(row[0])"
|
|
|
|
:key="participation[1].event.uuid"
|
|
|
|
:participation="participation[1]"
|
|
|
|
/>
|
|
|
|
</div>
|
2019-01-21 14:08:22 +00:00
|
|
|
</div>
|
2019-10-05 17:07:50 +00:00
|
|
|
<span class="view-all">
|
|
|
|
<router-link :to=" { name: RouteName.MY_EVENTS }">{{ $t('View everything')}} >></router-link>
|
2019-09-18 15:32:37 +00:00
|
|
|
</span>
|
2019-10-05 17:07:50 +00:00
|
|
|
</section>
|
|
|
|
<section v-if="currentActor && lastWeekEvents.length > 0">
|
|
|
|
<h3 class="title">
|
|
|
|
{{ $t("Last week") }}
|
|
|
|
</h3>
|
|
|
|
<b-loading :active.sync="$apollo.loading"></b-loading>
|
2019-09-26 14:38:58 +00:00
|
|
|
<div>
|
2019-10-05 17:07:50 +00:00
|
|
|
<EventListCard
|
|
|
|
v-for="participation in lastWeekEvents"
|
|
|
|
:key="participation.id"
|
|
|
|
:participation="participation"
|
|
|
|
:options="{ hideDate: false }"
|
|
|
|
/>
|
2019-03-21 19:23:42 +00:00
|
|
|
</div>
|
2019-10-05 17:07:50 +00:00
|
|
|
</section>
|
2019-10-07 14:48:13 +00:00
|
|
|
<section class="events-featured">
|
|
|
|
<h3 class="title">{{ $t('Featured events') }}</h3>
|
2019-10-05 17:07:50 +00:00
|
|
|
<b-loading :active.sync="$apollo.loading"></b-loading>
|
2019-10-08 17:41:14 +00:00
|
|
|
<div v-if="filteredFeaturedEvents.length > 0" class="columns is-multiline">
|
|
|
|
<div class="column is-one-third-desktop" v-for="event in filteredFeaturedEvents.slice(0, 6)" :key="event.uuid">
|
2019-10-05 17:07:50 +00:00
|
|
|
<EventCard
|
|
|
|
:event="event"
|
|
|
|
/>
|
|
|
|
</div>
|
2019-04-03 15:29:03 +00:00
|
|
|
</div>
|
2019-10-05 17:07:50 +00:00
|
|
|
<b-message v-else type="is-danger">
|
|
|
|
{{ $t('No events found') }}
|
|
|
|
</b-message>
|
|
|
|
</section>
|
|
|
|
</div>
|
2019-01-21 14:08:22 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2019-02-22 13:55:47 +00:00
|
|
|
import ngeohash from 'ngeohash';
|
|
|
|
import { FETCH_EVENTS } from '@/graphql/event';
|
|
|
|
import { Component, Vue } from 'vue-property-decorator';
|
2019-09-18 15:32:37 +00:00
|
|
|
import EventListCard from '@/components/Event/EventListCard.vue';
|
2019-02-22 13:55:47 +00:00
|
|
|
import EventCard from '@/components/Event/EventCard.vue';
|
2019-09-18 15:32:37 +00:00
|
|
|
import { CURRENT_ACTOR_CLIENT, LOGGED_USER_PARTICIPATIONS } from '@/graphql/actor';
|
2019-04-26 13:22:16 +00:00
|
|
|
import { IPerson, Person } from '@/types/actor';
|
2019-02-22 13:55:47 +00:00
|
|
|
import { ICurrentUser } from '@/types/current-user.model';
|
|
|
|
import { CURRENT_USER_CLIENT } from '@/graphql/user';
|
|
|
|
import { RouteName } from '@/router';
|
2019-09-18 15:32:37 +00:00
|
|
|
import { EventModel, IEvent, IParticipant, Participant } from '@/types/event.model';
|
2019-04-03 15:29:03 +00:00
|
|
|
import DateComponent from '@/components/Event/DateCalendarIcon.vue';
|
|
|
|
import { CONFIG } from '@/graphql/config';
|
|
|
|
import { IConfig } from '@/types/config.model';
|
2019-01-21 14:08:22 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
apollo: {
|
|
|
|
events: {
|
|
|
|
query: FETCH_EVENTS,
|
2019-03-22 09:57:14 +00:00
|
|
|
fetchPolicy: 'no-cache', // Debug me: https://github.com/apollographql/apollo-client/issues/3030
|
2019-01-21 14:08:22 +00:00
|
|
|
},
|
2019-09-18 15:32:37 +00:00
|
|
|
currentActor: {
|
|
|
|
query: CURRENT_ACTOR_CLIENT,
|
2019-10-03 09:37:34 +00:00
|
|
|
update: data => new Person(data.currentActor),
|
2019-01-21 14:08:22 +00:00
|
|
|
},
|
|
|
|
currentUser: {
|
2019-03-22 09:57:14 +00:00
|
|
|
query: CURRENT_USER_CLIENT,
|
|
|
|
},
|
2019-04-03 15:29:03 +00:00
|
|
|
config: {
|
|
|
|
query: CONFIG,
|
|
|
|
},
|
2019-10-07 14:48:13 +00:00
|
|
|
currentUserParticipations: {
|
|
|
|
query: LOGGED_USER_PARTICIPATIONS,
|
|
|
|
variables() {
|
|
|
|
const lastWeek = new Date();
|
|
|
|
lastWeek.setDate(new Date().getDate() - 7);
|
|
|
|
return {
|
|
|
|
afterDateTime: lastWeek.toISOString(),
|
|
|
|
};
|
|
|
|
},
|
|
|
|
update: (data) => {
|
|
|
|
return data.loggedUser.participations.map(participation => new Participant(participation));
|
|
|
|
},
|
|
|
|
skip() {
|
|
|
|
return this.currentUser.isLoggedIn === false;
|
|
|
|
},
|
|
|
|
},
|
2019-01-21 14:08:22 +00:00
|
|
|
},
|
|
|
|
components: {
|
2019-03-21 19:23:42 +00:00
|
|
|
DateComponent,
|
2019-09-18 15:32:37 +00:00
|
|
|
EventListCard,
|
2019-03-22 09:57:14 +00:00
|
|
|
EventCard,
|
|
|
|
},
|
2019-01-21 14:08:22 +00:00
|
|
|
})
|
|
|
|
export default class Home extends Vue {
|
2019-10-08 18:00:26 +00:00
|
|
|
events: IEvent[] = [];
|
2019-01-21 14:08:22 +00:00
|
|
|
locations = [];
|
|
|
|
city = { name: null };
|
|
|
|
country = { name: null };
|
|
|
|
currentUser!: ICurrentUser;
|
2019-09-18 15:32:37 +00:00
|
|
|
currentActor!: IPerson;
|
2019-10-07 14:48:13 +00:00
|
|
|
config!: IConfig;
|
2019-07-23 16:36:17 +00:00
|
|
|
RouteName = RouteName;
|
2019-01-21 14:08:22 +00:00
|
|
|
|
2019-10-07 14:48:13 +00:00
|
|
|
currentUserParticipations: IParticipant[] = [];
|
|
|
|
|
2019-04-03 15:29:03 +00:00
|
|
|
// get displayed_name() {
|
|
|
|
// return this.loggedPerson && this.loggedPerson.name === null
|
|
|
|
// ? this.loggedPerson.preferredUsername
|
|
|
|
// : this.loggedPerson.name;
|
|
|
|
// }
|
2019-01-21 14:08:22 +00:00
|
|
|
|
2019-09-18 15:32:37 +00:00
|
|
|
isToday(date: Date) {
|
2019-03-21 19:23:42 +00:00
|
|
|
return (new Date(date)).toDateString() === (new Date()).toDateString();
|
|
|
|
}
|
|
|
|
|
|
|
|
isTomorrow(date: string) :boolean {
|
|
|
|
return this.isInDays(date, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
isInDays(date: string, nbDays: number) :boolean {
|
|
|
|
return this.calculateDiffDays(date) === nbDays;
|
|
|
|
}
|
|
|
|
|
|
|
|
isBefore(date: string, nbDays: number) :boolean {
|
2019-09-18 15:32:37 +00:00
|
|
|
return this.calculateDiffDays(date) < nbDays;
|
2019-03-21 19:23:42 +00:00
|
|
|
}
|
|
|
|
|
2019-09-20 16:22:03 +00:00
|
|
|
isAfter(date: string, nbDays: number) :boolean {
|
|
|
|
return this.calculateDiffDays(date) >= nbDays;
|
|
|
|
}
|
|
|
|
|
2019-03-21 19:23:42 +00:00
|
|
|
isInLessThanSevenDays(date: string): boolean {
|
2019-09-18 15:32:37 +00:00
|
|
|
return this.isBefore(date, 7);
|
2019-03-21 19:23:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
calculateDiffDays(date: string): number {
|
2019-09-18 15:32:37 +00:00
|
|
|
return Math.ceil(((new Date(date)).getTime() - (new Date()).getTime()) / 1000 / 60 / 60 / 24);
|
2019-03-21 19:23:42 +00:00
|
|
|
}
|
|
|
|
|
2019-09-18 15:32:37 +00:00
|
|
|
get goingToEvents(): Map<string, Map<string, IParticipant>> {
|
|
|
|
const res = this.currentUserParticipations.filter(({ event }) => {
|
2019-09-20 16:22:03 +00:00
|
|
|
return event.beginsOn != null && this.isAfter(event.beginsOn.toDateString(), 0) && this.isBefore(event.beginsOn.toDateString(), 7);
|
2019-03-21 19:23:42 +00:00
|
|
|
});
|
|
|
|
res.sort(
|
2019-09-18 15:32:37 +00:00
|
|
|
(a: IParticipant, b: IParticipant) => a.event.beginsOn.getTime() - b.event.beginsOn.getTime(),
|
2019-03-21 19:23:42 +00:00
|
|
|
);
|
2019-10-07 14:48:13 +00:00
|
|
|
|
2019-09-18 15:32:37 +00:00
|
|
|
return res.reduce((acc: Map<string, Map<string, IParticipant>>, participation: IParticipant) => {
|
|
|
|
const day = (new Date(participation.event.beginsOn)).toDateString();
|
|
|
|
const participations: Map<string, IParticipant> = acc.get(day) || new Map();
|
2019-09-20 16:22:03 +00:00
|
|
|
participations.set(`${participation.event.uuid}${participation.actor.id}`, participation);
|
2019-09-18 15:32:37 +00:00
|
|
|
acc.set(day, participations);
|
2019-03-21 19:23:42 +00:00
|
|
|
return acc;
|
2019-04-03 15:29:03 +00:00
|
|
|
}, new Map());
|
2019-01-21 14:08:22 +00:00
|
|
|
}
|
|
|
|
|
2019-09-18 15:32:37 +00:00
|
|
|
get lastWeekEvents() {
|
|
|
|
const res = this.currentUserParticipations.filter(({ event }) => {
|
|
|
|
return event.beginsOn != null && this.isBefore(event.beginsOn.toDateString(), 0);
|
|
|
|
});
|
|
|
|
res.sort(
|
|
|
|
(a: IParticipant, b: IParticipant) => a.event.beginsOn.getTime() - b.event.beginsOn.getTime(),
|
|
|
|
);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2019-10-08 17:41:14 +00:00
|
|
|
get filteredFeaturedEvents() {
|
2019-10-08 18:00:26 +00:00
|
|
|
if (!this.currentUser.isLoggedIn || !this.currentActor.id) return this.events;
|
|
|
|
return this.events.filter(event => event.organizerActor && event.organizerActor.id !== this.currentActor.id);
|
2019-10-08 17:41:14 +00:00
|
|
|
}
|
|
|
|
|
2019-01-21 14:08:22 +00:00
|
|
|
geoLocalize() {
|
|
|
|
const router = this.$router;
|
2019-02-22 13:55:47 +00:00
|
|
|
const sessionCity = sessionStorage.getItem('City');
|
|
|
|
|
2019-01-21 14:08:22 +00:00
|
|
|
if (sessionCity) {
|
2019-02-22 13:55:47 +00:00
|
|
|
return router.push({ name: 'EventList', params: { location: sessionCity } });
|
2019-01-21 14:08:22 +00:00
|
|
|
}
|
2019-02-22 13:55:47 +00:00
|
|
|
|
|
|
|
navigator.geolocation.getCurrentPosition(
|
|
|
|
pos => {
|
|
|
|
const crd = pos.coords;
|
|
|
|
|
|
|
|
const geoHash = ngeohash.encode(crd.latitude, crd.longitude, 11);
|
|
|
|
sessionStorage.setItem('City', geoHash);
|
|
|
|
router.push({ name: RouteName.EVENT_LIST, params: { location: geoHash } });
|
|
|
|
},
|
|
|
|
|
|
|
|
err => console.warn(`ERROR(${err.code}): ${err.message}`),
|
|
|
|
|
|
|
|
{
|
|
|
|
enableHighAccuracy: true,
|
|
|
|
timeout: 5000,
|
|
|
|
maximumAge: 0,
|
|
|
|
},
|
|
|
|
);
|
2019-01-21 14:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getAddressData(addressData) {
|
2019-02-22 13:55:47 +00:00
|
|
|
const geoHash = ngeohash.encode(
|
2019-01-21 14:08:22 +00:00
|
|
|
addressData.latitude,
|
|
|
|
addressData.longitude,
|
2019-03-22 09:57:14 +00:00
|
|
|
11,
|
2019-01-21 14:08:22 +00:00
|
|
|
);
|
2019-03-22 09:57:14 +00:00
|
|
|
sessionStorage.setItem('City', geoHash);
|
2019-02-22 13:55:47 +00:00
|
|
|
|
|
|
|
this.$router.push({ name: RouteName.EVENT_LIST, params: { location: geoHash } });
|
2019-01-21 14:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
viewEvent(event) {
|
2019-02-22 13:55:47 +00:00
|
|
|
this.$router.push({ name: RouteName.EVENT, params: { uuid: event.uuid } });
|
2019-01-21 14:08:22 +00:00
|
|
|
}
|
|
|
|
|
2019-04-03 15:29:03 +00:00
|
|
|
// ipLocation() {
|
|
|
|
// return this.city.name ? this.city.name : this.country.name;
|
|
|
|
// }
|
2019-01-21 14:08:22 +00:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
2019-09-20 16:22:03 +00:00
|
|
|
<style lang="scss" scoped>
|
2019-10-05 17:07:50 +00:00
|
|
|
@import "@/variables.scss";
|
|
|
|
|
2019-01-21 14:08:22 +00:00
|
|
|
.search-autocomplete {
|
|
|
|
border: 1px solid #dbdbdb;
|
|
|
|
color: rgba(0, 0, 0, 0.87);
|
|
|
|
}
|
|
|
|
|
2019-10-07 14:48:13 +00:00
|
|
|
.events-featured {
|
2019-03-21 19:23:42 +00:00
|
|
|
margin: 25px auto;
|
2019-10-07 14:48:13 +00:00
|
|
|
|
|
|
|
.columns {
|
|
|
|
margin: 1rem auto 3rem;
|
|
|
|
}
|
2019-01-21 14:08:22 +00:00
|
|
|
}
|
2019-09-18 15:32:37 +00:00
|
|
|
|
|
|
|
.date-component-container {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
margin: 1.5rem auto;
|
|
|
|
|
|
|
|
h3.subtitle {
|
|
|
|
margin-left: 7px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
section.container {
|
|
|
|
margin: auto auto 3rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
span.view-all {
|
|
|
|
display: block;
|
|
|
|
margin-top: 2rem;
|
|
|
|
text-align: right;
|
|
|
|
|
|
|
|
a {
|
|
|
|
text-decoration: underline;
|
|
|
|
}
|
|
|
|
}
|
2019-10-05 17:07:50 +00:00
|
|
|
|
|
|
|
section.hero {
|
|
|
|
margin-top: -3px;
|
|
|
|
background: lighten($secondary, 20%);
|
|
|
|
|
|
|
|
.column figure.image img {
|
2019-10-07 14:48:13 +00:00
|
|
|
max-width: 400px;
|
2019-10-05 17:07:50 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-21 14:08:22 +00:00
|
|
|
</style>
|