add close button to sidebar

This commit is contained in:
Thomas Amland 2020-08-19 18:39:11 +02:00
parent d08118bfad
commit 0dccb04bd5
5 changed files with 28 additions and 16 deletions

View File

@ -1,9 +1,12 @@
<template> <template>
<div> <div>
<nav class="nav flex-column"> <nav class="nav flex-column">
<router-link class="nav-link logo" :to="{name: 'home'}"> <div class="nav-link logo d-flex justify-content-between">
<Logo /> <Logo />
</router-link> <button class="btn btn-link btn-lg p-0 d-md-none" @click="hideMenu">
<Icon icon="x" />
</button>
</div>
<router-link class="nav-link" :to="{name: 'home'}"> <router-link class="nav-link" :to="{name: 'home'}">
<Icon icon="card-text" class="" /> Home <Icon icon="card-text" class="" /> Home
@ -43,6 +46,7 @@
import Vue from 'vue' import Vue from 'vue'
import Logo from './Logo.vue' import Logo from './Logo.vue'
import PlaylistNav from '@/playlist/PlaylistNav.vue' import PlaylistNav from '@/playlist/PlaylistNav.vue'
import { mapActions } from 'vuex'
export default Vue.extend({ export default Vue.extend({
components: { components: {
@ -50,10 +54,7 @@
PlaylistNav, PlaylistNav,
}, },
methods: { methods: {
logout() { ...mapActions(['hideMenu']),
this.$auth.logout()
this.$router.go(0)
}, },
}
}) })
</script> </script>

View File

@ -12,13 +12,16 @@
no-header no-header
backdrop backdrop
backdrop-variant="" backdrop-variant=""
@hidden="toggleMenu" @hidden="hideMenu"
> >
<Nav /> <Nav />
</b-sidebar> </b-sidebar>
</div> </div>
</template> </template>
<style> <style>
.sidebar-container nav {
padding-top: 0.5rem;
}
.sidebar-container .sidebar-fixed { .sidebar-container .sidebar-fixed {
padding-left: 0.5rem; padding-left: 0.5rem;
padding-right: 0.5rem; padding-right: 0.5rem;
@ -48,7 +51,7 @@
<script lang="ts"> <script lang="ts">
import Vue from 'vue' import Vue from 'vue'
import Nav from './Nav.vue' import Nav from './Nav.vue'
import { mapState, mapMutations } from 'vuex' import { mapState, mapActions } from 'vuex'
export default Vue.extend({ export default Vue.extend({
components: { components: {
@ -58,7 +61,7 @@
...mapState(['showMenu']) ...mapState(['showMenu'])
}, },
methods: { methods: {
...mapMutations(['toggleMenu']), ...mapActions(['hideMenu']),
}, },
}) })
</script> </script>

View File

@ -1,6 +1,6 @@
<template> <template>
<div class="d-flex align-items-center mb-2"> <div class="d-flex align-items-center mb-2">
<button class="navbar-toggler text-white d-md-none" @click="toggleMenu"> <button class="navbar-toggler text-white d-md-none" @click="showMenu">
<Icon icon="list" /> <Icon icon="list" />
</button> </button>
@ -31,7 +31,7 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import Vue from 'vue' import Vue from 'vue'
import { mapMutations, mapState } from 'vuex' import { mapActions, mapState } from 'vuex'
import SearchForm from '@/search/SearchForm.vue' import SearchForm from '@/search/SearchForm.vue'
export default Vue.extend({ export default Vue.extend({
@ -45,8 +45,8 @@
]), ]),
}, },
methods: { methods: {
...mapMutations([ ...mapActions([
'toggleMenu', 'showMenu',
]), ]),
logout() { logout() {
this.$auth.logout() this.$auth.logout()

View File

@ -21,6 +21,7 @@
BIconBoxArrowRight, BIconBoxArrowRight,
BIconPersonFill, BIconPersonFill,
BIconPersonCircle, BIconPersonCircle,
BIconX,
} from 'bootstrap-vue' } from 'bootstrap-vue'
export default Vue.extend({ export default Vue.extend({
@ -42,6 +43,7 @@
BIconBoxArrowRight, BIconBoxArrowRight,
BIconPersonFill, BIconPersonFill,
BIconPersonCircle, BIconPersonCircle,
BIconX,
}, },
props: { props: {
icon: { type: String, required: true } icon: { type: String, required: true }

View File

@ -34,8 +34,8 @@ const setupRootModule = (authService: AuthService, api: API): Module<State, any>
state.username = username state.username = username
state.server = server state.server = server
}, },
toggleMenu(state) { setMenuVisible(state, visible) {
state.showMenu = !state.showMenu state.showMenu = visible
}, },
setPlaylists(state, playlists: any[]) { setPlaylists(state, playlists: any[]) {
state.playlists = playlists state.playlists = playlists
@ -46,6 +46,12 @@ const setupRootModule = (authService: AuthService, api: API): Module<State, any>
}, },
}, },
actions: { actions: {
showMenu({ commit }) {
commit('setMenuVisible', true)
},
hideMenu({ commit }) {
commit('setMenuVisible', false)
},
loadPlaylists({ commit }) { loadPlaylists({ commit }) {
api.getPlaylists().then(result => { api.getPlaylists().then(result => {
commit('setPlaylists', result) commit('setPlaylists', result)