2018-01-09 17:52:26 +01:00
|
|
|
<template>
|
2019-10-05 19:07:50 +02:00
|
|
|
<b-navbar type="is-secondary" wrapper-class="container">
|
2019-09-20 18:22:25 +02:00
|
|
|
<template slot="brand">
|
2019-10-03 11:37:34 +02:00
|
|
|
<b-navbar-item tag="router-link" :to="{ name: RouteName.HOME }"><logo /></b-navbar-item>
|
2019-09-20 18:22:25 +02:00
|
|
|
</template>
|
|
|
|
<template slot="start">
|
2019-10-03 12:32:20 +02:00
|
|
|
<b-navbar-item tag="router-link" :to="{ name: RouteName.EXPLORE }">{{ $t('Explore') }}</b-navbar-item>
|
2019-10-09 17:25:09 +02:00
|
|
|
<b-navbar-item tag="router-link" :to="{ name: RouteName.MY_EVENTS }">{{ $t('My events') }}</b-navbar-item>
|
2019-10-03 11:37:34 +02:00
|
|
|
<b-navbar-item tag="span">
|
|
|
|
<b-button tag="router-link" :to="{ name: RouteName.CREATE_EVENT }" type="is-success">{{ $t('Create') }}</b-button>
|
|
|
|
</b-navbar-item>
|
2019-09-20 18:22:25 +02:00
|
|
|
</template>
|
|
|
|
<template slot="end">
|
|
|
|
<b-navbar-item tag="div">
|
|
|
|
<search-field />
|
|
|
|
</b-navbar-item>
|
|
|
|
|
2019-10-08 18:13:06 +02:00
|
|
|
<b-navbar-dropdown v-if="currentActor.id && currentUser.isLoggedIn" right>
|
2019-09-20 18:22:25 +02:00
|
|
|
<template slot="label" v-if="currentActor" class="navbar-dropdown-profile">
|
|
|
|
<figure class="image is-32x32" v-if="currentActor.avatar">
|
|
|
|
<img class="is-rounded" alt="avatarUrl" :src="currentActor.avatar.url">
|
|
|
|
</figure>
|
2019-10-13 16:24:43 +02:00
|
|
|
<b-icon v-else icon="account-circle" />
|
2019-09-20 18:22:25 +02:00
|
|
|
</template>
|
|
|
|
|
2019-10-12 18:19:51 +02:00
|
|
|
<b-navbar-item tag="span" v-for="identity in identities" v-if="identities.length > 1" :active="identity.id === currentActor.id" :key="identity.id">
|
2019-09-20 18:22:25 +02:00
|
|
|
<span @click="setIdentity(identity)">
|
|
|
|
<div class="media-left">
|
|
|
|
<figure class="image is-32x32" v-if="identity.avatar">
|
|
|
|
<img class="is-rounded" :src="identity.avatar.url" alt="" />
|
2019-06-17 17:15:27 +02:00
|
|
|
</figure>
|
2019-10-13 16:24:43 +02:00
|
|
|
<b-icon v-else icon="account-circle" />
|
2019-04-03 17:29:03 +02:00
|
|
|
</div>
|
2019-04-01 11:49:54 +02:00
|
|
|
|
2019-09-20 18:22:25 +02:00
|
|
|
<div class="media-content">
|
|
|
|
<span>{{ identity.displayName() }}</span>
|
2019-10-13 16:24:43 +02:00
|
|
|
<span class="has-text-grey" v-if="identity.name">
|
|
|
|
@{{ identity.preferredUsername }}
|
|
|
|
</span>
|
2019-04-03 17:29:03 +02:00
|
|
|
</div>
|
2019-09-20 18:22:25 +02:00
|
|
|
</span>
|
|
|
|
|
|
|
|
<hr class="navbar-divider">
|
|
|
|
</b-navbar-item>
|
|
|
|
|
|
|
|
|
2019-10-03 12:32:20 +02:00
|
|
|
<b-navbar-item tag="router-link" :to="{ name: RouteName.UPDATE_IDENTITY }">
|
|
|
|
{{ $t('My account') }}
|
2019-09-20 18:22:25 +02:00
|
|
|
</b-navbar-item>
|
|
|
|
|
2019-10-03 12:32:20 +02:00
|
|
|
<!-- <b-navbar-item tag="router-link" :to="{ name: RouteName.CREATE_GROUP }">-->
|
|
|
|
<!-- {{ $t('Create group') }}-->
|
|
|
|
<!-- </b-navbar-item>-->
|
2019-09-20 18:22:25 +02:00
|
|
|
|
2019-10-03 12:32:20 +02:00
|
|
|
<b-navbar-item v-if="currentUser.role === ICurrentUserRole.ADMINISTRATOR" tag="router-link" :to="{ name: RouteName.DASHBOARD }">
|
|
|
|
{{ $t('Administration') }}
|
2019-09-20 18:22:25 +02:00
|
|
|
</b-navbar-item>
|
|
|
|
|
2019-09-23 11:30:23 +02:00
|
|
|
<b-navbar-item tag="span">
|
|
|
|
<span @click="logout">{{ $t('Log out') }}</span>
|
|
|
|
</b-navbar-item>
|
2019-09-20 18:22:25 +02:00
|
|
|
</b-navbar-dropdown>
|
|
|
|
|
|
|
|
<b-navbar-item v-else tag="div">
|
|
|
|
<div class="buttons">
|
2019-10-03 11:37:34 +02:00
|
|
|
<router-link class="button is-primary" v-if="config && config.registrationsOpen" :to="{ name: RouteName.REGISTER }">
|
2019-09-20 18:22:25 +02:00
|
|
|
<strong>{{ $t('Sign up') }}</strong>
|
|
|
|
</router-link>
|
|
|
|
|
2019-10-03 11:37:34 +02:00
|
|
|
<router-link class="button is-light" :to="{ name: RouteName.LOGIN }">{{ $t('Log in') }}</router-link>
|
2019-01-21 15:08:22 +01:00
|
|
|
</div>
|
2019-09-20 18:22:25 +02:00
|
|
|
</b-navbar-item>
|
|
|
|
</template>
|
|
|
|
</b-navbar>
|
2018-01-09 17:52:26 +01:00
|
|
|
</template>
|
|
|
|
|
2018-12-21 15:41:34 +01:00
|
|
|
<script lang="ts">
|
2019-08-13 08:43:37 +02:00
|
|
|
import { Component, Vue, Watch } from 'vue-property-decorator';
|
|
|
|
import { CURRENT_USER_CLIENT } from '@/graphql/user';
|
2019-09-11 09:59:01 +02:00
|
|
|
import { changeIdentity, logout } from '@/utils/auth';
|
2019-10-03 12:32:20 +02:00
|
|
|
import { CURRENT_ACTOR_CLIENT, IDENTITIES } from '@/graphql/actor';
|
2019-09-11 09:59:01 +02:00
|
|
|
import { IPerson, Person } from '@/types/actor';
|
2019-08-13 08:43:37 +02:00
|
|
|
import { CONFIG } from '@/graphql/config';
|
|
|
|
import { IConfig } from '@/types/config.model';
|
2019-09-09 09:31:08 +02:00
|
|
|
import { ICurrentUser, ICurrentUserRole } from '@/types/current-user.model';
|
2019-08-13 08:43:37 +02:00
|
|
|
import Logo from '@/components/Logo.vue';
|
|
|
|
import SearchField from '@/components/SearchField.vue';
|
2019-09-09 09:31:08 +02:00
|
|
|
import { RouteName } from '@/router';
|
2019-10-08 20:00:26 +02:00
|
|
|
import { GraphQLError } from 'graphql';
|
2019-08-12 16:04:16 +02:00
|
|
|
|
2019-08-13 08:43:37 +02: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-09-11 09:59:01 +02:00
|
|
|
currentActor: {
|
|
|
|
query: CURRENT_ACTOR_CLIENT,
|
|
|
|
},
|
|
|
|
identities: {
|
|
|
|
query: IDENTITIES,
|
2019-09-18 17:32:37 +02:00
|
|
|
update: ({ identities }) => identities ? identities.map(identity => new Person(identity)) : [],
|
2019-10-07 13:47:46 +02:00
|
|
|
skip() {
|
|
|
|
return this.currentUser.isLoggedIn === false;
|
|
|
|
},
|
2019-10-08 18:13:06 +02:00
|
|
|
error({ graphQLErrors }) { this.handleErrors(graphQLErrors); },
|
2019-09-11 09:59:01 +02: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 {
|
2019-09-11 09:59:01 +02:00
|
|
|
currentActor!: IPerson;
|
2019-03-22 13:58:19 +01:00
|
|
|
config!: IConfig;
|
2019-04-01 11:49:54 +02:00
|
|
|
currentUser!: ICurrentUser;
|
2019-09-09 09:31:08 +02:00
|
|
|
ICurrentUserRole = ICurrentUserRole;
|
2019-09-18 17:32:37 +02:00
|
|
|
identities: IPerson[] = [];
|
2019-10-03 11:37:34 +02:00
|
|
|
RouteName = RouteName;
|
2018-12-21 15:41:34 +01:00
|
|
|
|
2019-09-18 17:32:37 +02:00
|
|
|
@Watch('currentActor')
|
|
|
|
async initializeListOfIdentities() {
|
2019-10-07 13:47:46 +02:00
|
|
|
if (!this.currentUser.isLoggedIn) return;
|
2019-09-18 17:32:37 +02:00
|
|
|
const { data } = await this.$apollo.query<{ identities: IPerson[] }>({
|
|
|
|
query: IDENTITIES,
|
|
|
|
});
|
|
|
|
if (data) {
|
|
|
|
this.identities = data.identities.map(identity => new Person(identity));
|
2019-10-04 18:28:25 +02:00
|
|
|
|
|
|
|
// If we don't have any identities, the user has validated their account,
|
|
|
|
// is logging for the first time but didn't create an identity somehow
|
|
|
|
if (this.identities.length === 0) {
|
|
|
|
await this.$router.push({
|
|
|
|
name: RouteName.REGISTER_PROFILE,
|
|
|
|
params: { email: this.currentUser.email, userAlreadyActivated: 'true' },
|
|
|
|
});
|
|
|
|
}
|
2019-09-18 17:32:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-12 13:16:36 +02:00
|
|
|
async handleErrors(errors: GraphQLError[]) {
|
|
|
|
if (errors.length > 0 && errors[0].message === 'You need to be logged-in to view your list of identities') {
|
2019-10-08 18:13:06 +02:00
|
|
|
await this.logout();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-01 11:49:54 +02:00
|
|
|
async logout() {
|
2019-08-12 16:04:16 +02:00
|
|
|
await logout(this.$apollo.provider.defaultClient);
|
2019-09-23 11:30:23 +02:00
|
|
|
this.$buefy.notification.open({
|
|
|
|
message: this.$t('You have been disconnected') as string,
|
|
|
|
type: 'is-success',
|
|
|
|
position: 'is-bottom-right',
|
|
|
|
duration: 5000,
|
|
|
|
});
|
2019-04-01 11:49:54 +02:00
|
|
|
|
2019-09-09 09:31:08 +02:00
|
|
|
if (this.$route.name === RouteName.HOME) return;
|
2019-09-23 11:30:23 +02:00
|
|
|
await this.$router.push({ name: RouteName.HOME });
|
2019-01-18 14:47:10 +01:00
|
|
|
}
|
2019-09-11 09:59:01 +02:00
|
|
|
|
|
|
|
async setIdentity(identity: IPerson) {
|
|
|
|
return await changeIdentity(this.$apollo.provider.defaultClient, identity);
|
|
|
|
}
|
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>
|
2019-08-13 08:43:37 +02:00
|
|
|
@import "../variables.scss";
|
2019-04-03 17:29:03 +02:00
|
|
|
|
2019-08-13 08:43:37 +02:00
|
|
|
nav {
|
2019-09-20 18:22:25 +02:00
|
|
|
.navbar-dropdown .navbar-item {
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
|
|
span {
|
|
|
|
display: inherit;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.is-active {
|
|
|
|
background: $secondary;
|
|
|
|
}
|
|
|
|
|
|
|
|
img {
|
|
|
|
max-height: 2.5em;
|
|
|
|
}
|
2019-09-23 11:30:23 +02:00
|
|
|
|
|
|
|
&:hover {
|
|
|
|
background: whitesmoke;
|
|
|
|
}
|
2019-09-20 18:22:25 +02:00
|
|
|
}
|
2019-04-24 17:36:25 +02:00
|
|
|
|
2019-09-20 18:22:25 +02:00
|
|
|
.navbar-item.has-dropdown a.navbar-link figure {
|
|
|
|
margin-right: 0.75rem;
|
2019-10-12 19:23:32 +02:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2019-04-03 17:29:03 +02:00
|
|
|
}
|
2019-10-11 15:07:34 +02:00
|
|
|
|
|
|
|
a.navbar-item:focus-within {
|
|
|
|
background-color: inherit;
|
|
|
|
}
|
2019-08-13 08:43:37 +02:00
|
|
|
}
|
2019-04-03 17:29:03 +02:00
|
|
|
</style>
|