2018-01-09 16:52:26 +00:00
|
|
|
<template>
|
2019-01-21 14:08:22 +00:00
|
|
|
<div id="mobilizon">
|
2019-04-03 15:29:03 +00:00
|
|
|
<NavBar />
|
2020-10-09 16:13:15 +00:00
|
|
|
<div v-if="config && config.demoMode">
|
2020-02-18 07:57:00 +00:00
|
|
|
<b-message
|
2020-10-09 16:13:15 +00:00
|
|
|
class="container"
|
2020-02-18 07:57:00 +00:00
|
|
|
type="is-danger"
|
|
|
|
:title="$t('Warning').toLocaleUpperCase()"
|
|
|
|
closable
|
|
|
|
aria-close-label="Close"
|
|
|
|
>
|
2019-10-11 07:42:51 +00:00
|
|
|
<p>
|
2020-10-28 10:36:16 +00: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 07:42:51 +00:00
|
|
|
</p>
|
|
|
|
</b-message>
|
|
|
|
</div>
|
2021-02-03 17:00:49 +00:00
|
|
|
<error v-if="error" :error="error" />
|
|
|
|
|
|
|
|
<main v-else>
|
2019-10-08 20:27:14 +00:00
|
|
|
<transition name="fade" mode="out-in">
|
2019-10-08 18:01:00 +00:00
|
|
|
<router-view />
|
|
|
|
</transition>
|
2019-01-21 14:08:22 +00:00
|
|
|
</main>
|
2019-04-03 15:29:03 +00:00
|
|
|
<mobilizon-footer />
|
2019-01-21 14:08:22 +00:00
|
|
|
</div>
|
2018-01-09 16:52:26 +00:00
|
|
|
</template>
|
|
|
|
|
2018-12-21 14:41:34 +00:00
|
|
|
<script lang="ts">
|
2020-02-18 07:57:00 +00:00
|
|
|
import { Component, Vue } from "vue-property-decorator";
|
|
|
|
import NavBar from "./components/NavBar.vue";
|
2020-11-30 09:24:11 +00: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 07:57:00 +00: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 08:58:23 +00:00
|
|
|
import { ICurrentUser } from "./types/current-user.model";
|
2021-05-27 16:24:11 +00:00
|
|
|
import jwt_decode, { JwtPayload } from "jwt-decode";
|
|
|
|
import { refreshAccessToken } from "./apollo/utils";
|
2020-07-09 15:24:28 +00:00
|
|
|
|
2019-08-13 06:43:37 +00:00
|
|
|
@Component({
|
2019-01-18 13:47:10 +00:00
|
|
|
apollo: {
|
2020-06-11 08:58:23 +00:00
|
|
|
currentUser: CURRENT_USER_CLIENT,
|
2019-11-21 15:07:43 +00:00
|
|
|
config: CONFIG,
|
2019-01-18 13:47:10 +00:00
|
|
|
},
|
2018-12-21 16:10:39 +00:00
|
|
|
components: {
|
2019-04-03 15:29:03 +00:00
|
|
|
Logo,
|
2019-03-22 09:57:14 +00:00
|
|
|
NavBar,
|
2021-02-03 17:00:49 +00:00
|
|
|
error: () =>
|
|
|
|
import(/* webpackChunkName: "editor" */ "./components/Error.vue"),
|
2020-02-18 07:57:00 +00:00
|
|
|
"mobilizon-footer": Footer,
|
2019-03-22 09:57:14 +00:00
|
|
|
},
|
2021-05-25 14:21:29 +00:00
|
|
|
metaInfo() {
|
|
|
|
return {
|
|
|
|
titleTemplate: "%s | Mobilizon",
|
|
|
|
};
|
|
|
|
},
|
2018-12-21 16:10:39 +00:00
|
|
|
})
|
|
|
|
export default class App extends Vue {
|
2019-11-21 15:07:43 +00:00
|
|
|
config!: IConfig;
|
2020-07-09 15:24:28 +00:00
|
|
|
|
2020-06-11 08:58:23 +00:00
|
|
|
currentUser!: ICurrentUser;
|
2019-11-21 15:07:43 +00:00
|
|
|
|
2021-02-03 17:00:49 +00:00
|
|
|
error: Error | null = null;
|
|
|
|
|
2021-05-12 16:10:33 +00:00
|
|
|
online = true;
|
|
|
|
|
2021-05-27 16:24:11 +00:00
|
|
|
interval: number | undefined = undefined;
|
|
|
|
|
2020-09-29 07:53:48 +00:00
|
|
|
async created(): Promise<void> {
|
2019-09-18 15:32:37 +00:00
|
|
|
if (await this.initializeCurrentUser()) {
|
|
|
|
await initializeCurrentActor(this.$apollo.provider.defaultClient);
|
|
|
|
}
|
2018-12-21 14:41:34 +00:00
|
|
|
}
|
|
|
|
|
2021-02-03 17:00:49 +00:00
|
|
|
errorCaptured(error: Error): void {
|
|
|
|
this.error = error;
|
|
|
|
}
|
|
|
|
|
2019-09-18 15:32:37 +00:00
|
|
|
private async initializeCurrentUser() {
|
2019-01-18 13:47:10 +00:00
|
|
|
const userId = localStorage.getItem(AUTH_USER_ID);
|
|
|
|
const userEmail = localStorage.getItem(AUTH_USER_EMAIL);
|
2019-08-12 14:04:16 +00:00
|
|
|
const accessToken = localStorage.getItem(AUTH_ACCESS_TOKEN);
|
2019-09-09 07:31:08 +00:00
|
|
|
const role = localStorage.getItem(AUTH_USER_ROLE);
|
2019-01-18 13:47:10 +00:00
|
|
|
|
2019-09-09 07:31:08 +00:00
|
|
|
if (userId && userEmail && accessToken && role) {
|
2020-02-18 07:57:00 +00:00
|
|
|
return this.$apollo.mutate({
|
2019-01-18 13:47:10 +00:00
|
|
|
mutation: UPDATE_CURRENT_USER_CLIENT,
|
|
|
|
variables: {
|
|
|
|
id: userId,
|
|
|
|
email: userEmail,
|
2019-04-01 09:49:54 +00:00
|
|
|
isLoggedIn: true,
|
2019-09-09 07:31:08 +00:00
|
|
|
role,
|
2019-01-18 13:47:10 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2019-09-18 15:32:37 +00:00
|
|
|
return false;
|
2019-09-11 07:59:01 +00:00
|
|
|
}
|
2021-05-12 16:10:33 +00:00
|
|
|
|
|
|
|
mounted(): void {
|
|
|
|
this.online = window.navigator.onLine;
|
|
|
|
window.addEventListener("offline", () => {
|
|
|
|
this.online = false;
|
|
|
|
this.showOfflineNetworkWarning();
|
|
|
|
console.log("offline");
|
|
|
|
});
|
|
|
|
window.addEventListener("online", () => {
|
|
|
|
this.online = true;
|
|
|
|
console.log("online");
|
|
|
|
});
|
2021-05-27 16:24:11 +00: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 16:10:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
showOfflineNetworkWarning(): void {
|
|
|
|
this.$notifier.error(this.$t("You are offline") as string);
|
|
|
|
}
|
2021-05-27 16:24:11 +00:00
|
|
|
|
|
|
|
unmounted(): void {
|
|
|
|
clearInterval(this.interval);
|
|
|
|
this.interval = undefined;
|
|
|
|
}
|
2018-12-21 16:10:39 +00:00
|
|
|
}
|
2018-01-09 16:52:26 +00:00
|
|
|
</script>
|
|
|
|
|
2019-04-03 15:29:03 +00:00
|
|
|
<style lang="scss">
|
2019-08-13 06:43:37 +00:00
|
|
|
@import "variables";
|
2019-04-03 15:29:03 +00:00
|
|
|
|
2019-10-09 15:54:35 +00:00
|
|
|
/* Icons */
|
|
|
|
$mdi-font-path: "~@mdi/font/fonts";
|
|
|
|
@import "~@mdi/font/scss/materialdesignicons";
|
|
|
|
|
2020-06-17 13:54:24 +00:00
|
|
|
@import "common";
|
2020-10-09 16:13:15 +00:00
|
|
|
|
|
|
|
#mobilizon {
|
|
|
|
min-height: 100vh;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
|
|
main {
|
|
|
|
flex-grow: 1;
|
|
|
|
}
|
|
|
|
}
|
2018-01-09 16:52:26 +00:00
|
|
|
</style>
|