2022-07-12 10:55:28 +02:00
|
|
|
<template>
|
2022-08-22 12:12:09 +02:00
|
|
|
<!-- <o-loading v-model:active="$apollo.loading" /> -->
|
|
|
|
<!-- Nice looking SVGs -->
|
|
|
|
<section class="mt-5 sm:mt-24">
|
|
|
|
<div class="-z-10 overflow-hidden">
|
|
|
|
<img
|
|
|
|
alt=""
|
|
|
|
src="/img/shape-1.svg"
|
|
|
|
class="-z-10 absolute left-[2%] top-36"
|
|
|
|
width="300"
|
|
|
|
/>
|
|
|
|
<img
|
|
|
|
alt=""
|
|
|
|
src="/img/shape-2.svg"
|
|
|
|
class="-z-10 absolute left-[50%] top-[5%] -translate-x-2/4 opacity-60"
|
|
|
|
width="800"
|
|
|
|
/>
|
|
|
|
<img
|
|
|
|
alt=""
|
|
|
|
src="/img/shape-3.svg"
|
|
|
|
class="-z-10 absolute top-0 right-36"
|
|
|
|
width="200"
|
|
|
|
/>
|
2022-07-12 10:55:28 +02:00
|
|
|
</div>
|
2022-08-22 12:12:09 +02:00
|
|
|
</section>
|
|
|
|
<!-- Unlogged introduction -->
|
|
|
|
<unlogged-introduction :config="config" v-if="config && !isLoggedIn" />
|
|
|
|
<!-- Search fields -->
|
|
|
|
<search-fields v-model:search="search" v-model:location="location" />
|
|
|
|
<!-- Categories preview -->
|
|
|
|
<categories-preview />
|
|
|
|
<!-- Welcome back -->
|
2022-09-01 10:00:17 +02:00
|
|
|
<section
|
|
|
|
class="container mx-auto"
|
|
|
|
v-if="currentActor?.id && (welcomeBack || newRegisteredUser)"
|
|
|
|
>
|
2022-08-22 12:12:09 +02:00
|
|
|
<o-notification variant="info" v-if="welcomeBack">{{
|
2022-11-07 09:02:20 +01:00
|
|
|
t("Welcome back {username}!", {
|
2022-08-22 12:12:09 +02:00
|
|
|
username: displayName(currentActor),
|
|
|
|
})
|
|
|
|
}}</o-notification>
|
|
|
|
<o-notification variant="info" v-if="newRegisteredUser">{{
|
2022-11-07 09:02:20 +01:00
|
|
|
t("Welcome to Mobilizon, {username}!", {
|
2022-08-22 12:12:09 +02:00
|
|
|
username: displayName(currentActor),
|
|
|
|
})
|
|
|
|
}}</o-notification>
|
|
|
|
</section>
|
|
|
|
<!-- Your upcoming events -->
|
|
|
|
<section v-if="canShowMyUpcomingEvents" class="container mx-auto">
|
|
|
|
<h2 class="dark:text-white font-bold">
|
2022-11-07 09:02:20 +01:00
|
|
|
{{ t("Your upcoming events") }}
|
2022-08-22 12:12:09 +02:00
|
|
|
</h2>
|
2022-07-12 10:55:28 +02:00
|
|
|
<div
|
2022-08-22 12:12:09 +02:00
|
|
|
v-for="row of goingToEvents"
|
|
|
|
class="text-slate-700 dark:text-slate-300"
|
|
|
|
:key="row[0]"
|
2022-07-12 10:55:28 +02:00
|
|
|
>
|
2022-08-22 12:12:09 +02:00
|
|
|
<p class="date-component-container" v-if="isInLessThanSevenDays(row[0])">
|
|
|
|
<span v-if="isToday(row[0])">{{
|
2022-11-07 09:02:20 +01:00
|
|
|
t(
|
2022-08-22 12:12:09 +02:00
|
|
|
"You have one event today.",
|
|
|
|
{
|
|
|
|
count: row[1].size,
|
|
|
|
},
|
|
|
|
row[1].size
|
|
|
|
)
|
|
|
|
}}</span>
|
|
|
|
<span v-else-if="isTomorrow(row[0])">{{
|
2022-11-07 09:02:20 +01:00
|
|
|
t(
|
2022-08-22 12:12:09 +02:00
|
|
|
"You have one event tomorrow.",
|
|
|
|
{
|
|
|
|
count: row[1].size,
|
|
|
|
},
|
|
|
|
row[1].size
|
|
|
|
)
|
|
|
|
}}</span>
|
|
|
|
<span v-else-if="isInLessThanSevenDays(row[0])">
|
|
|
|
{{
|
2022-11-07 09:02:20 +01:00
|
|
|
t(
|
2022-08-22 12:12:09 +02:00
|
|
|
"You have one event in {days} days.",
|
|
|
|
{
|
|
|
|
count: row[1].size,
|
|
|
|
days: calculateDiffDays(row[0]),
|
2022-07-12 10:55:28 +02:00
|
|
|
},
|
2022-08-22 12:12:09 +02:00
|
|
|
row[1].size
|
|
|
|
)
|
|
|
|
}}
|
2022-07-12 10:55:28 +02:00
|
|
|
</span>
|
2022-08-22 12:12:09 +02:00
|
|
|
</p>
|
|
|
|
<div>
|
|
|
|
<event-participation-card
|
|
|
|
v-for="participation in thisWeek(row)"
|
|
|
|
:key="participation[1].id"
|
|
|
|
:participation="participation[1]"
|
|
|
|
/>
|
|
|
|
</div>
|
2022-07-12 10:55:28 +02:00
|
|
|
</div>
|
2022-08-22 12:12:09 +02:00
|
|
|
<span
|
|
|
|
class="block mt-2 text-right underline text-slate-700 dark:text-slate-300"
|
|
|
|
>
|
|
|
|
<router-link
|
|
|
|
:to="{ name: RouteName.MY_EVENTS }"
|
|
|
|
class="hover:text-slate-800 hover:dark:text-slate-400"
|
2022-11-07 09:02:20 +01:00
|
|
|
>{{ t("View everything") }} >></router-link
|
2022-08-22 12:12:09 +02:00
|
|
|
>
|
|
|
|
</span>
|
|
|
|
</section>
|
|
|
|
<!-- Events from your followed groups -->
|
2022-11-07 09:02:20 +01:00
|
|
|
<section
|
|
|
|
class="relative pt-10 px-2 container mx-auto px-2"
|
|
|
|
v-if="canShowFollowedGroupEvents"
|
|
|
|
>
|
|
|
|
<h2
|
|
|
|
class="text-xl font-bold tracking-tight text-gray-900 dark:text-gray-100 mt-0"
|
|
|
|
>
|
|
|
|
{{ t("Upcoming events from your groups") }}
|
2022-08-22 12:12:09 +02:00
|
|
|
</h2>
|
2022-11-07 09:02:20 +01:00
|
|
|
<p>{{ t("That you follow or of which you are a member") }}</p>
|
2022-08-22 12:12:09 +02:00
|
|
|
<multi-card :events="filteredFollowedGroupsEvents" />
|
|
|
|
<span
|
|
|
|
class="block mt-2 text-right underline text-slate-700 dark:text-slate-300"
|
|
|
|
>
|
|
|
|
<router-link
|
|
|
|
class="hover:text-slate-800 hover:dark:text-slate-400"
|
|
|
|
:to="{
|
|
|
|
name: RouteName.MY_EVENTS,
|
|
|
|
query: {
|
|
|
|
showUpcoming: 'true',
|
|
|
|
showDrafts: 'false',
|
|
|
|
showAttending: 'false',
|
|
|
|
showMyGroups: 'true',
|
|
|
|
},
|
|
|
|
}"
|
2022-11-07 09:02:20 +01:00
|
|
|
>{{ t("View everything") }} >></router-link
|
2022-08-22 12:12:09 +02:00
|
|
|
>
|
|
|
|
</span>
|
|
|
|
</section>
|
|
|
|
<!-- Recent events -->
|
2022-10-05 17:42:12 +02:00
|
|
|
<CloseEvents
|
|
|
|
@doGeoLoc="performGeoLocation()"
|
|
|
|
:userLocation="userLocation"
|
|
|
|
:doingGeoloc="doingGeoloc"
|
|
|
|
/>
|
2022-08-22 12:12:09 +02:00
|
|
|
<CloseGroups :userLocation="userLocation" @doGeoLoc="performGeoLocation()" />
|
2022-08-26 16:08:58 +02:00
|
|
|
<OnlineEvents />
|
|
|
|
<LastEvents v-if="instanceName" :instanceName="instanceName" />
|
2022-08-22 12:12:09 +02:00
|
|
|
<!-- Unlogged content section -->
|
|
|
|
<picture v-if="!currentUser?.isLoggedIn">
|
|
|
|
<source
|
|
|
|
media="(max-width: 799px)"
|
|
|
|
:srcset="`/img/pics/homepage-480w.webp`"
|
|
|
|
type="image/webp"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<source
|
|
|
|
media="(max-width: 1024px)"
|
|
|
|
:srcset="`/img/pics/homepage-1024w.webp`"
|
|
|
|
type="image/webp"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<source
|
|
|
|
media="(max-width: 1920px)"
|
|
|
|
:srcset="`/img/pics/homepage-1920w.webp`"
|
|
|
|
type="image/webp"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<source
|
|
|
|
media="(min-width: 1921px)"
|
|
|
|
:srcset="`/img/pics/homepage.webp`"
|
|
|
|
type="image/webp"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<img
|
|
|
|
:src="`/img/pics/homepage-1024w.webp`"
|
|
|
|
width="3840"
|
|
|
|
height="2719"
|
|
|
|
alt=""
|
|
|
|
loading="lazy"
|
|
|
|
/>
|
|
|
|
</picture>
|
|
|
|
<presentation v-if="!currentUser?.isLoggedIn" />
|
2022-07-12 10:55:28 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2022-08-26 16:08:58 +02:00
|
|
|
import { ParticipantRole } from "@/types/enums";
|
2022-07-12 10:55:28 +02:00
|
|
|
import { IParticipant } from "../types/participant.model";
|
2022-07-12 10:55:28 +02:00
|
|
|
import MultiCard from "../components/Event/MultiCard.vue";
|
|
|
|
import { CURRENT_ACTOR_CLIENT } from "../graphql/actor";
|
2022-08-22 12:12:09 +02:00
|
|
|
import { IPerson, displayName } from "../types/actor";
|
2022-08-26 16:08:58 +02:00
|
|
|
import { ICurrentUser, IUser } from "../types/current-user.model";
|
2022-07-12 10:55:28 +02:00
|
|
|
import { CURRENT_USER_CLIENT } from "../graphql/user";
|
|
|
|
import { HOME_USER_QUERIES } from "../graphql/home";
|
|
|
|
import RouteName from "../router/name";
|
|
|
|
import { IEvent } from "../types/event.model";
|
|
|
|
// import { IFollowedGroupEvent } from "../types/followedGroupEvent.model";
|
|
|
|
import CloseEvents from "@/components/Local/CloseEvents.vue";
|
2022-08-22 12:12:09 +02:00
|
|
|
import CloseGroups from "@/components/Local/CloseGroups.vue";
|
2022-08-16 13:59:37 +02:00
|
|
|
import LastEvents from "@/components/Local/LastEvents.vue";
|
2022-08-26 16:08:58 +02:00
|
|
|
import OnlineEvents from "@/components/Local/OnlineEvents.vue";
|
2022-10-05 12:13:19 +02:00
|
|
|
import {
|
|
|
|
computed,
|
|
|
|
onMounted,
|
|
|
|
reactive,
|
|
|
|
ref,
|
|
|
|
watch,
|
|
|
|
defineAsyncComponent,
|
|
|
|
} from "vue";
|
2022-07-12 10:55:28 +02:00
|
|
|
import { useMutation, useQuery } from "@vue/apollo-composable";
|
|
|
|
import { useRouter } from "vue-router";
|
|
|
|
import { REVERSE_GEOCODE } from "@/graphql/address";
|
|
|
|
import { IAddress } from "@/types/address.model";
|
|
|
|
import {
|
|
|
|
CURRENT_USER_LOCATION_CLIENT,
|
|
|
|
UPDATE_CURRENT_USER_LOCATION_CLIENT,
|
|
|
|
} from "@/graphql/location";
|
|
|
|
import { LocationType } from "@/types/user-location.model";
|
|
|
|
import Presentation from "@/components/Home/MobilizonPresentation.vue";
|
|
|
|
import CategoriesPreview from "@/components/Home/CategoriesPreview.vue";
|
|
|
|
import UnloggedIntroduction from "@/components/Home/UnloggedIntroduction.vue";
|
|
|
|
import SearchFields from "@/components/Home/SearchFields.vue";
|
|
|
|
import { useHead } from "@vueuse/head";
|
2022-08-22 12:12:09 +02:00
|
|
|
import { geoHashToCoords } from "@/utils/location";
|
2022-08-26 16:08:58 +02:00
|
|
|
import { useServerProvidedLocation } from "@/composition/apollo/config";
|
|
|
|
import { ABOUT } from "@/graphql/config";
|
|
|
|
import { IConfig } from "@/types/config.model";
|
2022-11-07 09:02:20 +01:00
|
|
|
import { useI18n } from "vue-i18n";
|
|
|
|
|
|
|
|
const { t } = useI18n({ useScope: "global" });
|
2022-07-12 10:55:28 +02:00
|
|
|
|
2022-10-05 12:13:19 +02:00
|
|
|
const EventParticipationCard = defineAsyncComponent(
|
|
|
|
() => import("@/components/Event/EventParticipationCard.vue")
|
|
|
|
);
|
|
|
|
|
2022-08-26 16:08:58 +02:00
|
|
|
const { result: aboutConfigResult } = useQuery<{
|
|
|
|
config: Pick<
|
|
|
|
IConfig,
|
|
|
|
"name" | "description" | "slogan" | "registrationsOpen"
|
|
|
|
>;
|
2022-10-05 17:42:12 +02:00
|
|
|
}>(ABOUT, undefined, {
|
|
|
|
fetchPolicy: "cache-only",
|
|
|
|
});
|
2022-08-26 16:08:58 +02:00
|
|
|
|
|
|
|
const config = computed(() => aboutConfigResult.value?.config);
|
2022-07-12 10:55:28 +02:00
|
|
|
|
|
|
|
const { result: currentActorResult } = useQuery<{ currentActor: IPerson }>(
|
|
|
|
CURRENT_ACTOR_CLIENT
|
|
|
|
);
|
2022-08-22 12:12:09 +02:00
|
|
|
const currentActor = computed<IPerson | undefined>(
|
|
|
|
() => currentActorResult.value?.currentActor
|
2022-07-12 10:55:28 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
const { result: currentUserResult } = useQuery<{
|
|
|
|
currentUser: ICurrentUser;
|
|
|
|
}>(CURRENT_USER_CLIENT);
|
|
|
|
|
|
|
|
const currentUser = computed(() => currentUserResult.value?.currentUser);
|
|
|
|
|
2022-08-26 16:08:58 +02:00
|
|
|
const instanceName = computed(() => config.value?.name);
|
2022-07-12 10:55:28 +02:00
|
|
|
|
|
|
|
const { result: userResult } = useQuery<{ loggedUser: IUser }>(
|
|
|
|
HOME_USER_QUERIES,
|
|
|
|
{ afterDateTime: new Date().toISOString() },
|
|
|
|
() => ({
|
|
|
|
enabled: currentUser.value?.id != undefined,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
const loggedUser = computed(() => userResult.value?.loggedUser);
|
|
|
|
const followedGroupEvents = computed(
|
|
|
|
() => userResult.value?.loggedUser?.followedGroupEvents
|
|
|
|
);
|
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const currentUserParticipations = computed(
|
|
|
|
() => loggedUser.value?.participations.elements
|
2022-07-12 10:55:28 +02:00
|
|
|
);
|
|
|
|
|
2022-08-26 16:08:58 +02:00
|
|
|
const location = ref(null);
|
|
|
|
const search = ref("");
|
2022-07-12 10:55:28 +02:00
|
|
|
|
|
|
|
const isToday = (date: string): boolean => {
|
|
|
|
return new Date(date).toDateString() === new Date().toDateString();
|
|
|
|
};
|
|
|
|
|
|
|
|
const isTomorrow = (date: string): boolean => {
|
|
|
|
return isInDays(date, 1);
|
|
|
|
};
|
|
|
|
|
|
|
|
const isInDays = (date: string, nbDays: number): boolean => {
|
|
|
|
return calculateDiffDays(date) === nbDays;
|
|
|
|
};
|
|
|
|
|
|
|
|
const isBefore = (date: string, nbDays: number): boolean => {
|
|
|
|
return calculateDiffDays(date) < nbDays;
|
|
|
|
};
|
|
|
|
|
|
|
|
const isAfter = (date: string, nbDays: number): boolean => {
|
|
|
|
return calculateDiffDays(date) >= nbDays;
|
|
|
|
};
|
|
|
|
|
|
|
|
const isInLessThanSevenDays = (date: string): boolean => {
|
|
|
|
return isBefore(date, 7);
|
|
|
|
};
|
|
|
|
|
|
|
|
const thisWeek = (
|
|
|
|
row: [string, Map<string, IParticipant>]
|
|
|
|
): Map<string, IParticipant> => {
|
|
|
|
if (isInLessThanSevenDays(row[0])) {
|
|
|
|
return row[1];
|
|
|
|
}
|
|
|
|
return new Map();
|
|
|
|
};
|
|
|
|
|
|
|
|
const calculateDiffDays = (date: string): number => {
|
|
|
|
return Math.ceil(
|
|
|
|
(new Date(date).getTime() - new Date().getTime()) / 1000 / 60 / 60 / 24
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const thisWeekGoingToEvents = computed<IParticipant[]>(() => {
|
|
|
|
const res = (currentUserParticipations.value || []).filter(
|
|
|
|
({ event, role }) =>
|
|
|
|
event.beginsOn != null &&
|
|
|
|
isAfter(event.beginsOn, 0) &&
|
|
|
|
isBefore(event.beginsOn, 7) &&
|
|
|
|
role !== ParticipantRole.REJECTED
|
|
|
|
);
|
|
|
|
res.sort(
|
|
|
|
(a: IParticipant, b: IParticipant) =>
|
|
|
|
new Date(a.event.beginsOn).getTime() -
|
|
|
|
new Date(b.event.beginsOn).getTime()
|
|
|
|
);
|
|
|
|
return res;
|
|
|
|
});
|
|
|
|
|
|
|
|
const goingToEvents = computed<Map<string, Map<string, IParticipant>>>(() => {
|
|
|
|
return thisWeekGoingToEvents.value?.reduce(
|
|
|
|
(
|
|
|
|
acc: Map<string, Map<string, IParticipant>>,
|
|
|
|
participation: IParticipant
|
|
|
|
) => {
|
|
|
|
const day = new Date(participation.event.beginsOn).toDateString();
|
|
|
|
const participations: Map<string, IParticipant> =
|
|
|
|
acc.get(day) || new Map();
|
|
|
|
participations.set(
|
|
|
|
`${participation.event.uuid}${participation.actor.id}`,
|
|
|
|
participation
|
|
|
|
);
|
|
|
|
acc.set(day, participations);
|
|
|
|
return acc;
|
|
|
|
},
|
|
|
|
new Map()
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
const canShowMyUpcomingEvents = computed<boolean>(() => {
|
|
|
|
return currentActor.value?.id != undefined && goingToEvents.value.size > 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
const canShowFollowedGroupEvents = computed<boolean>(() => {
|
|
|
|
return filteredFollowedGroupsEvents.value.length > 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
const filteredFollowedGroupsEvents = computed<IEvent[]>(() => {
|
|
|
|
return (followedGroupEvents.value?.elements || [])
|
|
|
|
.map(({ event }: { event: IEvent }) => event)
|
|
|
|
.filter(
|
|
|
|
({ id }) =>
|
|
|
|
!thisWeekGoingToEvents.value
|
|
|
|
.map(({ event: { id: event_id } }) => event_id)
|
|
|
|
.includes(id)
|
|
|
|
)
|
|
|
|
.slice(0, 4);
|
|
|
|
});
|
|
|
|
|
2022-08-26 16:08:58 +02:00
|
|
|
const welcomeBack = ref(false);
|
|
|
|
const newRegisteredUser = ref(false);
|
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
onMounted(() => {
|
|
|
|
if (window.localStorage.getItem("welcome-back")) {
|
2022-08-26 16:08:58 +02:00
|
|
|
welcomeBack.value = true;
|
2022-07-12 10:55:28 +02:00
|
|
|
window.localStorage.removeItem("welcome-back");
|
|
|
|
}
|
|
|
|
if (window.localStorage.getItem("new-registered-user")) {
|
2022-08-26 16:08:58 +02:00
|
|
|
newRegisteredUser.value = true;
|
2022-07-12 10:55:28 +02:00
|
|
|
window.localStorage.removeItem("new-registered-user");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
watch(loggedUser, (loggedUserValue) => {
|
2022-09-27 10:50:14 +02:00
|
|
|
if (
|
|
|
|
loggedUserValue?.id &&
|
|
|
|
loggedUserValue?.settings === null &&
|
|
|
|
loggedUserValue.defaultActor?.id
|
|
|
|
) {
|
|
|
|
console.info("No user settings, going to onboarding", loggedUserValue);
|
2022-07-12 10:55:28 +02:00
|
|
|
router.push({
|
|
|
|
name: RouteName.WELCOME_SCREEN,
|
|
|
|
params: { step: "1" },
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2022-08-22 12:12:09 +02:00
|
|
|
const isLoggedIn = computed(() => loggedUser.value?.id !== undefined);
|
2022-07-12 10:55:28 +02:00
|
|
|
|
2022-08-22 12:12:09 +02:00
|
|
|
/**
|
|
|
|
* Geolocation stuff
|
|
|
|
*/
|
2022-07-12 10:55:28 +02:00
|
|
|
|
2022-08-22 12:12:09 +02:00
|
|
|
// The location hash saved in the user settings (should be the default)
|
|
|
|
const userSettingsLocationGeoHash = computed(
|
|
|
|
() => loggedUser.value?.settings?.location?.geohash
|
|
|
|
);
|
|
|
|
|
|
|
|
// The location provided by the server
|
2022-08-26 16:08:58 +02:00
|
|
|
const { location: serverLocation } = useServerProvidedLocation();
|
2022-08-22 12:12:09 +02:00
|
|
|
|
|
|
|
// The coords from the user location or the server provided location
|
|
|
|
const coords = computed(() => {
|
|
|
|
const userSettingsCoords = geoHashToCoords(
|
|
|
|
userSettingsLocationGeoHash.value ?? undefined
|
|
|
|
);
|
|
|
|
|
|
|
|
if (userSettingsCoords) {
|
|
|
|
return { ...userSettingsCoords, isIPLocation: false };
|
|
|
|
}
|
|
|
|
|
|
|
|
return { ...serverLocation.value, isIPLocation: true };
|
|
|
|
});
|
|
|
|
|
|
|
|
const { result: reverseGeocodeResult } = useQuery<{
|
|
|
|
reverseGeocode: IAddress[];
|
|
|
|
}>(REVERSE_GEOCODE, coords, () => ({
|
|
|
|
enabled: coords.value?.longitude != undefined,
|
|
|
|
}));
|
|
|
|
|
|
|
|
const userSettingsLocation = computed(() => {
|
|
|
|
const address = reverseGeocodeResult.value?.reverseGeocode[0];
|
|
|
|
const placeName = address?.locality ?? address?.region ?? address?.country;
|
|
|
|
return {
|
|
|
|
lat: coords.value?.latitude,
|
|
|
|
lon: coords.value?.longitude,
|
|
|
|
name: placeName,
|
|
|
|
picture: address?.pictureInfo,
|
|
|
|
isIPLocation: coords.value?.isIPLocation,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
const { result: currentUserLocationResult } = useQuery<{
|
|
|
|
currentUserLocation: LocationType;
|
|
|
|
}>(CURRENT_USER_LOCATION_CLIENT);
|
|
|
|
|
|
|
|
// The user's location currently in the Apollo cache
|
|
|
|
const currentUserLocation = computed(() => {
|
|
|
|
return {
|
|
|
|
...(currentUserLocationResult.value?.currentUserLocation ?? {
|
|
|
|
lat: undefined,
|
|
|
|
lon: undefined,
|
|
|
|
accuracy: undefined,
|
|
|
|
isIPLocation: undefined,
|
|
|
|
name: undefined,
|
|
|
|
picture: undefined,
|
|
|
|
}),
|
|
|
|
isIPLocation: false,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
const userLocation = computed(() => {
|
|
|
|
if (
|
|
|
|
!userSettingsLocation.value ||
|
|
|
|
(userSettingsLocation.value?.isIPLocation &&
|
|
|
|
currentUserLocation.value?.name)
|
|
|
|
) {
|
|
|
|
return currentUserLocation.value;
|
|
|
|
}
|
|
|
|
return userSettingsLocation.value;
|
|
|
|
});
|
|
|
|
|
|
|
|
const { mutate: saveCurrentUserLocation } = useMutation<any, LocationType>(
|
|
|
|
UPDATE_CURRENT_USER_LOCATION_CLIENT
|
|
|
|
);
|
|
|
|
|
|
|
|
const reverseGeoCodeInformation = reactive<{
|
|
|
|
latitude: number | undefined;
|
|
|
|
longitude: number | undefined;
|
|
|
|
accuracy: number | undefined;
|
|
|
|
}>({
|
|
|
|
latitude: undefined,
|
|
|
|
longitude: undefined,
|
|
|
|
accuracy: undefined,
|
|
|
|
});
|
|
|
|
|
|
|
|
const { onResult: onReverseGeocodeResult } = useQuery<{
|
|
|
|
reverseGeocode: IAddress[];
|
|
|
|
}>(REVERSE_GEOCODE, reverseGeoCodeInformation, () => ({
|
|
|
|
enabled: reverseGeoCodeInformation.latitude !== undefined,
|
|
|
|
}));
|
|
|
|
|
|
|
|
onReverseGeocodeResult((result) => {
|
|
|
|
if (!result?.data) return;
|
|
|
|
const geoLocationInformation = result?.data?.reverseGeocode[0];
|
|
|
|
const placeName =
|
|
|
|
geoLocationInformation.locality ??
|
|
|
|
geoLocationInformation.region ??
|
|
|
|
geoLocationInformation.country;
|
|
|
|
|
|
|
|
saveCurrentUserLocation({
|
|
|
|
lat: reverseGeoCodeInformation.latitude,
|
|
|
|
lon: reverseGeoCodeInformation.longitude,
|
|
|
|
accuracy: Math.round(reverseGeoCodeInformation.accuracy ?? 12) / 1000,
|
|
|
|
isIPLocation: false,
|
|
|
|
name: placeName,
|
|
|
|
picture: geoLocationInformation.pictureInfo,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
const fetchAndSaveCurrentLocationName = async ({
|
|
|
|
coords: { latitude, longitude, accuracy },
|
2022-08-26 16:08:58 +02:00
|
|
|
}: // eslint-disable-next-line no-undef
|
|
|
|
GeolocationPosition) => {
|
2022-08-22 12:12:09 +02:00
|
|
|
reverseGeoCodeInformation.latitude = latitude;
|
|
|
|
reverseGeoCodeInformation.longitude = longitude;
|
|
|
|
reverseGeoCodeInformation.accuracy = accuracy;
|
2022-10-05 17:42:12 +02:00
|
|
|
doingGeoloc.value = false;
|
2022-08-22 12:12:09 +02:00
|
|
|
};
|
|
|
|
|
2022-10-05 17:42:12 +02:00
|
|
|
const doingGeoloc = ref(false);
|
|
|
|
|
2022-08-22 12:12:09 +02:00
|
|
|
const performGeoLocation = () => {
|
2022-10-05 17:42:12 +02:00
|
|
|
doingGeoloc.value = true;
|
|
|
|
navigator.geolocation.getCurrentPosition(
|
|
|
|
fetchAndSaveCurrentLocationName,
|
|
|
|
() => {
|
|
|
|
doingGeoloc.value = false;
|
|
|
|
}
|
|
|
|
);
|
2022-08-22 12:12:09 +02:00
|
|
|
};
|
2022-08-12 16:46:44 +02:00
|
|
|
|
2022-08-22 12:12:09 +02:00
|
|
|
/**
|
|
|
|
* View Head
|
|
|
|
*/
|
2022-07-12 10:55:28 +02:00
|
|
|
useHead({
|
2022-07-12 10:55:28 +02:00
|
|
|
title: computed(() => instanceName.value ?? ""),
|
2022-07-12 10:55:28 +02:00
|
|
|
});
|
|
|
|
</script>
|