2018-01-09 16:52:26 +00:00
|
|
|
<template>
|
2019-01-21 14:08:22 +00:00
|
|
|
<nav class="navbar is-fixed-top" role="navigation" aria-label="main navigation">
|
|
|
|
<div class="navbar-brand">
|
|
|
|
<router-link class="navbar-item" :to="{ name: 'Home' }">Mobilizon</router-link>
|
2019-01-18 13:47:10 +00:00
|
|
|
|
2019-01-21 14:08:22 +00:00
|
|
|
<a
|
|
|
|
role="button"
|
|
|
|
class="navbar-burger burger"
|
|
|
|
aria-label="menu"
|
|
|
|
aria-expanded="false"
|
|
|
|
data-target="navbarBasicExample"
|
|
|
|
>
|
|
|
|
<span aria-hidden="true"></span>
|
|
|
|
<span aria-hidden="true"></span>
|
|
|
|
<span aria-hidden="true"></span>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
<div class="navbar-end">
|
|
|
|
<div class="navbar-item">
|
|
|
|
<div class="buttons">
|
2019-04-01 09:49:54 +00:00
|
|
|
<router-link class="button is-primary" v-if="!currentUser.isLoggedIn && config && config.registrationsOpen" :to="{ name: 'Register' }">
|
2019-01-21 14:08:22 +00:00
|
|
|
<strong>
|
|
|
|
<translate>Sign up</translate>
|
|
|
|
</strong>
|
|
|
|
</router-link>
|
2019-04-01 09:49:54 +00:00
|
|
|
<router-link class="button is-light" v-if="!currentUser.isLoggedIn" :to="{ name: 'Login' }">
|
2019-01-21 14:08:22 +00:00
|
|
|
<translate>Log in</translate>
|
|
|
|
</router-link>
|
|
|
|
<router-link
|
|
|
|
class="button is-light"
|
2019-04-01 09:49:54 +00:00
|
|
|
v-if="currentUser.isLoggedIn && loggedPerson"
|
2019-01-21 14:08:22 +00:00
|
|
|
:to="{ name: 'Profile', params: { name: loggedPerson.preferredUsername} }"
|
|
|
|
>
|
|
|
|
<figure class="image is-24x24">
|
|
|
|
<img :src="loggedPerson.avatarUrl">
|
|
|
|
</figure>
|
|
|
|
<span>{{ loggedPerson.preferredUsername }}</span>
|
|
|
|
</router-link>
|
2019-04-01 09:49:54 +00:00
|
|
|
|
|
|
|
<span v-if="currentUser.isLoggedIn" class="button" v-on:click="logout()">Log out</span>
|
2019-01-21 14:08:22 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</nav>
|
2018-01-09 16:52:26 +00:00
|
|
|
</template>
|
|
|
|
|
2018-12-21 14:41:34 +00:00
|
|
|
<script lang="ts">
|
2019-03-22 09:57:14 +00:00
|
|
|
import { Component, Vue, Watch } from 'vue-property-decorator';
|
|
|
|
import { SEARCH } from '@/graphql/search';
|
2019-04-01 09:49:54 +00:00
|
|
|
import { CURRENT_USER_CLIENT, UPDATE_CURRENT_USER_CLIENT } from '@/graphql/user';
|
2019-03-22 09:57:14 +00:00
|
|
|
import { onLogout } from '@/vue-apollo';
|
|
|
|
import { deleteUserData } from '@/utils/auth';
|
|
|
|
import { LOGGED_PERSON } from '@/graphql/actor';
|
2019-03-05 11:07:58 +00:00
|
|
|
import { IActor, IPerson } from '@/types/actor.model';
|
2019-03-22 09:57:14 +00:00
|
|
|
import { RouteName } from '@/router';
|
2019-03-22 12:58:19 +00:00
|
|
|
import { CONFIG } from '@/graphql/config';
|
|
|
|
import { IConfig } from '@/types/config.model';
|
2019-04-01 09:49:54 +00:00
|
|
|
import { ICurrentUser } from '@/types/current-user.model'
|
2018-12-21 14:41:34 +00:00
|
|
|
|
2019-01-24 14:57:45 +00:00
|
|
|
@Component({
|
2018-12-21 16:10:39 +00:00
|
|
|
apollo: {
|
|
|
|
search: {
|
|
|
|
query: SEARCH,
|
|
|
|
variables() {
|
|
|
|
return {
|
2019-03-22 09:57:14 +00:00
|
|
|
searchText: this.searchText,
|
2018-12-21 16:10:39 +00:00
|
|
|
};
|
2018-11-06 09:30:27 +00:00
|
|
|
},
|
2018-12-21 16:10:39 +00:00
|
|
|
skip() {
|
|
|
|
return !this.searchText;
|
2019-03-22 09:57:14 +00:00
|
|
|
},
|
2018-12-21 16:10:39 +00:00
|
|
|
},
|
2019-01-18 13:47:10 +00:00
|
|
|
currentUser: {
|
2019-03-22 09:57:14 +00:00
|
|
|
query: CURRENT_USER_CLIENT,
|
2019-01-21 14:08:22 +00:00
|
|
|
},
|
2019-03-22 12:58:19 +00:00
|
|
|
config: {
|
|
|
|
query: CONFIG,
|
|
|
|
}
|
|
|
|
}
|
2018-12-21 16:10:39 +00:00
|
|
|
})
|
|
|
|
export default class NavBar extends Vue {
|
|
|
|
notifications = [
|
2019-03-22 09:57:14 +00:00
|
|
|
{ header: 'Coucou' },
|
|
|
|
{ title: "T'as une notification", subtitle: 'Et elle est cool' },
|
2018-12-21 16:10:39 +00:00
|
|
|
];
|
|
|
|
model = null;
|
|
|
|
search: any[] = [];
|
|
|
|
searchText: string | null = null;
|
|
|
|
searchSelect = null;
|
2019-04-01 09:49:54 +00:00
|
|
|
loggedPerson: IPerson | null = null;
|
2019-03-22 12:58:19 +00:00
|
|
|
config!: IConfig;
|
2019-04-01 09:49:54 +00:00
|
|
|
currentUser!: ICurrentUser;
|
2018-12-21 14:41:34 +00:00
|
|
|
|
2018-12-21 16:10:39 +00:00
|
|
|
get items() {
|
|
|
|
return this.search.map(searchEntry => {
|
|
|
|
switch (searchEntry.__typename) {
|
2019-03-22 09:57:14 +00:00
|
|
|
case 'Actor':
|
2019-01-21 14:08:22 +00:00
|
|
|
searchEntry.label =
|
|
|
|
searchEntry.preferredUsername +
|
2019-03-22 09:57:14 +00:00
|
|
|
(searchEntry.domain === null ? '' : `@${searchEntry.domain}`);
|
2018-12-21 16:10:39 +00:00
|
|
|
break;
|
2019-03-22 09:57:14 +00:00
|
|
|
case 'Event':
|
2018-12-21 16:10:39 +00:00
|
|
|
searchEntry.label = searchEntry.title;
|
2018-12-21 14:41:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-12-21 16:10:39 +00:00
|
|
|
return searchEntry;
|
|
|
|
});
|
|
|
|
}
|
2018-12-21 14:41:34 +00:00
|
|
|
|
2019-04-01 09:49:54 +00: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-22 13:55:47 +00:00
|
|
|
@Watch('model')
|
2018-12-21 16:10:39 +00:00
|
|
|
onModelChanged(val) {
|
|
|
|
switch (val.__typename) {
|
2019-02-22 13:55:47 +00:00
|
|
|
case 'Event':
|
|
|
|
this.$router.push({ name: RouteName.EVENT, params: { uuid: val.uuid } });
|
2018-12-21 16:10:39 +00:00
|
|
|
break;
|
2019-02-22 13:55:47 +00:00
|
|
|
|
|
|
|
case 'Actor':
|
2019-01-21 14:08:22 +00:00
|
|
|
this.$router.push({
|
2019-02-22 13:55:47 +00:00
|
|
|
name: RouteName.PROFILE,
|
|
|
|
params: { name: this.usernameWithDomain(val) },
|
2019-01-21 14:08:22 +00:00
|
|
|
});
|
2018-12-21 16:10:39 +00:00
|
|
|
break;
|
2018-12-21 14:41:34 +00:00
|
|
|
}
|
2018-12-21 16:10:39 +00:00
|
|
|
}
|
2018-12-21 14:41:34 +00:00
|
|
|
|
2019-02-22 13:55:47 +00:00
|
|
|
usernameWithDomain(actor: IActor) {
|
2019-01-21 14:08:22 +00:00
|
|
|
return (
|
|
|
|
actor.preferredUsername +
|
2019-02-22 13:55:47 +00:00
|
|
|
(actor.domain === null ? '' : `@${actor.domain}`)
|
2019-01-21 14:08:22 +00:00
|
|
|
);
|
2018-12-21 16:10:39 +00:00
|
|
|
}
|
2018-07-04 12:29:17 +00:00
|
|
|
|
2018-12-21 16:10:39 +00:00
|
|
|
enter() {
|
2019-03-22 09:57:14 +00:00
|
|
|
console.log('enter');
|
|
|
|
this.$apollo.queries['search'].refetch();
|
2018-12-21 14:41:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-01 09:49:54 +00:00
|
|
|
async logout() {
|
|
|
|
await this.$apollo.mutate({
|
|
|
|
mutation: UPDATE_CURRENT_USER_CLIENT,
|
|
|
|
variables: {
|
|
|
|
id: null,
|
|
|
|
email: null,
|
|
|
|
isLoggedIn: false,
|
|
|
|
},
|
|
|
|
});
|
2019-01-18 13:47:10 +00:00
|
|
|
|
|
|
|
deleteUserData();
|
|
|
|
|
2019-04-01 09:49:54 +00:00
|
|
|
onLogout(this.$apollo)
|
|
|
|
|
|
|
|
return this.$router.push({ path: '/' })
|
2019-01-18 13:47:10 +00:00
|
|
|
}
|
2018-12-21 16:10:39 +00:00
|
|
|
}
|
2018-12-21 14:41:34 +00:00
|
|
|
</script>
|