2018-01-09 17:52:26 +01:00
|
|
|
<template>
|
2019-01-21 15:08:22 +01:00
|
|
|
<nav class="navbar is-fixed-top" role="navigation" aria-label="main navigation">
|
2019-04-03 17:29:03 +02:00
|
|
|
<div class="container">
|
|
|
|
<div class="navbar-brand">
|
|
|
|
<router-link class="navbar-item" :to="{ name: 'Home' }"><logo /></router-link>
|
2019-01-18 14:47:10 +01:00
|
|
|
|
2019-04-03 17:29:03 +02:00
|
|
|
<a
|
|
|
|
role="button"
|
|
|
|
class="navbar-burger burger"
|
|
|
|
aria-label="menu"
|
|
|
|
aria-expanded="false"
|
|
|
|
data-target="navbarBasicExample"
|
|
|
|
@click="showNavbar = !showNavbar" :class="{ 'is-active': showNavbar }"
|
|
|
|
>
|
|
|
|
<span aria-hidden="true"></span>
|
|
|
|
<span aria-hidden="true"></span>
|
|
|
|
<span aria-hidden="true"></span>
|
|
|
|
</a>
|
|
|
|
</div>
|
2019-06-17 17:15:27 +02:00
|
|
|
|
2019-04-03 17:29:03 +02:00
|
|
|
<div class="navbar-menu" :class="{ 'is-active': showNavbar }">
|
|
|
|
<div class="navbar-end">
|
|
|
|
<div class="navbar-item">
|
|
|
|
<search-field />
|
|
|
|
</div>
|
2019-06-17 17:15:27 +02:00
|
|
|
|
|
|
|
<div class="navbar-item has-dropdown is-hoverable" v-if="currentUser.isLoggedIn">
|
|
|
|
<a
|
|
|
|
class="navbar-link"
|
|
|
|
v-if="loggedPerson"
|
|
|
|
>
|
|
|
|
<figure class="image is-24x24" v-if="loggedPerson.avatar">
|
|
|
|
<img alt="avatarUrl" :src="loggedPerson.avatar.url">
|
|
|
|
</figure>
|
|
|
|
<span>{{ loggedPerson.preferredUsername }}</span>
|
|
|
|
</a>
|
|
|
|
|
|
|
|
<div class="navbar-dropdown">
|
|
|
|
<span class="navbar-item">
|
|
|
|
<router-link :to="{ name: 'UpdateIdentity' }" v-translate>My account</router-link>
|
|
|
|
</span>
|
|
|
|
|
|
|
|
<a v-translate class="navbar-item" v-on:click="logout()">Log out</a>
|
2019-04-03 17:29:03 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-04-01 11:49:54 +02:00
|
|
|
|
2019-06-17 17:15:27 +02:00
|
|
|
<div class="navbar-item" v-else>
|
|
|
|
<div class="buttons">
|
|
|
|
<router-link class="button is-primary" v-if="config && config.registrationsOpen" :to="{ name: 'Register' }">
|
|
|
|
<strong v-translate>Sign up</strong>
|
2019-04-26 15:22:16 +02:00
|
|
|
</router-link>
|
|
|
|
|
2019-06-17 17:15:27 +02:00
|
|
|
<router-link class="button is-primary" :to="{ name: 'Login' }" v-translate>Log in</router-link>
|
2019-04-03 17:29:03 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2019-01-21 15:08:22 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</nav>
|
2018-01-09 17:52:26 +01:00
|
|
|
</template>
|
|
|
|
|
2018-12-21 15:41:34 +01:00
|
|
|
<script lang="ts">
|
2019-03-22 10:57:14 +01:00
|
|
|
import { Component, Vue, Watch } from 'vue-property-decorator';
|
2019-04-01 11:49:54 +02:00
|
|
|
import { CURRENT_USER_CLIENT, UPDATE_CURRENT_USER_CLIENT } from '@/graphql/user';
|
2019-03-22 10:57:14 +01:00
|
|
|
import { onLogout } from '@/vue-apollo';
|
|
|
|
import { deleteUserData } from '@/utils/auth';
|
|
|
|
import { LOGGED_PERSON } from '@/graphql/actor';
|
2019-04-26 15:22:16 +02:00
|
|
|
import { IPerson } from '@/types/actor';
|
2019-03-22 13:58:19 +01:00
|
|
|
import { CONFIG } from '@/graphql/config';
|
|
|
|
import { IConfig } from '@/types/config.model';
|
2019-04-03 17:29:03 +02:00
|
|
|
import { ICurrentUser } from '@/types/current-user.model';
|
|
|
|
import Logo from '@/components/Logo.vue';
|
|
|
|
import SearchField from '@/components/SearchField.vue';
|
2018-12-21 15:41:34 +01:00
|
|
|
|
2019-01-24 15:57:45 +01:00
|
|
|
@Component({
|
2018-12-21 17:10:39 +01:00
|
|
|
apollo: {
|
2019-01-18 14:47:10 +01:00
|
|
|
currentUser: {
|
2019-03-22 10:57:14 +01:00
|
|
|
query: CURRENT_USER_CLIENT,
|
2019-01-21 15:08:22 +01:00
|
|
|
},
|
2019-03-22 13:58:19 +01:00
|
|
|
config: {
|
|
|
|
query: CONFIG,
|
2019-03-21 20:23:42 +01:00
|
|
|
},
|
|
|
|
},
|
2019-04-03 17:29:03 +02:00
|
|
|
components: {
|
|
|
|
Logo,
|
|
|
|
SearchField,
|
|
|
|
},
|
2018-12-21 17:10:39 +01:00
|
|
|
})
|
|
|
|
export default class NavBar extends Vue {
|
|
|
|
notifications = [
|
2019-03-22 10:57:14 +01:00
|
|
|
{ header: 'Coucou' },
|
|
|
|
{ title: "T'as une notification", subtitle: 'Et elle est cool' },
|
2018-12-21 17:10:39 +01:00
|
|
|
];
|
2019-04-01 11:49:54 +02:00
|
|
|
loggedPerson: IPerson | null = null;
|
2019-03-22 13:58:19 +01:00
|
|
|
config!: IConfig;
|
2019-04-01 11:49:54 +02:00
|
|
|
currentUser!: ICurrentUser;
|
2019-04-03 17:29:03 +02:00
|
|
|
showNavbar: boolean = false;
|
2018-12-21 15:41:34 +01:00
|
|
|
|
2019-04-01 11:49:54 +02:00
|
|
|
@Watch('currentUser')
|
|
|
|
async onCurrentUserChanged() {
|
|
|
|
// Refresh logged person object
|
|
|
|
if (this.currentUser.isLoggedIn) {
|
|
|
|
const result = await this.$apollo.query({
|
|
|
|
query: LOGGED_PERSON,
|
|
|
|
});
|
|
|
|
|
|
|
|
this.loggedPerson = result.data.loggedPerson;
|
|
|
|
} else {
|
|
|
|
this.loggedPerson = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async logout() {
|
|
|
|
await this.$apollo.mutate({
|
|
|
|
mutation: UPDATE_CURRENT_USER_CLIENT,
|
|
|
|
variables: {
|
|
|
|
id: null,
|
|
|
|
email: null,
|
|
|
|
isLoggedIn: false,
|
|
|
|
},
|
|
|
|
});
|
2019-01-18 14:47:10 +01:00
|
|
|
|
|
|
|
deleteUserData();
|
|
|
|
|
2019-04-03 17:29:03 +02:00
|
|
|
onLogout(this.$apollo);
|
2019-04-01 11:49:54 +02:00
|
|
|
|
2019-04-03 17:29:03 +02:00
|
|
|
return this.$router.push({ path: '/' });
|
2019-01-18 14:47:10 +01:00
|
|
|
}
|
2018-12-21 17:10:39 +01:00
|
|
|
}
|
2018-12-21 15:41:34 +01:00
|
|
|
</script>
|
2019-04-03 17:29:03 +02:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
@import "../variables.scss";
|
|
|
|
|
|
|
|
nav {
|
|
|
|
border-bottom: solid 1px #0a0a0a;
|
2019-04-24 17:36:25 +02:00
|
|
|
|
|
|
|
.navbar-item img {
|
|
|
|
max-height: 2.5em;
|
|
|
|
}
|
2019-04-03 17:29:03 +02:00
|
|
|
}
|
|
|
|
</style>
|