2022-07-12 10:55:28 +02:00
|
|
|
<template>
|
|
|
|
<close-content
|
2022-08-22 12:12:09 +02:00
|
|
|
class="container mx-auto px-2"
|
2022-10-05 17:42:12 +02:00
|
|
|
v-show="loading || (events && events.total > 0)"
|
2022-07-12 10:55:28 +02:00
|
|
|
:suggestGeoloc="suggestGeoloc"
|
|
|
|
v-on="attrs"
|
2022-08-22 12:12:09 +02:00
|
|
|
@doGeoLoc="emit('doGeoLoc')"
|
2022-10-05 17:42:12 +02:00
|
|
|
:doingGeoloc="doingGeoloc"
|
2022-07-12 10:55:28 +02:00
|
|
|
>
|
|
|
|
<template #title>
|
2022-08-19 15:07:58 +02:00
|
|
|
<template v-if="userLocationName">
|
|
|
|
{{ t("Events nearby {position}", { position: userLocationName }) }}
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
{{ t("Events close to you") }}
|
|
|
|
</template>
|
2022-07-12 10:55:28 +02:00
|
|
|
</template>
|
|
|
|
<template #content>
|
|
|
|
<skeleton-event-result
|
|
|
|
v-for="i in 6"
|
|
|
|
class="scroll-ml-6 snap-center shrink-0 w-[18rem] my-4"
|
|
|
|
:key="i"
|
2022-10-05 17:42:12 +02:00
|
|
|
v-show="loading"
|
2022-07-12 10:55:28 +02:00
|
|
|
/>
|
|
|
|
<event-card
|
|
|
|
v-for="event in events.elements"
|
|
|
|
:event="event"
|
|
|
|
:key="event.uuid"
|
|
|
|
/>
|
|
|
|
<more-content
|
2022-08-22 12:12:09 +02:00
|
|
|
v-if="userLocationName && userLocation?.lat && userLocation?.lon"
|
2022-07-12 10:55:28 +02:00
|
|
|
:to="{
|
2022-08-26 16:08:58 +02:00
|
|
|
name: RouteName.SEARCH,
|
2022-07-12 10:55:28 +02:00
|
|
|
query: {
|
|
|
|
locationName: userLocationName,
|
|
|
|
lat: userLocation.lat?.toString(),
|
|
|
|
lon: userLocation.lon?.toString(),
|
|
|
|
contentType: 'EVENTS',
|
2022-10-05 17:42:12 +02:00
|
|
|
distance: `${distance}_km`,
|
2022-07-12 10:55:28 +02:00
|
|
|
},
|
|
|
|
}"
|
2022-08-22 12:12:09 +02:00
|
|
|
:picture="userLocation?.picture"
|
2022-07-12 10:55:28 +02:00
|
|
|
>
|
|
|
|
{{
|
|
|
|
t("View more events around {position}", {
|
|
|
|
position: userLocationName,
|
|
|
|
})
|
|
|
|
}}
|
|
|
|
</more-content>
|
|
|
|
</template>
|
|
|
|
</close-content>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
import { LocationType } from "../../types/user-location.model";
|
|
|
|
import MoreContent from "./MoreContent.vue";
|
|
|
|
import CloseContent from "./CloseContent.vue";
|
2022-10-11 17:56:22 +02:00
|
|
|
import { computed, onMounted, useAttrs } from "vue";
|
2022-07-12 10:55:28 +02:00
|
|
|
import { SEARCH_EVENTS } from "@/graphql/search";
|
|
|
|
import { IEvent } from "@/types/event.model";
|
2022-10-05 17:42:12 +02:00
|
|
|
import { useLazyQuery } from "@vue/apollo-composable";
|
2022-07-12 10:55:28 +02:00
|
|
|
import EventCard from "../Event/EventCard.vue";
|
|
|
|
import { Paginate } from "@/types/paginate";
|
|
|
|
import SkeletonEventResult from "../Event/SkeletonEventResult.vue";
|
|
|
|
import { useI18n } from "vue-i18n";
|
2022-08-22 12:12:09 +02:00
|
|
|
import { coordsToGeoHash } from "@/utils/location";
|
2022-08-26 16:08:58 +02:00
|
|
|
import { roundToNearestMinute } from "@/utils/datetime";
|
|
|
|
import RouteName from "@/router/name";
|
2022-07-12 10:55:28 +02:00
|
|
|
|
2022-10-05 17:42:12 +02:00
|
|
|
const props = defineProps<{
|
|
|
|
userLocation: LocationType;
|
|
|
|
doingGeoloc?: boolean;
|
|
|
|
}>();
|
2022-08-22 12:12:09 +02:00
|
|
|
const emit = defineEmits(["doGeoLoc"]);
|
2022-07-12 10:55:28 +02:00
|
|
|
|
2022-08-22 12:12:09 +02:00
|
|
|
const EVENT_PAGE_LIMIT = 12;
|
2022-07-12 10:55:28 +02:00
|
|
|
|
|
|
|
const { t } = useI18n({ useScope: "global" });
|
|
|
|
const attrs = useAttrs();
|
|
|
|
|
2022-10-05 17:42:12 +02:00
|
|
|
const userLocation = computed(() => props.userLocation);
|
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const userLocationName = computed(() => {
|
2022-10-05 17:42:12 +02:00
|
|
|
return userLocation.value?.name;
|
2022-07-12 10:55:28 +02:00
|
|
|
});
|
2022-10-05 17:42:12 +02:00
|
|
|
const suggestGeoloc = computed(() => userLocation.value?.isIPLocation);
|
2022-07-12 10:55:28 +02:00
|
|
|
|
2022-08-26 16:08:58 +02:00
|
|
|
const geoHash = computed(() =>
|
|
|
|
coordsToGeoHash(props.userLocation.lat, props.userLocation.lon)
|
|
|
|
);
|
|
|
|
|
2022-10-05 17:42:12 +02:00
|
|
|
const distance = computed<number>(() => (suggestGeoloc.value ? 150 : 25));
|
|
|
|
|
|
|
|
const now = computed(() => roundToNearestMinute(new Date()));
|
|
|
|
|
|
|
|
const searchEnabled = computed(() => geoHash.value != undefined);
|
|
|
|
|
|
|
|
const {
|
|
|
|
result: eventsResult,
|
|
|
|
loading: loadingEvents,
|
|
|
|
load: load,
|
|
|
|
} = useLazyQuery<{
|
2022-07-12 10:55:28 +02:00
|
|
|
searchEvents: Paginate<IEvent>;
|
2022-08-26 16:08:58 +02:00
|
|
|
}>(
|
|
|
|
SEARCH_EVENTS,
|
|
|
|
() => ({
|
|
|
|
location: geoHash.value,
|
2022-10-05 17:42:12 +02:00
|
|
|
beginsOn: now.value,
|
2022-08-26 16:08:58 +02:00
|
|
|
endsOn: undefined,
|
2022-10-05 17:42:12 +02:00
|
|
|
radius: distance.value,
|
2022-08-26 16:08:58 +02:00
|
|
|
eventPage: 1,
|
|
|
|
limit: EVENT_PAGE_LIMIT,
|
|
|
|
type: "IN_PERSON",
|
|
|
|
}),
|
|
|
|
() => ({
|
2022-10-05 17:42:12 +02:00
|
|
|
enabled: searchEnabled.value,
|
|
|
|
fetchPolicy: "cache-first",
|
2022-08-26 16:08:58 +02:00
|
|
|
})
|
|
|
|
);
|
2022-07-12 10:55:28 +02:00
|
|
|
|
|
|
|
const events = computed(
|
|
|
|
() => eventsResult.value?.searchEvents ?? { elements: [], total: 0 }
|
|
|
|
);
|
2022-10-05 17:42:12 +02:00
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
load();
|
|
|
|
});
|
|
|
|
|
|
|
|
const loading = computed(() => props.doingGeoloc || loadingEvents.value);
|
2022-07-12 10:55:28 +02:00
|
|
|
</script>
|