improve user menu

This commit is contained in:
Thomas Amland 2020-07-31 18:39:29 +02:00
parent b82172adf6
commit 6ad7d8d33d
4 changed files with 32 additions and 6 deletions

View File

@ -9,9 +9,21 @@
<SearchForm/> <SearchForm/>
<template v-if="username"> <template v-if="username">
<b-dropdown variant="link" right :text="username"> <b-dropdown variant="link" right no-caret>
<template #button-content>
<b-avatar variant="secondary">
<Icon icon="person-fill"/>
</b-avatar>
</template>
<b-dropdown-text>
{{ server }}
</b-dropdown-text>
<b-dropdown-text>
{{ username }}
</b-dropdown-text>
<b-dropdown-divider/>
<b-dropdown-item-button @click="logout"> <b-dropdown-item-button @click="logout">
<Icon icon="box-arrow-right"/> Logout Log out
</b-dropdown-item-button> </b-dropdown-item-button>
</b-dropdown> </b-dropdown>
</template> </template>
@ -27,7 +39,10 @@ import SearchForm from '@/search/SearchForm.vue';
SearchForm, SearchForm,
}, },
computed: { computed: {
...mapState(["username"]) ...mapState([
"server",
"username",
])
}, },
methods: { methods: {
...mapMutations([ ...mapMutations([

View File

@ -51,7 +51,10 @@ export default Vue.extend({
this.username = await this.$auth.username; this.username = await this.$auth.username;
const success = await this.$auth.autoLogin(); const success = await this.$auth.autoLogin();
if (success) { if (success) {
this.$store.commit("setLoginSuccess", { username: this.username}); this.$store.commit("setLoginSuccess", {
username: this.username,
server: this.server,
});
this.$router.push(this.returnTo); this.$router.push(this.returnTo);
} else { } else {
this.showModal = true; this.showModal = true;
@ -62,7 +65,10 @@ export default Vue.extend({
this.busy = true; this.busy = true;
this.$auth.loginWithPassword(this.server, this.username, this.password, this.rememberLogin) this.$auth.loginWithPassword(this.server, this.username, this.password, this.rememberLogin)
.then(() => { .then(() => {
this.$store.commit("setLoginSuccess", { username: this.username }); this.$store.commit("setLoginSuccess", {
username: this.username,
server: this.server,
});
this.$router.push(this.returnTo); this.$router.push(this.returnTo);
}) })
.catch(err => { .catch(err => {

View File

@ -19,6 +19,7 @@
BIconThreeDotsVertical, BIconThreeDotsVertical,
BIconMusicNoteBeamed, BIconMusicNoteBeamed,
BIconBoxArrowRight, BIconBoxArrowRight,
BIconPersonFill,
} from 'bootstrap-vue' } from 'bootstrap-vue'
export default Vue.extend({ export default Vue.extend({
@ -38,6 +39,7 @@
BIconThreeDotsVertical, BIconThreeDotsVertical,
BIconMusicNoteBeamed, BIconMusicNoteBeamed,
BIconBoxArrowRight, BIconBoxArrowRight,
BIconPersonFill,
}, },
props: { props: {
icon: { type: String } icon: { type: String }

View File

@ -9,6 +9,7 @@ import { API } from './api';
interface State { interface State {
isLoggedIn: boolean; isLoggedIn: boolean;
username: null | string; username: null | string;
server: null | string;
showMenu: boolean; showMenu: boolean;
error: Error | null; error: Error | null;
playlists: any[]; playlists: any[];
@ -18,6 +19,7 @@ const setupRootModule = (authService: AuthService, api: API): Module<State, any>
state: { state: {
isLoggedIn: false, isLoggedIn: false,
username: null, username: null,
server: null,
showMenu: false, showMenu: false,
error: null, error: null,
playlists: [], playlists: [],
@ -29,9 +31,10 @@ const setupRootModule = (authService: AuthService, api: API): Module<State, any>
clearError(state) { clearError(state) {
state.error = null; state.error = null;
}, },
setLoginSuccess(state, { username }) { setLoginSuccess(state, { username, server }) {
state.isLoggedIn = true; state.isLoggedIn = true;
state.username = username; state.username = username;
state.server = server;
}, },
toggleMenu(state) { toggleMenu(state) {
state.showMenu = !state.showMenu; state.showMenu = !state.showMenu;