2019-01-21 15:08:22 +01:00
|
|
|
<template>
|
2019-08-12 16:04:16 +02:00
|
|
|
<div class="container" v-if="config">
|
2019-01-24 15:57:45 +01:00
|
|
|
<section class="hero is-link" v-if="!currentUser.id || !loggedPerson">
|
2019-01-21 15:08:22 +01:00
|
|
|
<div class="hero-body">
|
|
|
|
<div class="container">
|
2019-04-03 17:29:03 +02:00
|
|
|
<h1 class="title">{{ config.name }}</h1>
|
|
|
|
<h2 class="subtitle">{{ config.description }}</h2>
|
|
|
|
<router-link class="button" :to="{ name: 'Register' }" v-if="config.registrationsOpen">
|
2019-01-21 15:08:22 +01:00
|
|
|
<translate>Register</translate>
|
|
|
|
</router-link>
|
2019-04-03 17:29:03 +02:00
|
|
|
<p v-else>
|
|
|
|
<translate>This instance isn't opened to registrations, but you can register on other instances.</translate>
|
|
|
|
</p>
|
2019-01-21 15:08:22 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
<section v-else>
|
|
|
|
<h1>
|
|
|
|
<translate
|
|
|
|
:translate-params="{username: loggedPerson.preferredUsername}"
|
|
|
|
>Welcome back %{username}</translate>
|
|
|
|
</h1>
|
|
|
|
</section>
|
2019-07-23 18:36:17 +02:00
|
|
|
<b-dropdown aria-role="list">
|
|
|
|
<button class="button is-primary" slot="trigger">
|
|
|
|
<span>Create</span>
|
|
|
|
<b-icon icon="menu-down"></b-icon>
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<b-dropdown-item aria-role="listitem">
|
|
|
|
<router-link :to="{ name: RouteName.CREATE_EVENT }">Event</router-link>
|
|
|
|
</b-dropdown-item>
|
|
|
|
<b-dropdown-item aria-role="listitem">
|
|
|
|
<router-link :to="{ name: RouteName.CREATE_GROUP }">Group</router-link>
|
|
|
|
</b-dropdown-item>
|
|
|
|
<b-dropdown-item aria-role="listitem">Something else</b-dropdown-item>
|
|
|
|
</b-dropdown>
|
2019-04-03 17:29:03 +02:00
|
|
|
<section v-if="loggedPerson" class="container">
|
|
|
|
<span class="events-nearby title"><translate>Events you're going at</translate></span>
|
2019-03-21 20:23:42 +01:00
|
|
|
<b-loading :active.sync="$apollo.loading"></b-loading>
|
|
|
|
<div v-if="goingToEvents.size > 0" v-for="row in Array.from(goingToEvents.entries())">
|
|
|
|
<!-- Iterators will be supported in v-for with VueJS 3 -->
|
|
|
|
<date-component :date="row[0]"></date-component>
|
|
|
|
<h3 class="subtitle"
|
|
|
|
v-if="isToday(row[0])"
|
|
|
|
v-translate="{count: row[1].length}"
|
|
|
|
:translate-n="row[1].length"
|
|
|
|
translate-plural="You have %{ count } events today"
|
|
|
|
>
|
|
|
|
You have one event today.
|
|
|
|
</h3>
|
|
|
|
<h3 class="subtitle"
|
|
|
|
v-else-if="isTomorrow(row[0])"
|
|
|
|
v-translate="{count: row[1].length}"
|
|
|
|
:translate-n="row[1].length"
|
|
|
|
translate-plural="You have %{ count } events tomorrow"
|
|
|
|
>
|
|
|
|
You have one event tomorrow.
|
|
|
|
</h3>
|
|
|
|
<h3 class="subtitle"
|
|
|
|
v-else
|
|
|
|
v-translate="{count: row[1].length, days: calculateDiffDays(row[0])}"
|
|
|
|
:translate-n="row[1].length"
|
|
|
|
translate-plural="You have %{ count } events in %{ days } days"
|
|
|
|
>
|
|
|
|
You have one event in %{ days } days.
|
|
|
|
</h3>
|
|
|
|
<div class="columns">
|
|
|
|
<EventCard
|
|
|
|
v-for="event in row[1]"
|
|
|
|
:key="event.uuid"
|
|
|
|
:event="event"
|
|
|
|
:options="{loggedPerson: loggedPerson}"
|
|
|
|
class="column is-one-quarter-desktop is-half-mobile"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<b-message v-else type="is-danger">
|
|
|
|
<translate>You're not going to any event yet</translate>
|
|
|
|
</b-message>
|
|
|
|
</section>
|
2019-04-03 17:29:03 +02:00
|
|
|
<section class="container">
|
|
|
|
<h3 class="events-nearby title"><translate>Events nearby you</translate></h3>
|
2019-01-21 15:08:22 +01:00
|
|
|
<b-loading :active.sync="$apollo.loading"></b-loading>
|
|
|
|
<div v-if="events.length > 0" class="columns is-multiline">
|
2019-04-03 17:29:03 +02:00
|
|
|
<div class="column is-one-third-desktop" v-for="event in events.slice(0, 6)" :key="event.uuid">
|
|
|
|
<EventCard
|
|
|
|
:event="event"
|
|
|
|
/>
|
|
|
|
</div>
|
2019-01-21 15:08:22 +01:00
|
|
|
</div>
|
|
|
|
<b-message v-else type="is-danger">
|
|
|
|
<translate>No events found</translate>
|
|
|
|
</b-message>
|
|
|
|
</section>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2019-02-22 14:55:47 +01:00
|
|
|
import ngeohash from 'ngeohash';
|
|
|
|
import { FETCH_EVENTS } from '@/graphql/event';
|
|
|
|
import { Component, Vue } from 'vue-property-decorator';
|
|
|
|
import EventCard from '@/components/Event/EventCard.vue';
|
2019-03-21 20:23:42 +01:00
|
|
|
import { LOGGED_PERSON_WITH_GOING_TO_EVENTS } from '@/graphql/actor';
|
2019-04-26 15:22:16 +02:00
|
|
|
import { IPerson, Person } from '@/types/actor';
|
2019-02-22 14:55:47 +01:00
|
|
|
import { ICurrentUser } from '@/types/current-user.model';
|
|
|
|
import { CURRENT_USER_CLIENT } from '@/graphql/user';
|
|
|
|
import { RouteName } from '@/router';
|
2019-03-21 20:23:42 +01:00
|
|
|
import { IEvent } from '@/types/event.model';
|
2019-04-03 17:29:03 +02:00
|
|
|
import DateComponent from '@/components/Event/DateCalendarIcon.vue';
|
|
|
|
import { CONFIG } from '@/graphql/config';
|
|
|
|
import { IConfig } from '@/types/config.model';
|
2019-01-21 15:08:22 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
apollo: {
|
|
|
|
events: {
|
|
|
|
query: FETCH_EVENTS,
|
2019-03-22 10:57:14 +01:00
|
|
|
fetchPolicy: 'no-cache', // Debug me: https://github.com/apollographql/apollo-client/issues/3030
|
2019-01-21 15:08:22 +01:00
|
|
|
},
|
|
|
|
loggedPerson: {
|
2019-03-21 20:23:42 +01:00
|
|
|
query: LOGGED_PERSON_WITH_GOING_TO_EVENTS,
|
2019-01-21 15:08:22 +01:00
|
|
|
},
|
|
|
|
currentUser: {
|
2019-03-22 10:57:14 +01:00
|
|
|
query: CURRENT_USER_CLIENT,
|
|
|
|
},
|
2019-04-03 17:29:03 +02:00
|
|
|
config: {
|
|
|
|
query: CONFIG,
|
|
|
|
},
|
2019-01-21 15:08:22 +01:00
|
|
|
},
|
|
|
|
components: {
|
2019-03-21 20:23:42 +01:00
|
|
|
DateComponent,
|
2019-03-22 10:57:14 +01:00
|
|
|
EventCard,
|
|
|
|
},
|
2019-01-21 15:08:22 +01:00
|
|
|
})
|
|
|
|
export default class Home extends Vue {
|
2019-04-03 17:29:03 +02:00
|
|
|
events: Event[] = [];
|
2019-01-21 15:08:22 +01:00
|
|
|
locations = [];
|
|
|
|
city = { name: null };
|
|
|
|
country = { name: null };
|
2019-03-21 20:23:42 +01:00
|
|
|
loggedPerson: IPerson = new Person();
|
2019-01-21 15:08:22 +01:00
|
|
|
currentUser!: ICurrentUser;
|
2019-04-03 17:29:03 +02:00
|
|
|
config: IConfig = { description: '', name: '', registrationsOpen: false };
|
2019-07-23 18:36:17 +02:00
|
|
|
RouteName = RouteName;
|
2019-01-21 15:08:22 +01:00
|
|
|
|
2019-04-03 17:29:03 +02:00
|
|
|
// get displayed_name() {
|
|
|
|
// return this.loggedPerson && this.loggedPerson.name === null
|
|
|
|
// ? this.loggedPerson.preferredUsername
|
|
|
|
// : this.loggedPerson.name;
|
|
|
|
// }
|
2019-01-21 15:08:22 +01:00
|
|
|
|
2019-03-21 20:23:42 +01:00
|
|
|
isToday(date: string) {
|
|
|
|
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 {
|
|
|
|
return this.calculateDiffDays(date) > nbDays;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: Use me
|
|
|
|
isInLessThanSevenDays(date: string): boolean {
|
|
|
|
return this.isInDays(date, 7);
|
|
|
|
}
|
|
|
|
|
|
|
|
calculateDiffDays(date: string): number {
|
|
|
|
const dateObj = new Date(date);
|
|
|
|
return Math.ceil((dateObj.getTime() - (new Date()).getTime()) / 1000 / 60 / 60 / 24);
|
|
|
|
}
|
|
|
|
|
|
|
|
get goingToEvents(): Map<string, IEvent[]> {
|
|
|
|
const res = this.$data.loggedPerson.goingToEvents.filter((event) => {
|
2019-04-03 17:29:03 +02:00
|
|
|
return event.beginsOn != null && this.isBefore(event.beginsOn, 0);
|
2019-03-21 20:23:42 +01:00
|
|
|
});
|
|
|
|
res.sort(
|
|
|
|
(a: IEvent, b: IEvent) => new Date(a.beginsOn) > new Date(b.beginsOn),
|
|
|
|
);
|
2019-04-03 17:29:03 +02:00
|
|
|
return res.reduce((acc: Map<string, IEvent[]>, event: IEvent) => {
|
2019-03-21 20:23:42 +01:00
|
|
|
const day = (new Date(event.beginsOn)).toDateString();
|
|
|
|
const events: IEvent[] = acc.get(day) || [];
|
|
|
|
events.push(event);
|
|
|
|
acc.set(day, events);
|
|
|
|
return acc;
|
2019-04-03 17:29:03 +02:00
|
|
|
}, new Map());
|
2019-01-21 15:08:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
geoLocalize() {
|
|
|
|
const router = this.$router;
|
2019-02-22 14:55:47 +01:00
|
|
|
const sessionCity = sessionStorage.getItem('City');
|
|
|
|
|
2019-01-21 15:08:22 +01:00
|
|
|
if (sessionCity) {
|
2019-02-22 14:55:47 +01:00
|
|
|
return router.push({ name: 'EventList', params: { location: sessionCity } });
|
2019-01-21 15:08:22 +01:00
|
|
|
}
|
2019-02-22 14:55:47 +01: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 15:08:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
getAddressData(addressData) {
|
2019-02-22 14:55:47 +01:00
|
|
|
const geoHash = ngeohash.encode(
|
2019-01-21 15:08:22 +01:00
|
|
|
addressData.latitude,
|
|
|
|
addressData.longitude,
|
2019-03-22 10:57:14 +01:00
|
|
|
11,
|
2019-01-21 15:08:22 +01:00
|
|
|
);
|
2019-03-22 10:57:14 +01:00
|
|
|
sessionStorage.setItem('City', geoHash);
|
2019-02-22 14:55:47 +01:00
|
|
|
|
|
|
|
this.$router.push({ name: RouteName.EVENT_LIST, params: { location: geoHash } });
|
2019-01-21 15:08:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
viewEvent(event) {
|
2019-02-22 14:55:47 +01:00
|
|
|
this.$router.push({ name: RouteName.EVENT, params: { uuid: event.uuid } });
|
2019-01-21 15:08:22 +01:00
|
|
|
}
|
|
|
|
|
2019-04-03 17:29:03 +02:00
|
|
|
// ipLocation() {
|
|
|
|
// return this.city.name ? this.city.name : this.country.name;
|
|
|
|
// }
|
2019-01-21 15:08:22 +01:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
|
|
|
<style scoped>
|
|
|
|
.search-autocomplete {
|
|
|
|
border: 1px solid #dbdbdb;
|
|
|
|
color: rgba(0, 0, 0, 0.87);
|
|
|
|
}
|
|
|
|
|
|
|
|
.events-nearby {
|
2019-03-21 20:23:42 +01:00
|
|
|
margin: 25px auto;
|
2019-01-21 15:08:22 +01:00
|
|
|
}
|
|
|
|
</style>
|