2019-01-21 15:08:22 +01:00
|
|
|
<template>
|
|
|
|
<div>
|
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">
|
|
|
|
<h1 class="title">Find events you like</h1>
|
|
|
|
<h2 class="subtitle">Share them with Mobilizon</h2>
|
|
|
|
<router-link class="button" :to="{ name: 'Register' }">
|
|
|
|
<translate>Register</translate>
|
|
|
|
</router-link>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
<section v-else>
|
|
|
|
<h1>
|
|
|
|
<translate
|
|
|
|
:translate-params="{username: loggedPerson.preferredUsername}"
|
|
|
|
>Welcome back %{username}</translate>
|
|
|
|
</h1>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
|
|
<span class="events-nearby title">Events nearby you</span>
|
|
|
|
<b-loading :active.sync="$apollo.loading"></b-loading>
|
|
|
|
<div v-if="events.length > 0" class="columns is-multiline">
|
|
|
|
<EventCard
|
|
|
|
v-for="event in events"
|
|
|
|
:key="event.uuid"
|
|
|
|
:event="event"
|
|
|
|
class="column is-one-quarter-desktop is-half-mobile"
|
|
|
|
/>
|
|
|
|
</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';
|
|
|
|
import { LOGGED_PERSON } from '@/graphql/actor';
|
|
|
|
import { IPerson } from '@/types/actor.model';
|
|
|
|
import { ICurrentUser } from '@/types/current-user.model';
|
|
|
|
import { CURRENT_USER_CLIENT } from '@/graphql/user';
|
|
|
|
import { RouteName } from '@/router';
|
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-22 10:57:14 +01:00
|
|
|
query: LOGGED_PERSON,
|
2019-01-21 15:08:22 +01:00
|
|
|
},
|
|
|
|
currentUser: {
|
2019-03-22 10:57:14 +01:00
|
|
|
query: CURRENT_USER_CLIENT,
|
|
|
|
},
|
2019-01-21 15:08:22 +01:00
|
|
|
},
|
|
|
|
components: {
|
2019-03-22 10:57:14 +01:00
|
|
|
EventCard,
|
|
|
|
},
|
2019-01-21 15:08:22 +01:00
|
|
|
})
|
|
|
|
export default class Home extends Vue {
|
|
|
|
events = [];
|
|
|
|
locations = [];
|
|
|
|
city = { name: null };
|
|
|
|
country = { name: null };
|
|
|
|
// FIXME: correctly parse local storage
|
|
|
|
loggedPerson!: IPerson;
|
|
|
|
currentUser!: ICurrentUser;
|
|
|
|
|
|
|
|
get displayed_name() {
|
|
|
|
return this.loggedPerson.name === null
|
|
|
|
? this.loggedPerson.preferredUsername
|
|
|
|
: this.loggedPerson.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchLocations() {
|
|
|
|
// FIXME: remove eventFetch
|
|
|
|
// eventFetch('/locations', this.$store)
|
|
|
|
// .then(response => (response.json()))
|
|
|
|
// .then((response) => {
|
|
|
|
// this.locations = response;
|
|
|
|
// });
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
ipLocation() {
|
|
|
|
return this.city.name ? this.city.name : this.country.name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</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 {
|
|
|
|
margin-bottom: 25px;
|
|
|
|
}
|
|
|
|
</style>
|