2019-04-03 15:29:03 +00:00
|
|
|
<template>
|
2020-08-05 09:42:23 +00:00
|
|
|
<div class="section container">
|
|
|
|
<h1 class="title">{{ $t("Explore") }}</h1>
|
|
|
|
<section class="hero is-light">
|
|
|
|
<div class="hero-body">
|
|
|
|
<form @submit.prevent="submit()">
|
|
|
|
<b-field :label="$t('Key words')" label-for="search" expanded>
|
|
|
|
<b-input
|
|
|
|
icon="magnify"
|
|
|
|
type="search"
|
|
|
|
id="search"
|
|
|
|
size="is-large"
|
|
|
|
expanded
|
|
|
|
v-model="search"
|
|
|
|
:placeholder="$t('For instance: London, Taekwondo, Architecture…')"
|
|
|
|
/>
|
|
|
|
</b-field>
|
|
|
|
<b-field grouped group-multiline position="is-right" expanded>
|
|
|
|
<b-field :label="$t('Location')" label-for="location">
|
|
|
|
<address-auto-complete
|
|
|
|
v-model="location"
|
|
|
|
id="location"
|
|
|
|
:placeholder="$t('For instance: London')"
|
|
|
|
/>
|
|
|
|
</b-field>
|
|
|
|
<b-field :label="$t('Radius')" label-for="radius">
|
|
|
|
<b-select v-model="radius" id="radius">
|
|
|
|
<option
|
|
|
|
v-for="(radiusOption, index) in radiusOptions"
|
|
|
|
:key="index"
|
|
|
|
:value="radiusOption"
|
|
|
|
>{{ radiusString(radiusOption) }}</option
|
|
|
|
>
|
|
|
|
</b-select>
|
|
|
|
</b-field>
|
|
|
|
<b-field :label="$t('Date')" label-for="date">
|
|
|
|
<b-select v-model="when" id="date">
|
|
|
|
<option v-for="(option, index) in options" :key="index" :value="option">{{
|
|
|
|
option.label
|
|
|
|
}}</option>
|
|
|
|
</b-select>
|
|
|
|
</b-field>
|
|
|
|
</b-field>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
<section class="events-featured" v-if="searchEvents.initial">
|
|
|
|
<b-loading :active.sync="$apollo.loading"></b-loading>
|
|
|
|
<h2 class="title">{{ $t("Featured events") }}</h2>
|
|
|
|
<div v-if="events.length > 0" class="columns is-multiline">
|
|
|
|
<div class="column is-one-third-desktop" v-for="event in events" :key="event.uuid">
|
|
|
|
<EventCard :event="event" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<b-message v-else-if="events.length === 0 && $apollo.loading === false" type="is-danger">{{
|
|
|
|
$t("No events found")
|
|
|
|
}}</b-message>
|
|
|
|
</section>
|
|
|
|
<b-tabs v-else v-model="activeTab" type="is-boxed" class="searchTabs">
|
2020-02-18 07:57:00 +00:00
|
|
|
<b-tab-item>
|
|
|
|
<template slot="header">
|
|
|
|
<b-icon icon="calendar"></b-icon>
|
|
|
|
<span>
|
|
|
|
{{ $t("Events") }}
|
|
|
|
<b-tag rounded>{{ searchEvents.total }}</b-tag>
|
|
|
|
</span>
|
|
|
|
</template>
|
|
|
|
<div v-if="searchEvents.total > 0" class="columns is-multiline">
|
|
|
|
<div
|
2020-07-06 16:36:51 +00:00
|
|
|
class="column is-one-quarter-desktop"
|
2020-02-18 07:57:00 +00:00
|
|
|
v-for="event in searchEvents.elements"
|
|
|
|
:key="event.uuid"
|
|
|
|
>
|
|
|
|
<EventCard :event="event" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<b-message v-else-if="$apollo.loading === false" type="is-danger">{{
|
|
|
|
$t("No events found")
|
|
|
|
}}</b-message>
|
|
|
|
</b-tab-item>
|
|
|
|
</b-tabs>
|
2020-08-05 09:42:23 +00:00
|
|
|
</div>
|
2019-04-03 15:29:03 +00:00
|
|
|
</template>
|
2020-08-05 09:42:23 +00:00
|
|
|
|
2019-04-03 15:29:03 +00:00
|
|
|
<script lang="ts">
|
2020-02-18 07:57:00 +00:00
|
|
|
import { Component, Prop, Vue, Watch } from "vue-property-decorator";
|
|
|
|
import EventCard from "../components/Event/EventCard.vue";
|
2020-08-05 09:42:23 +00:00
|
|
|
import { FETCH_EVENTS } from "../graphql/event";
|
|
|
|
import { IEvent } from "../types/event.model";
|
|
|
|
import RouteName from "../router/name";
|
2020-07-31 15:52:26 +00:00
|
|
|
import { IAddress, Address } from "../types/address.model";
|
2020-02-18 07:57:00 +00:00
|
|
|
import { SearchEvent, SearchGroup } from "../types/search.model";
|
2020-08-05 09:42:23 +00:00
|
|
|
import AddressAutoComplete from "../components/Event/AddressAutoComplete.vue";
|
2020-07-31 15:52:26 +00:00
|
|
|
import ngeohash from "ngeohash";
|
2020-08-05 09:42:23 +00:00
|
|
|
import { SEARCH_EVENTS, SEARCH_GROUPS } from "../graphql/search";
|
|
|
|
import { Paginate } from "../types/paginate";
|
|
|
|
import {
|
|
|
|
endOfToday,
|
|
|
|
addDays,
|
|
|
|
startOfDay,
|
|
|
|
endOfDay,
|
|
|
|
endOfWeek,
|
|
|
|
addWeeks,
|
|
|
|
startOfWeek,
|
|
|
|
endOfMonth,
|
|
|
|
addMonths,
|
|
|
|
startOfMonth,
|
|
|
|
eachWeekendOfInterval,
|
|
|
|
} from "date-fns";
|
|
|
|
|
|
|
|
interface ISearchTimeOption {
|
|
|
|
label: string;
|
|
|
|
start?: Date;
|
|
|
|
end?: Date | null;
|
|
|
|
}
|
2019-04-03 15:29:03 +00:00
|
|
|
|
|
|
|
enum SearchTabs {
|
2020-02-18 07:57:00 +00:00
|
|
|
EVENTS = 0,
|
|
|
|
GROUPS = 1,
|
2019-04-03 15:29:03 +00:00
|
|
|
}
|
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
const tabsName: { events: number; groups: number } = {
|
2019-04-03 15:29:03 +00:00
|
|
|
events: SearchTabs.EVENTS,
|
|
|
|
groups: SearchTabs.GROUPS,
|
|
|
|
};
|
|
|
|
|
|
|
|
@Component({
|
2020-08-05 09:42:23 +00:00
|
|
|
components: {
|
|
|
|
EventCard,
|
|
|
|
AddressAutoComplete,
|
|
|
|
},
|
2019-04-03 15:29:03 +00:00
|
|
|
apollo: {
|
2020-08-05 09:42:23 +00:00
|
|
|
events: FETCH_EVENTS,
|
2019-04-24 17:01:39 +00:00
|
|
|
searchEvents: {
|
|
|
|
query: SEARCH_EVENTS,
|
|
|
|
variables() {
|
|
|
|
return {
|
2020-07-31 15:52:26 +00:00
|
|
|
term: this.search,
|
2020-08-03 15:34:50 +00:00
|
|
|
tags: this.actualTag,
|
2020-07-31 15:52:26 +00:00
|
|
|
location: this.geohash,
|
2020-08-05 09:42:23 +00:00
|
|
|
beginsOn: this.start,
|
|
|
|
endsOn: this.end,
|
|
|
|
radius: this.radius,
|
2019-04-24 17:01:39 +00:00
|
|
|
};
|
|
|
|
},
|
2020-08-05 09:42:23 +00:00
|
|
|
debounce: 300,
|
2019-04-24 17:01:39 +00:00
|
|
|
skip() {
|
2020-08-05 09:42:23 +00:00
|
|
|
return !this.search && !this.actualTag && !this.geohash && this.end === null;
|
2019-04-03 15:29:03 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-08-05 09:42:23 +00:00
|
|
|
metaInfo() {
|
|
|
|
return {
|
|
|
|
// if no subcomponents specify a metaInfo.title, this title will be used
|
|
|
|
title: this.$t("Explore events") as string,
|
|
|
|
// all titles will be injected into this template
|
|
|
|
titleTemplate: "%s | Mobilizon",
|
|
|
|
};
|
2019-04-03 15:29:03 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
export default class Search extends Vue {
|
2020-08-05 09:42:23 +00:00
|
|
|
@Prop({ type: String, required: false, default: "" }) searchTerm!: string;
|
2020-02-18 07:57:00 +00:00
|
|
|
@Prop({ type: String, required: false, default: "events" }) searchType!: "events" | "groups";
|
2019-04-03 15:29:03 +00:00
|
|
|
|
2020-08-05 09:42:23 +00:00
|
|
|
events: IEvent[] = [];
|
2020-02-18 07:57:00 +00:00
|
|
|
|
2020-08-05 09:42:23 +00:00
|
|
|
searchEvents: Paginate<IEvent> & { initial: boolean } = { total: 0, elements: [], initial: true };
|
|
|
|
|
|
|
|
search = this.searchTerm;
|
2020-02-18 07:57:00 +00:00
|
|
|
|
2019-04-03 15:29:03 +00:00
|
|
|
activeTab: SearchTabs = tabsName[this.searchType];
|
|
|
|
|
2020-07-31 15:52:26 +00:00
|
|
|
location: IAddress = new Address();
|
|
|
|
|
2020-08-05 09:42:23 +00:00
|
|
|
options: ISearchTimeOption[] = [
|
|
|
|
{
|
|
|
|
label: this.$t("Today") as string,
|
|
|
|
start: new Date(),
|
|
|
|
end: endOfToday(),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: this.$t("Tomorrow") as string,
|
|
|
|
start: startOfDay(addDays(new Date(), 1)),
|
|
|
|
end: endOfDay(addDays(new Date(), 1)),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: this.$t("This weekend") as string,
|
|
|
|
start: this.weekend.start,
|
|
|
|
end: this.weekend.end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: this.$t("This week") as string,
|
|
|
|
start: new Date(),
|
|
|
|
end: endOfWeek(new Date(), { locale: this.$dateFnsLocale }),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: this.$t("Next week") as string,
|
|
|
|
start: startOfWeek(addWeeks(new Date(), 1), { locale: this.$dateFnsLocale }),
|
|
|
|
end: endOfWeek(addWeeks(new Date(), 1), { locale: this.$dateFnsLocale }),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: this.$t("This month") as string,
|
|
|
|
start: new Date(),
|
|
|
|
end: endOfMonth(new Date()),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: this.$t("Next month") as string,
|
|
|
|
start: startOfMonth(addMonths(new Date(), 1)),
|
|
|
|
end: endOfMonth(addMonths(new Date(), 1)),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: this.$t("Any day") as string,
|
|
|
|
start: undefined,
|
|
|
|
end: undefined,
|
|
|
|
},
|
|
|
|
];
|
2020-02-07 16:04:03 +00:00
|
|
|
|
2020-08-05 09:42:23 +00:00
|
|
|
when: ISearchTimeOption = {
|
|
|
|
label: this.$t("Any day") as string,
|
|
|
|
start: undefined,
|
|
|
|
end: null,
|
|
|
|
};
|
2019-04-03 15:29:03 +00:00
|
|
|
|
2020-08-05 09:42:23 +00:00
|
|
|
radiusString = (radius: number | null) => {
|
|
|
|
if (radius) {
|
|
|
|
return this.$tc("{nb} km", radius, { nb: radius });
|
2019-04-03 15:29:03 +00:00
|
|
|
}
|
2020-08-05 09:42:23 +00:00
|
|
|
return this.$t("any distance");
|
|
|
|
};
|
2019-04-03 15:29:03 +00:00
|
|
|
|
2020-08-05 09:42:23 +00:00
|
|
|
radiusOptions: (number | null)[] = [1, 5, 10, 25, 50, 100, 150, null];
|
2019-04-03 15:29:03 +00:00
|
|
|
|
2020-08-05 09:42:23 +00:00
|
|
|
radius: number | undefined = undefined;
|
|
|
|
|
|
|
|
submit() {
|
|
|
|
this.$apollo.queries.searchEvents.refetch();
|
2019-04-03 15:29:03 +00:00
|
|
|
}
|
|
|
|
|
2020-08-05 09:42:23 +00:00
|
|
|
@Watch("searchTerm")
|
|
|
|
updateSearchTerm() {
|
|
|
|
this.search = this.searchTerm;
|
2020-02-07 16:04:03 +00:00
|
|
|
}
|
2020-07-31 15:52:26 +00:00
|
|
|
|
2020-08-05 09:42:23 +00:00
|
|
|
get weekend(): { start: Date; end: Date } {
|
|
|
|
const now = new Date();
|
|
|
|
const endOfWeekDate = endOfWeek(now, { locale: this.$dateFnsLocale });
|
|
|
|
const startOfWeekDate = startOfWeek(now, { locale: this.$dateFnsLocale });
|
|
|
|
const [start, end] = eachWeekendOfInterval({ start: startOfWeekDate, end: endOfWeekDate });
|
|
|
|
return { start: startOfDay(start), end: endOfDay(end) };
|
2020-07-31 15:52:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get geohash() {
|
|
|
|
if (this.location && this.location.geom) {
|
|
|
|
const [lon, lat] = this.location.geom.split(";");
|
|
|
|
return ngeohash.encode(lat, lon, 6);
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
}
|
2020-08-05 09:42:23 +00:00
|
|
|
|
|
|
|
get start(): Date | undefined {
|
|
|
|
return this.when.start;
|
|
|
|
}
|
|
|
|
|
|
|
|
get end(): Date | undefined | null {
|
|
|
|
return this.when.end;
|
|
|
|
}
|
2019-04-03 15:29:03 +00:00
|
|
|
}
|
|
|
|
</script>
|
2020-08-05 09:42:23 +00:00
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
@import "@/variables.scss";
|
|
|
|
|
|
|
|
main > .container {
|
|
|
|
background: $white;
|
|
|
|
|
|
|
|
.hero-body {
|
|
|
|
padding: 1rem 1.5rem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
h1.title {
|
|
|
|
margin-top: 1.5rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
h3.title {
|
|
|
|
margin-bottom: 1.5rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
.events-featured {
|
|
|
|
margin: 25px auto;
|
|
|
|
|
|
|
|
.columns {
|
|
|
|
margin: 1rem auto 3rem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
form {
|
|
|
|
/deep/ .field label.label {
|
|
|
|
margin-bottom: 0;
|
|
|
|
}
|
2020-02-18 07:57:00 +00:00
|
|
|
}
|
2019-04-03 15:29:03 +00:00
|
|
|
</style>
|