2019-04-03 17:29:03 +02:00
|
|
|
<template>
|
2020-08-05 11:42:23 +02: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">
|
2020-08-05 14:39:17 +02:00
|
|
|
<b-select v-model="when" id="date" :disabled="activeTab !== 0">
|
2020-08-05 11:42:23 +02:00
|
|
|
<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 08:57:00 +01: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 18:36:51 +02:00
|
|
|
class="column is-one-quarter-desktop"
|
2020-02-18 08:57:00 +01: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>
|
2020-08-05 14:39:17 +02:00
|
|
|
<b-tab-item v-if="config && config.features.groups">
|
|
|
|
<template slot="header">
|
|
|
|
<b-icon icon="account-multiple"></b-icon>
|
|
|
|
<span>
|
|
|
|
{{ $t("Groups") }} <b-tag rounded>{{ searchGroups.total }}</b-tag>
|
|
|
|
</span>
|
|
|
|
</template>
|
|
|
|
<div v-if="searchGroups.total > 0" class="columns is-multiline">
|
|
|
|
<div
|
|
|
|
class="column is-one-quarter-desktop"
|
|
|
|
v-for="group in searchGroups.elements"
|
|
|
|
:key="group.uuid"
|
|
|
|
>
|
|
|
|
<group-card :group="group" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<b-message v-else-if="$apollo.loading === false" type="is-danger">
|
|
|
|
{{ $t("No groups found") }}
|
|
|
|
</b-message>
|
|
|
|
</b-tab-item>
|
2020-02-18 08:57:00 +01:00
|
|
|
</b-tabs>
|
2020-08-05 11:42:23 +02:00
|
|
|
</div>
|
2019-04-03 17:29:03 +02:00
|
|
|
</template>
|
2020-08-05 11:42:23 +02:00
|
|
|
|
2019-04-03 17:29:03 +02:00
|
|
|
<script lang="ts">
|
2020-02-18 08:57:00 +01:00
|
|
|
import { Component, Prop, Vue, Watch } from "vue-property-decorator";
|
|
|
|
import EventCard from "../components/Event/EventCard.vue";
|
2020-08-05 11:42:23 +02:00
|
|
|
import { FETCH_EVENTS } from "../graphql/event";
|
|
|
|
import { IEvent } from "../types/event.model";
|
|
|
|
import RouteName from "../router/name";
|
2020-07-31 17:52:26 +02:00
|
|
|
import { IAddress, Address } from "../types/address.model";
|
2020-02-18 08:57:00 +01:00
|
|
|
import { SearchEvent, SearchGroup } from "../types/search.model";
|
2020-08-05 11:42:23 +02:00
|
|
|
import AddressAutoComplete from "../components/Event/AddressAutoComplete.vue";
|
2020-07-31 17:52:26 +02:00
|
|
|
import ngeohash from "ngeohash";
|
2020-08-05 11:42:23 +02: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";
|
2020-08-05 14:39:17 +02:00
|
|
|
import { IGroup } from "../types/actor";
|
|
|
|
import GroupCard from "../components/Group/GroupCard.vue";
|
|
|
|
import { CONFIG } from "../graphql/config";
|
2020-08-05 11:42:23 +02:00
|
|
|
|
|
|
|
interface ISearchTimeOption {
|
|
|
|
label: string;
|
|
|
|
start?: Date;
|
|
|
|
end?: Date | null;
|
|
|
|
}
|
2019-04-03 17:29:03 +02:00
|
|
|
|
|
|
|
enum SearchTabs {
|
2020-02-18 08:57:00 +01:00
|
|
|
EVENTS = 0,
|
|
|
|
GROUPS = 1,
|
2019-04-03 17:29:03 +02:00
|
|
|
}
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
const tabsName: { events: number; groups: number } = {
|
2019-04-03 17:29:03 +02:00
|
|
|
events: SearchTabs.EVENTS,
|
|
|
|
groups: SearchTabs.GROUPS,
|
|
|
|
};
|
|
|
|
|
|
|
|
@Component({
|
2020-08-05 11:42:23 +02:00
|
|
|
components: {
|
|
|
|
EventCard,
|
|
|
|
AddressAutoComplete,
|
2020-08-05 14:39:17 +02:00
|
|
|
GroupCard,
|
2020-08-05 11:42:23 +02:00
|
|
|
},
|
2019-04-03 17:29:03 +02:00
|
|
|
apollo: {
|
2020-08-05 14:39:17 +02:00
|
|
|
config: CONFIG,
|
2020-08-05 11:42:23 +02:00
|
|
|
events: FETCH_EVENTS,
|
2019-04-24 19:01:39 +02:00
|
|
|
searchEvents: {
|
|
|
|
query: SEARCH_EVENTS,
|
|
|
|
variables() {
|
|
|
|
return {
|
2020-07-31 17:52:26 +02:00
|
|
|
term: this.search,
|
2020-08-03 17:34:50 +02:00
|
|
|
tags: this.actualTag,
|
2020-07-31 17:52:26 +02:00
|
|
|
location: this.geohash,
|
2020-08-05 11:42:23 +02:00
|
|
|
beginsOn: this.start,
|
|
|
|
endsOn: this.end,
|
|
|
|
radius: this.radius,
|
2019-04-24 19:01:39 +02:00
|
|
|
};
|
|
|
|
},
|
2020-08-05 11:42:23 +02:00
|
|
|
debounce: 300,
|
2019-04-24 19:01:39 +02:00
|
|
|
skip() {
|
2020-08-05 11:42:23 +02:00
|
|
|
return !this.search && !this.actualTag && !this.geohash && this.end === null;
|
2019-04-03 17:29:03 +02:00
|
|
|
},
|
|
|
|
},
|
2020-08-05 14:39:17 +02:00
|
|
|
searchGroups: {
|
|
|
|
query: SEARCH_GROUPS,
|
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
searchText: this.search,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
skip() {
|
|
|
|
return this.search == null || this.search == "";
|
|
|
|
},
|
|
|
|
},
|
2019-04-03 17:29:03 +02:00
|
|
|
},
|
2020-08-05 11:42:23 +02: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 17:29:03 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
export default class Search extends Vue {
|
2020-08-05 11:42:23 +02:00
|
|
|
events: IEvent[] = [];
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2020-08-05 11:42:23 +02:00
|
|
|
searchEvents: Paginate<IEvent> & { initial: boolean } = { total: 0, elements: [], initial: true };
|
2020-08-05 14:39:17 +02:00
|
|
|
searchGroups: Paginate<IGroup> = { total: 0, elements: [] };
|
2020-08-05 11:42:23 +02:00
|
|
|
|
2020-08-05 14:39:17 +02:00
|
|
|
search: string = (this.$route.query.term as string) || "";
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2020-08-05 14:39:17 +02:00
|
|
|
activeTab: SearchTabs = tabsName[this.$route.query.searchType as "events" | "groups"] || 0;
|
2019-04-03 17:29:03 +02:00
|
|
|
|
2020-07-31 17:52:26 +02:00
|
|
|
location: IAddress = new Address();
|
|
|
|
|
2020-08-05 11:42:23 +02: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 17:04:03 +01:00
|
|
|
|
2020-08-05 11:42:23 +02:00
|
|
|
when: ISearchTimeOption = {
|
|
|
|
label: this.$t("Any day") as string,
|
|
|
|
start: undefined,
|
|
|
|
end: null,
|
|
|
|
};
|
2019-04-03 17:29:03 +02:00
|
|
|
|
2020-08-05 11:42:23 +02:00
|
|
|
radiusString = (radius: number | null) => {
|
|
|
|
if (radius) {
|
|
|
|
return this.$tc("{nb} km", radius, { nb: radius });
|
2019-04-03 17:29:03 +02:00
|
|
|
}
|
2020-08-05 11:42:23 +02:00
|
|
|
return this.$t("any distance");
|
|
|
|
};
|
2019-04-03 17:29:03 +02:00
|
|
|
|
2020-08-05 11:42:23 +02:00
|
|
|
radiusOptions: (number | null)[] = [1, 5, 10, 25, 50, 100, 150, null];
|
2019-04-03 17:29:03 +02:00
|
|
|
|
2020-08-05 14:39:17 +02:00
|
|
|
radius: number | null = null;
|
2020-08-05 11:42:23 +02:00
|
|
|
|
|
|
|
submit() {
|
|
|
|
this.$apollo.queries.searchEvents.refetch();
|
2019-04-03 17:29:03 +02:00
|
|
|
}
|
|
|
|
|
2020-08-05 14:39:17 +02:00
|
|
|
@Watch("search")
|
2020-08-05 11:42:23 +02:00
|
|
|
updateSearchTerm() {
|
2020-08-05 14:39:17 +02:00
|
|
|
this.$router.push({
|
|
|
|
name: RouteName.SEARCH,
|
|
|
|
query: Object.assign({}, this.$route.query, { term: this.search }),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Watch("activeTab")
|
|
|
|
updateActiveTab() {
|
|
|
|
const searchType = this.activeTab === tabsName.events ? "events" : "groups";
|
|
|
|
this.$router.push({
|
|
|
|
name: RouteName.SEARCH,
|
|
|
|
query: Object.assign({}, this.$route.query, { searchType }),
|
|
|
|
});
|
2020-02-07 17:04:03 +01:00
|
|
|
}
|
2020-07-31 17:52:26 +02:00
|
|
|
|
2020-08-05 11:42:23 +02: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 17:52:26 +02: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 11:42:23 +02:00
|
|
|
|
|
|
|
get start(): Date | undefined {
|
|
|
|
return this.when.start;
|
|
|
|
}
|
|
|
|
|
|
|
|
get end(): Date | undefined | null {
|
|
|
|
return this.when.end;
|
|
|
|
}
|
2019-04-03 17:29:03 +02:00
|
|
|
}
|
|
|
|
</script>
|
2020-08-05 11:42:23 +02: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 08:57:00 +01:00
|
|
|
}
|
2019-04-03 17:29:03 +02:00
|
|
|
</style>
|