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>
|
2020-08-27 11:53:24 +02:00
|
|
|
<section v-if="tag">
|
2020-08-10 18:54:25 +02:00
|
|
|
<i18n path="Events tagged with {tag}">
|
2020-08-27 11:53:24 +02:00
|
|
|
<b-tag slot="tag" type="is-light">{{ $t("#{tag}", { tag }) }}</b-tag>
|
2020-08-10 18:54:25 +02:00
|
|
|
</i18n>
|
|
|
|
</section>
|
|
|
|
<section class="hero is-light" v-else>
|
2020-08-05 11:42:23 +02:00
|
|
|
<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"
|
|
|
|
>
|
2020-08-27 15:41:48 +02:00
|
|
|
{{ radiusString(radiusOption) }}
|
|
|
|
</option>
|
2020-08-05 11:42:23 +02:00
|
|
|
</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-27 15:41:48 +02:00
|
|
|
<option v-for="(option, index) in options" :key="index" :value="option">
|
|
|
|
{{ option.label }}
|
|
|
|
</option>
|
2020-08-05 11:42:23 +02:00
|
|
|
</b-select>
|
|
|
|
</b-field>
|
|
|
|
</b-field>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</section>
|
2020-08-27 11:53:24 +02:00
|
|
|
<section class="events-featured" v-if="!tag && searchEvents.initial">
|
2020-08-05 11:42:23 +02:00
|
|
|
<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>
|
2020-09-22 11:45:54 +02:00
|
|
|
<div v-if="searchEvents.total > 0">
|
|
|
|
<div class="columns is-multiline">
|
|
|
|
<div
|
|
|
|
class="column is-one-quarter-desktop"
|
|
|
|
v-for="event in searchEvents.elements"
|
|
|
|
:key="event.uuid"
|
|
|
|
>
|
|
|
|
<EventCard :event="event" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="pagination">
|
|
|
|
<b-pagination
|
|
|
|
:total="searchEvents.total"
|
|
|
|
v-model="eventPage"
|
|
|
|
:per-page="EVENT_PAGE_LIMIT"
|
|
|
|
:aria-next-label="$t('Next page')"
|
|
|
|
:aria-previous-label="$t('Previous page')"
|
|
|
|
:aria-page-label="$t('Page')"
|
|
|
|
:aria-current-label="$t('Current page')"
|
|
|
|
>
|
|
|
|
</b-pagination>
|
2020-02-18 08:57:00 +01:00
|
|
|
</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>
|
2020-09-22 11:45:54 +02:00
|
|
|
<div v-if="searchGroups.total > 0">
|
|
|
|
<div 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>
|
|
|
|
<div class="pagination">
|
|
|
|
<b-pagination
|
|
|
|
:total="searchGroups.total"
|
|
|
|
v-model="groupPage"
|
|
|
|
:per-page="GROUP_PAGE_LIMIT"
|
|
|
|
:aria-next-label="$t('Next page')"
|
|
|
|
:aria-previous-label="$t('Previous page')"
|
|
|
|
:aria-page-label="$t('Page')"
|
|
|
|
:aria-current-label="$t('Current page')"
|
|
|
|
>
|
|
|
|
</b-pagination>
|
2020-08-05 14:39:17 +02:00
|
|
|
</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";
|
2020-07-31 17:52:26 +02:00
|
|
|
import ngeohash from "ngeohash";
|
2020-08-05 11:42:23 +02:00
|
|
|
import {
|
|
|
|
endOfToday,
|
|
|
|
addDays,
|
|
|
|
startOfDay,
|
|
|
|
endOfDay,
|
|
|
|
endOfWeek,
|
|
|
|
addWeeks,
|
|
|
|
startOfWeek,
|
|
|
|
endOfMonth,
|
|
|
|
addMonths,
|
|
|
|
startOfMonth,
|
|
|
|
eachWeekendOfInterval,
|
|
|
|
} from "date-fns";
|
2020-08-31 12:40:30 +02:00
|
|
|
import EventCard from "../components/Event/EventCard.vue";
|
|
|
|
import { FETCH_EVENTS } from "../graphql/event";
|
|
|
|
import { IEvent } from "../types/event.model";
|
|
|
|
import RouteName from "../router/name";
|
|
|
|
import { IAddress, Address } from "../types/address.model";
|
|
|
|
import AddressAutoComplete from "../components/Event/AddressAutoComplete.vue";
|
|
|
|
import { SEARCH_EVENTS, SEARCH_GROUPS } from "../graphql/search";
|
|
|
|
import { Paginate } from "../types/paginate";
|
2020-09-22 11:45:54 +02:00
|
|
|
import { SearchTabs } from "../types/search.model";
|
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
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2020-09-22 11:45:54 +02:00
|
|
|
const EVENT_PAGE_LIMIT = 1;
|
|
|
|
|
|
|
|
const GROUP_PAGE_LIMIT = 10;
|
|
|
|
|
2019-04-03 17:29:03 +02:00
|
|
|
@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,
|
2020-08-27 11:53:24 +02:00
|
|
|
fetchPolicy: "cache-and-network",
|
2019-04-24 19:01:39 +02:00
|
|
|
variables() {
|
|
|
|
return {
|
2020-07-31 17:52:26 +02:00
|
|
|
term: this.search,
|
2020-08-27 11:53:24 +02:00
|
|
|
tags: this.tag,
|
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,
|
2020-09-22 11:45:54 +02:00
|
|
|
page: this.eventPage,
|
|
|
|
limit: EVENT_PAGE_LIMIT,
|
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-27 11:53:24 +02:00
|
|
|
return !this.search && !this.tag && !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,
|
2020-08-27 11:53:24 +02:00
|
|
|
fetchPolicy: "cache-and-network",
|
2020-08-05 14:39:17 +02:00
|
|
|
variables() {
|
|
|
|
return {
|
2020-08-05 16:44:08 +02:00
|
|
|
term: this.search,
|
|
|
|
location: this.geohash,
|
|
|
|
radius: this.radius,
|
2020-09-22 11:45:54 +02:00
|
|
|
page: this.groupPage,
|
|
|
|
limit: GROUP_PAGE_LIMIT,
|
2020-08-05 14:39:17 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
skip() {
|
2020-08-05 16:44:08 +02:00
|
|
|
return !this.search && !this.geohash;
|
2020-08-05 14:39:17 +02:00
|
|
|
},
|
|
|
|
},
|
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-10 18:54:25 +02:00
|
|
|
@Prop({ type: String, required: false }) tag!: string;
|
2020-08-31 12:40:30 +02:00
|
|
|
|
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-31 12:40:30 +02:00
|
|
|
|
2020-08-05 14:39:17 +02:00
|
|
|
searchGroups: Paginate<IGroup> = { total: 0, elements: [] };
|
2020-08-05 11:42:23 +02:00
|
|
|
|
2020-09-22 11:45:54 +02:00
|
|
|
eventPage = 1;
|
|
|
|
|
|
|
|
groupPage = 1;
|
|
|
|
|
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-09-22 11:45:54 +02:00
|
|
|
EVENT_PAGE_LIMIT = EVENT_PAGE_LIMIT;
|
|
|
|
|
|
|
|
GROUP_PAGE_LIMIT = GROUP_PAGE_LIMIT;
|
|
|
|
|
|
|
|
radiusString = (radius: number | null): string => {
|
2020-08-05 11:42:23 +02:00
|
|
|
if (radius) {
|
2020-09-22 11:45:54 +02:00
|
|
|
return this.$tc("{nb} km", radius, { nb: radius }) as string;
|
2019-04-03 17:29:03 +02:00
|
|
|
}
|
2020-09-22 11:45:54 +02:00
|
|
|
return this.$t("any distance") as string;
|
2020-08-05 11:42:23 +02:00
|
|
|
};
|
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-31 12:40:30 +02:00
|
|
|
radius = 50;
|
2020-08-05 11:42:23 +02:00
|
|
|
|
2020-09-22 11:45:54 +02:00
|
|
|
submit(): void {
|
2020-08-05 11:42:23 +02:00
|
|
|
this.$apollo.queries.searchEvents.refetch();
|
2019-04-03 17:29:03 +02:00
|
|
|
}
|
|
|
|
|
2020-08-05 14:39:17 +02:00
|
|
|
@Watch("search")
|
2020-09-22 11:45:54 +02:00
|
|
|
updateSearchTerm(): void {
|
2020-08-05 14:39:17 +02:00
|
|
|
this.$router.push({
|
|
|
|
name: RouteName.SEARCH,
|
2020-08-31 12:40:30 +02:00
|
|
|
query: { ...this.$route.query, term: this.search },
|
2020-08-05 14:39:17 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Watch("activeTab")
|
2020-09-22 11:45:54 +02:00
|
|
|
updateActiveTab(): void {
|
2020-08-05 14:39:17 +02:00
|
|
|
const searchType = this.activeTab === tabsName.events ? "events" : "groups";
|
|
|
|
this.$router.push({
|
|
|
|
name: RouteName.SEARCH,
|
2020-08-31 12:40:30 +02:00
|
|
|
query: { ...this.$route.query, searchType },
|
2020-08-05 14:39:17 +02:00
|
|
|
});
|
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
|
|
|
}
|
|
|
|
|
2020-09-22 11:45:54 +02:00
|
|
|
get geohash(): string | undefined {
|
2020-07-31 17:52:26 +02:00
|
|
|
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>
|