Add navigation drawer

This commit is contained in:
Hubert Van De Walle 2020-06-18 23:06:58 +02:00
parent 0ed9905ff5
commit 496ece54eb

View File

@ -1,49 +1,108 @@
<template> <template>
<v-app-bar fixed app color="primary"> <div>
<v-navigation-drawer v-model="drawer" clipped fixed app color="primary">
<client-only>
<v-list-item v-if="loggedIn">
<v-list-item-avatar>
<v-icon>{{ mdiAccount }}</v-icon>
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-title>
{{ $auth.$state.user.username }}
</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-divider />
<v-list>
<v-list-item
v-for="(item, i) in items"
:key="i"
:to="item.to"
router
nuxt
exact
>
<v-list-item-action>
<v-icon>{{ item.icon }}</v-icon>
</v-list-item-action>
<v-list-item-content>
<v-list-item-title v-text="item.title" />
</v-list-item-content>
</v-list-item>
</v-list>
</client-only>
<template v-slot:append>
<client-only>
<div class="pa-2">
<v-btn
v-if="loggedIn"
block
color="secondary"
@click.stop="logout"
>
Logout
</v-btn>
<v-btn v-else block color="secondary" to="/account">
Login
</v-btn>
</div>
</client-only>
</template>
</v-navigation-drawer>
<v-app-bar clipped-left fixed app color="primary">
<v-app-bar-nav-icon @click.stop="drawer = !drawer">
<v-icon>{{ mdiMenu }}</v-icon>
</v-app-bar-nav-icon>
<v-btn to="/" text rounded>Simple Notes</v-btn> <v-btn to="/" text rounded>Simple Notes</v-btn>
<v-spacer /> <v-spacer />
<client-only> <client-only>
<v-btn aria-label="theme switcher" icon @click="toggleTheme"> <v-btn aria-label="theme switcher" icon @click="toggleTheme">
<v-icon <v-icon>
>{{ $vuetify.theme.dark ? mdiBrightness2 : mdiBrightness5 }} {{
$vuetify.theme.dark
? mdiBrightness2
: mdiBrightness5
}}
</v-icon> </v-icon>
</v-btn> </v-btn>
</client-only> </client-only>
<v-menu transition="scroll-y-transition" offset-y bottom left>
<template v-slot:activator="{ on }">
<v-btn aria-label="menu" icon v-on="on">
<v-icon>{{ mdiDotsVertical }}</v-icon>
</v-btn>
</template>
<v-list>
<v-list-item
v-if="loggedIn && !$route.path.includes('/notes')"
to="/notes"
>
My notes
</v-list-item>
<v-list-item v-if="loggedIn" @click="logout">
Logout
</v-list-item>
<v-list-item v-else>
<v-btn to="/account" text rounded>Account</v-btn>
</v-list-item>
</v-list>
</v-menu>
</v-app-bar> </v-app-bar>
</div>
</template> </template>
<script> <script>
import { mdiDotsVertical, mdiBrightness5, mdiBrightness2 } from '@mdi/js' import {
mdiMenu,
mdiBrightness5,
mdiBrightness2,
mdiPencil,
mdiHome,
mdiAccount,
} from '@mdi/js'
import { mapState } from 'vuex' import { mapState } from 'vuex'
export default { export default {
name: 'Navbar', name: 'Navbar',
data: () => ({ data: () => ({
mdiDotsVertical, mdiMenu,
mdiBrightness5, mdiBrightness5,
mdiBrightness2, mdiBrightness2,
mdiAccount,
drawer: false,
items: [
{
icon: mdiHome,
title: 'Welcome',
to: '/',
},
{
icon: mdiPencil,
title: 'Notes',
to: '/notes',
},
],
}), }),
computed: { computed: {
...mapState('auth', ['loggedIn']), ...mapState('auth', ['loggedIn']),