advplyr.audiobookshelf-app/components/app/SideDrawer.vue

208 lines
6 KiB
Vue
Raw Normal View History

<template>
2021-12-31 16:57:53 -06:00
<div class="fixed top-0 left-0 right-0 layout-wrapper w-full z-50 overflow-hidden pointer-events-none">
<div class="absolute top-0 left-0 w-full h-full bg-black transition-opacity duration-200" :class="show ? 'bg-opacity-60 pointer-events-auto' : 'bg-opacity-0'" @click="clickBackground" />
<div class="absolute top-0 right-0 w-64 h-full bg-bg transform transition-transform py-6 pointer-events-auto" :class="show ? '' : 'translate-x-64'" @click.stop>
<div class="px-6 mb-4">
<p v-if="user" class="text-base">
2021-12-31 16:57:53 -06:00
Welcome,
<strong>{{ username }}</strong>
</p>
</div>
<div class="w-full overflow-y-auto">
<template v-for="item in navItems">
<button v-if="item.action" :key="item.text" class="w-full hover:bg-bg/60 flex items-center py-3 px-6 text-fg-muted" @click="clickAction(item.action)">
<span class="text-lg" :class="item.iconOutlined ? 'material-icons-outlined' : 'material-icons'">{{ item.icon }}</span>
<p class="pl-4">{{ item.text }}</p>
</button>
<nuxt-link v-else :to="item.to" :key="item.text" class="w-full hover:bg-bg/60 flex items-center py-3 px-6 text-fg" :class="currentRoutePath.startsWith(item.to) ? 'bg-bg-hover/50' : 'text-fg-muted'">
<span class="text-lg" :class="item.iconOutlined ? 'material-icons-outlined' : 'material-icons'">{{ item.icon }}</span>
<p class="pl-4">{{ item.text }}</p>
</nuxt-link>
</template>
</div>
<div class="absolute bottom-0 left-0 w-full py-6 px-6 text-fg">
<div v-if="serverConnectionConfig" class="mb-4 flex justify-center">
<p class="text-xs text-fg-muted" style="word-break: break-word">{{ serverConnectionConfig.address }} (v{{ serverSettings.version }})</p>
</div>
<div class="flex items-center">
<p class="text-xs">{{ $config.version }}</p>
<div class="flex-grow" />
<div v-if="user" class="flex items-center" @click="disconnect">
<p class="text-xs pr-2">{{ $strings.ButtonDisconnect }}</p>
<i class="material-icons text-sm -mb-0.5">cloud_off</i>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
2021-12-04 19:56:29 -06:00
import TouchEvent from '@/objects/TouchEvent'
export default {
data() {
2021-12-04 19:56:29 -06:00
return {
touchEvent: null
}
},
watch: {
$route: {
handler() {
this.show = false
}
2021-12-04 19:56:29 -06:00
},
show: {
handler(newVal) {
if (newVal) this.registerListener()
else this.removeListener()
}
}
},
computed: {
show: {
get() {
return this.$store.state.showSideDrawer
},
set(val) {
this.$store.commit('setShowSideDrawer', val)
}
},
user() {
return this.$store.state.user.user
},
serverConnectionConfig() {
return this.$store.state.user.serverConnectionConfig
},
serverSettings() {
return this.$store.state.serverSettings || {}
},
username() {
return this.user ? this.user.username : ''
},
navItems() {
var items = [
{
icon: 'home',
text: this.$strings.ButtonHome,
to: '/bookshelf'
}
]
if (!this.serverConnectionConfig) {
items = [
{
icon: 'cloud_off',
text: this.$strings.ButtonConnectToServer,
to: '/connect'
}
].concat(items)
} else {
items.push({
icon: 'person',
text: this.$strings.HeaderAccount,
to: '/account'
})
items.push({
icon: 'equalizer',
text: this.$strings.ButtonUserStats,
to: '/stats'
})
}
2022-04-15 20:48:39 -05:00
if (this.$platform !== 'ios') {
items.push({
icon: 'folder',
iconOutlined: true,
text: this.$strings.ButtonLocalMedia,
2022-04-15 20:48:39 -05:00
to: '/localMedia/folders'
})
2022-08-21 15:02:22 -04:00
} else {
items.push({
icon: 'download',
iconOutlined: false,
text: this.$strings.HeaderDownloads,
to: '/downloads'
2022-08-21 15:02:22 -04:00
})
2022-04-15 20:48:39 -05:00
}
items.push({
icon: 'settings',
text: this.$strings.HeaderSettings,
to: '/settings'
})
if (this.serverConnectionConfig) {
items.push({
icon: 'login',
text: this.$strings.ButtonSwitchServerUser,
action: 'logout'
})
}
return items
},
currentRoutePath() {
return this.$route.path
}
},
methods: {
async clickAction(action) {
await this.$hapticsImpact()
if (action === 'logout') {
await this.logout()
this.$router.push('/connect')
}
},
clickBackground() {
this.show = false
},
async logout() {
if (this.user) {
await this.$nativeHttp.post('/logout').catch((error) => {
console.error('Failed to logout', error)
})
}
this.$socket.logout()
await this.$db.logout()
this.$localStore.removeLastLibraryId()
this.$store.commit('user/logout')
this.$store.commit('libraries/setCurrentLibrary', null)
},
async disconnect() {
await this.$hapticsImpact()
await this.logout()
if (this.$route.name !== 'bookshelf') {
this.$router.replace('/bookshelf')
} else {
location.reload()
}
2021-12-04 19:56:29 -06:00
},
touchstart(e) {
this.touchEvent = new TouchEvent(e)
},
touchend(e) {
if (!this.touchEvent) return
this.touchEvent.setEndEvent(e)
if (this.touchEvent.isSwipeRight()) {
this.show = false
}
this.touchEvent = null
},
registerListener() {
document.addEventListener('touchstart', this.touchstart)
document.addEventListener('touchend', this.touchend)
},
removeListener() {
document.removeEventListener('touchstart', this.touchstart)
document.removeEventListener('touchend', this.touchend)
}
},
mounted() {},
beforeDestroy() {
this.show = false
}
}
2022-08-03 22:17:11 -04:00
</script>