2018-01-09 17:52:26 +01:00
|
|
|
<template>
|
2019-01-21 15:08:22 +01:00
|
|
|
<div id="mobilizon">
|
2021-10-10 16:24:12 +02:00
|
|
|
<VueAnnouncer />
|
|
|
|
<VueSkipTo to="#main" :label="$t('Skip to main content')" />
|
2019-04-03 17:29:03 +02:00
|
|
|
<NavBar />
|
2020-10-09 18:13:15 +02:00
|
|
|
<div v-if="config && config.demoMode">
|
2020-02-18 08:57:00 +01:00
|
|
|
<b-message
|
2020-10-09 18:13:15 +02:00
|
|
|
class="container"
|
2020-02-18 08:57:00 +01:00
|
|
|
type="is-danger"
|
|
|
|
:title="$t('Warning').toLocaleUpperCase()"
|
|
|
|
closable
|
2021-11-13 12:33:14 +01:00
|
|
|
:aria-close-label="$t('Close')"
|
2020-02-18 08:57:00 +01:00
|
|
|
>
|
2019-10-11 09:42:51 +02:00
|
|
|
<p>
|
2020-10-28 11:36:16 +01:00
|
|
|
{{ $t("This is a demonstration site to test Mobilizon.") }}
|
|
|
|
<b>{{ $t("Please do not use it in any real way.") }}</b>
|
|
|
|
{{
|
|
|
|
$t(
|
|
|
|
"This website isn't moderated and the data that you enter will be automatically destroyed every day at 00:01 (Paris timezone)."
|
|
|
|
)
|
|
|
|
}}
|
2019-10-11 09:42:51 +02:00
|
|
|
</p>
|
|
|
|
</b-message>
|
|
|
|
</div>
|
2021-02-03 18:00:49 +01:00
|
|
|
<error v-if="error" :error="error" />
|
|
|
|
|
2021-10-10 16:24:12 +02:00
|
|
|
<main id="main" v-else>
|
2019-10-08 22:27:14 +02:00
|
|
|
<transition name="fade" mode="out-in">
|
2021-10-10 16:24:12 +02:00
|
|
|
<router-view ref="routerView" />
|
2019-10-08 20:01:00 +02:00
|
|
|
</transition>
|
2019-01-21 15:08:22 +01:00
|
|
|
</main>
|
2019-04-03 17:29:03 +02:00
|
|
|
<mobilizon-footer />
|
2019-01-21 15:08:22 +01:00
|
|
|
</div>
|
2018-01-09 17:52:26 +01:00
|
|
|
</template>
|
|
|
|
|
2018-12-21 15:41:34 +01:00
|
|
|
<script lang="ts">
|
2021-10-10 16:24:12 +02:00
|
|
|
import { Component, Ref, Vue, Watch } from "vue-property-decorator";
|
2020-02-18 08:57:00 +01:00
|
|
|
import NavBar from "./components/NavBar.vue";
|
2020-11-30 10:24:11 +01:00
|
|
|
import {
|
|
|
|
AUTH_ACCESS_TOKEN,
|
|
|
|
AUTH_USER_EMAIL,
|
|
|
|
AUTH_USER_ID,
|
|
|
|
AUTH_USER_ROLE,
|
|
|
|
} from "./constants";
|
|
|
|
import {
|
|
|
|
CURRENT_USER_CLIENT,
|
|
|
|
UPDATE_CURRENT_USER_CLIENT,
|
|
|
|
} from "./graphql/user";
|
2020-02-18 08:57:00 +01:00
|
|
|
import Footer from "./components/Footer.vue";
|
|
|
|
import Logo from "./components/Logo.vue";
|
|
|
|
import { initializeCurrentActor } from "./utils/auth";
|
|
|
|
import { CONFIG } from "./graphql/config";
|
|
|
|
import { IConfig } from "./types/config.model";
|
2020-06-11 10:58:23 +02:00
|
|
|
import { ICurrentUser } from "./types/current-user.model";
|
2021-05-27 18:24:11 +02:00
|
|
|
import jwt_decode, { JwtPayload } from "jwt-decode";
|
|
|
|
import { refreshAccessToken } from "./apollo/utils";
|
2021-10-10 16:24:12 +02:00
|
|
|
import { Route } from "vue-router";
|
2020-07-09 17:24:28 +02:00
|
|
|
|
2019-08-13 08:43:37 +02:00
|
|
|
@Component({
|
2019-01-18 14:47:10 +01:00
|
|
|
apollo: {
|
2020-06-11 10:58:23 +02:00
|
|
|
currentUser: CURRENT_USER_CLIENT,
|
2019-11-21 16:07:43 +01:00
|
|
|
config: CONFIG,
|
2019-01-18 14:47:10 +01:00
|
|
|
},
|
2018-12-21 17:10:39 +01:00
|
|
|
components: {
|
2019-04-03 17:29:03 +02:00
|
|
|
Logo,
|
2019-03-22 10:57:14 +01:00
|
|
|
NavBar,
|
2021-02-03 18:00:49 +01:00
|
|
|
error: () =>
|
|
|
|
import(/* webpackChunkName: "editor" */ "./components/Error.vue"),
|
2020-02-18 08:57:00 +01:00
|
|
|
"mobilizon-footer": Footer,
|
2019-03-22 10:57:14 +01:00
|
|
|
},
|
2021-05-25 16:21:29 +02:00
|
|
|
metaInfo() {
|
|
|
|
return {
|
|
|
|
titleTemplate: "%s | Mobilizon",
|
|
|
|
};
|
|
|
|
},
|
2018-12-21 17:10:39 +01:00
|
|
|
})
|
|
|
|
export default class App extends Vue {
|
2019-11-21 16:07:43 +01:00
|
|
|
config!: IConfig;
|
2020-07-09 17:24:28 +02:00
|
|
|
|
2020-06-11 10:58:23 +02:00
|
|
|
currentUser!: ICurrentUser;
|
2019-11-21 16:07:43 +01:00
|
|
|
|
2021-02-03 18:00:49 +01:00
|
|
|
error: Error | null = null;
|
|
|
|
|
2021-05-12 18:10:33 +02:00
|
|
|
online = true;
|
|
|
|
|
2021-05-27 18:24:11 +02:00
|
|
|
interval: number | undefined = undefined;
|
|
|
|
|
2021-10-10 16:24:12 +02:00
|
|
|
@Ref("routerView") routerView!: Vue;
|
|
|
|
|
2020-09-29 09:53:48 +02:00
|
|
|
async created(): Promise<void> {
|
2019-09-18 17:32:37 +02:00
|
|
|
if (await this.initializeCurrentUser()) {
|
|
|
|
await initializeCurrentActor(this.$apollo.provider.defaultClient);
|
|
|
|
}
|
2018-12-21 15:41:34 +01:00
|
|
|
}
|
|
|
|
|
2021-02-03 18:00:49 +01:00
|
|
|
errorCaptured(error: Error): void {
|
|
|
|
this.error = error;
|
|
|
|
}
|
|
|
|
|
2019-09-18 17:32:37 +02:00
|
|
|
private async initializeCurrentUser() {
|
2019-01-18 14:47:10 +01:00
|
|
|
const userId = localStorage.getItem(AUTH_USER_ID);
|
|
|
|
const userEmail = localStorage.getItem(AUTH_USER_EMAIL);
|
2019-08-12 16:04:16 +02:00
|
|
|
const accessToken = localStorage.getItem(AUTH_ACCESS_TOKEN);
|
2019-09-09 09:31:08 +02:00
|
|
|
const role = localStorage.getItem(AUTH_USER_ROLE);
|
2019-01-18 14:47:10 +01:00
|
|
|
|
2019-09-09 09:31:08 +02:00
|
|
|
if (userId && userEmail && accessToken && role) {
|
2020-02-18 08:57:00 +01:00
|
|
|
return this.$apollo.mutate({
|
2019-01-18 14:47:10 +01:00
|
|
|
mutation: UPDATE_CURRENT_USER_CLIENT,
|
|
|
|
variables: {
|
|
|
|
id: userId,
|
|
|
|
email: userEmail,
|
2019-04-01 11:49:54 +02:00
|
|
|
isLoggedIn: true,
|
2019-09-09 09:31:08 +02:00
|
|
|
role,
|
2019-01-18 14:47:10 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2019-09-18 17:32:37 +02:00
|
|
|
return false;
|
2019-09-11 09:59:01 +02:00
|
|
|
}
|
2021-05-12 18:10:33 +02:00
|
|
|
|
|
|
|
mounted(): void {
|
|
|
|
this.online = window.navigator.onLine;
|
|
|
|
window.addEventListener("offline", () => {
|
|
|
|
this.online = false;
|
|
|
|
this.showOfflineNetworkWarning();
|
2021-06-18 18:19:04 +02:00
|
|
|
console.debug("offline");
|
2021-05-12 18:10:33 +02:00
|
|
|
});
|
|
|
|
window.addEventListener("online", () => {
|
|
|
|
this.online = true;
|
2021-06-18 18:19:04 +02:00
|
|
|
console.debug("online");
|
|
|
|
});
|
|
|
|
document.addEventListener("refreshApp", (event: Event) => {
|
|
|
|
this.$buefy.snackbar.open({
|
|
|
|
queue: false,
|
|
|
|
indefinite: true,
|
2021-06-28 08:36:18 +02:00
|
|
|
type: "is-secondary",
|
2021-06-18 18:19:04 +02:00
|
|
|
actionText: this.$t("Update app") as string,
|
|
|
|
cancelText: this.$t("Ignore") as string,
|
|
|
|
message: this.$t("A new version is available.") as string,
|
|
|
|
onAction: async () => {
|
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
|
|
// @ts-ignore
|
|
|
|
const detail = event.detail;
|
|
|
|
const registration = detail as ServiceWorkerRegistration;
|
|
|
|
try {
|
|
|
|
await this.refreshApp(registration);
|
|
|
|
window.location.reload();
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
this.$notifier.error(
|
|
|
|
this.$t(
|
|
|
|
"An error has occured while refreshing the page."
|
|
|
|
) as string
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
2021-05-12 18:10:33 +02:00
|
|
|
});
|
2021-05-27 18:24:11 +02:00
|
|
|
|
|
|
|
this.interval = setInterval(async () => {
|
|
|
|
const accessToken = localStorage.getItem(AUTH_ACCESS_TOKEN);
|
|
|
|
if (accessToken) {
|
|
|
|
const token = jwt_decode<JwtPayload>(accessToken);
|
|
|
|
if (
|
|
|
|
token?.exp !== undefined &&
|
|
|
|
new Date(token.exp * 1000 - 60000) < new Date()
|
|
|
|
) {
|
|
|
|
refreshAccessToken(this.$apollo.getClient());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 60000);
|
2021-05-12 18:10:33 +02:00
|
|
|
}
|
|
|
|
|
2021-06-18 18:19:04 +02:00
|
|
|
private async refreshApp(
|
|
|
|
registration: ServiceWorkerRegistration
|
|
|
|
): Promise<any> {
|
|
|
|
const worker = registration.waiting;
|
|
|
|
if (!worker) {
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
console.debug("Doing worker.skipWaiting().");
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const channel = new MessageChannel();
|
|
|
|
|
|
|
|
channel.port1.onmessage = (event) => {
|
|
|
|
console.debug("Done worker.skipWaiting().");
|
|
|
|
if (event.data.error) {
|
|
|
|
reject(event.data);
|
|
|
|
} else {
|
|
|
|
resolve(event.data);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
console.debug("calling skip waiting");
|
|
|
|
worker?.postMessage({ type: "skip-waiting" }, [channel.port2]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-05-12 18:10:33 +02:00
|
|
|
showOfflineNetworkWarning(): void {
|
|
|
|
this.$notifier.error(this.$t("You are offline") as string);
|
|
|
|
}
|
2021-05-27 18:24:11 +02:00
|
|
|
|
|
|
|
unmounted(): void {
|
|
|
|
clearInterval(this.interval);
|
|
|
|
this.interval = undefined;
|
|
|
|
}
|
2021-10-10 16:24:12 +02:00
|
|
|
|
2021-12-16 16:48:50 +01:00
|
|
|
@Watch("config")
|
|
|
|
async initializeStatistics(config: IConfig) {
|
|
|
|
if (config) {
|
|
|
|
const { statistics } = (await import("./services/statistics")) as {
|
|
|
|
statistics: (config: IConfig, environment: Record<string, any>) => void;
|
|
|
|
};
|
|
|
|
statistics(config, { router: this.$router, version: config.version });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-10 16:24:12 +02:00
|
|
|
@Watch("$route", { immediate: true })
|
|
|
|
updateAnnouncement(route: Route): void {
|
|
|
|
const pageTitle = this.extractPageTitleFromRoute(route);
|
|
|
|
if (pageTitle) {
|
|
|
|
this.$announcer.polite(
|
|
|
|
this.$t("Navigated to {pageTitle}", {
|
|
|
|
pageTitle,
|
|
|
|
}) as string
|
|
|
|
);
|
|
|
|
}
|
|
|
|
// Set the focus to the router view
|
|
|
|
// https://marcus.io/blog/accessible-routing-vuejs
|
|
|
|
setTimeout(() => {
|
2022-01-10 10:19:27 +01:00
|
|
|
const focusTarget = (
|
|
|
|
this.routerView?.$refs?.componentFocusTarget !== undefined
|
|
|
|
? this.routerView?.$refs?.componentFocusTarget
|
|
|
|
: this.routerView?.$el
|
|
|
|
) as HTMLElement;
|
2022-03-31 10:48:41 +02:00
|
|
|
if (focusTarget && focusTarget instanceof Element) {
|
2021-10-13 12:52:57 +02:00
|
|
|
// Make focustarget programmatically focussable
|
|
|
|
focusTarget.setAttribute("tabindex", "-1");
|
2021-10-10 16:24:12 +02:00
|
|
|
|
2021-10-13 12:52:57 +02:00
|
|
|
// Focus element
|
|
|
|
focusTarget.focus();
|
2021-10-10 16:24:12 +02:00
|
|
|
|
2021-10-13 12:52:57 +02:00
|
|
|
// Remove tabindex from focustarget.
|
|
|
|
// Reason: https://axesslab.com/skip-links/#update-3-a-comment-from-gov-uk
|
|
|
|
focusTarget.removeAttribute("tabindex");
|
|
|
|
}
|
2021-10-10 16:24:12 +02:00
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
extractPageTitleFromRoute(route: Route): string {
|
|
|
|
if (route.meta?.announcer?.message) {
|
|
|
|
return route.meta?.announcer?.message();
|
|
|
|
}
|
|
|
|
return document.title;
|
|
|
|
}
|
2018-12-21 17:10:39 +01:00
|
|
|
}
|
2018-01-09 17:52:26 +01:00
|
|
|
</script>
|
|
|
|
|
2019-04-03 17:29:03 +02:00
|
|
|
<style lang="scss">
|
2019-08-13 08:43:37 +02:00
|
|
|
@import "variables";
|
2019-04-03 17:29:03 +02:00
|
|
|
|
2019-10-09 17:54:35 +02:00
|
|
|
/* Icons */
|
|
|
|
$mdi-font-path: "~@mdi/font/fonts";
|
|
|
|
@import "~@mdi/font/scss/materialdesignicons";
|
2020-06-17 15:54:24 +02:00
|
|
|
@import "common";
|
2020-10-09 18:13:15 +02:00
|
|
|
|
|
|
|
#mobilizon {
|
|
|
|
min-height: 100vh;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
|
|
main {
|
|
|
|
flex-grow: 1;
|
|
|
|
}
|
|
|
|
}
|
2021-10-10 16:24:12 +02:00
|
|
|
|
|
|
|
.vue-skip-to {
|
|
|
|
z-index: 40;
|
|
|
|
}
|
2018-01-09 17:52:26 +01:00
|
|
|
</style>
|