2022-05-09 01:21:46 +02:00
|
|
|
<template>
|
2022-06-04 19:07:38 +02:00
|
|
|
<div id="page-wrapper" class="bg-bg page overflow-y-auto p-4 md:p-8" :class="streamLibraryItem ? 'streaming' : ''">
|
2022-05-09 01:21:46 +02:00
|
|
|
<div class="max-w-6xl mx-auto">
|
2022-06-04 19:07:38 +02:00
|
|
|
<div class="flex flex-wrap sm:flex-nowrap justify-center mb-6">
|
2022-05-09 01:21:46 +02:00
|
|
|
<div class="w-48 min-w-48">
|
|
|
|
<div class="w-full h-52">
|
|
|
|
<covers-author-image :author="author" rounded="0" />
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-06-04 19:07:38 +02:00
|
|
|
<div class="flex-grow py-4 sm:py-0 px-4 md:px-8">
|
2022-05-09 01:21:46 +02:00
|
|
|
<div class="flex items-center mb-8">
|
|
|
|
<h1 class="text-2xl">{{ author.name }}</h1>
|
|
|
|
|
2022-05-09 01:48:57 +02:00
|
|
|
<button v-if="userCanUpdate" class="w-8 h-8 rounded-full flex items-center justify-center mx-4 cursor-pointer text-gray-300 hover:text-warning transform hover:scale-125 duration-100" @click="editAuthor">
|
2022-05-09 01:21:46 +02:00
|
|
|
<span class="material-icons text-base">edit</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
|
2022-11-09 00:10:08 +01:00
|
|
|
<p v-if="author.description" class="text-white text-opacity-60 uppercase text-xs mb-2">{{ $strings.LabelDescription }}</p>
|
2022-05-09 01:21:46 +02:00
|
|
|
<p class="text-white max-w-3xl text-sm leading-5">{{ author.description }}</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="py-4">
|
2022-11-13 00:22:16 +01:00
|
|
|
<widgets-item-slider :items="libraryItems" shelf-id="author-books" :bookshelf-view="$constants.BookshelfView.AUTHOR">
|
2022-05-20 00:42:34 +02:00
|
|
|
<nuxt-link :to="`/library/${currentLibraryId}/bookshelf?filter=authors.${$encode(author.id)}`" class="hover:underline">
|
2022-11-09 00:10:08 +01:00
|
|
|
<h2 class="text-lg">{{ libraryItems.length }} {{ $strings.LabelBooks }}</h2>
|
2022-05-20 00:42:34 +02:00
|
|
|
</nuxt-link>
|
2022-05-09 01:21:46 +02:00
|
|
|
</widgets-item-slider>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div v-for="series in authorSeries" :key="series.id" class="py-4">
|
2022-11-13 00:22:16 +01:00
|
|
|
<widgets-item-slider :items="series.items" :shelf-id="series.id" :bookshelf-view="$constants.BookshelfView.AUTHOR">
|
2022-05-20 00:42:34 +02:00
|
|
|
<nuxt-link :to="`/library/${currentLibraryId}/series/${series.id}`" class="hover:underline">
|
|
|
|
<h2 class="text-lg">{{ series.name }}</h2>
|
|
|
|
</nuxt-link>
|
2022-11-09 00:10:08 +01:00
|
|
|
<p class="text-white text-opacity-40 text-base px-2">{{ $strings.LabelSeries }}</p>
|
2022-05-09 01:21:46 +02:00
|
|
|
</widgets-item-slider>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
2023-05-13 23:47:38 +02:00
|
|
|
async asyncData({ store, app, params, redirect, query }) {
|
|
|
|
const author = await app.$axios.$get(`/api/authors/${params.id}?library=${query.library || store.state.libraries.currentLibraryId}&include=items,series`).catch((error) => {
|
2022-05-09 01:21:46 +02:00
|
|
|
console.error('Failed to get author', error)
|
|
|
|
return null
|
|
|
|
})
|
|
|
|
|
|
|
|
if (!author) {
|
|
|
|
return redirect(`/library/${store.state.libraries.currentLibraryId}/authors`)
|
|
|
|
}
|
|
|
|
|
2023-05-13 23:47:38 +02:00
|
|
|
if (query.library) {
|
|
|
|
store.commit('libraries/setCurrentLibrary', query.library)
|
|
|
|
}
|
|
|
|
|
2022-05-09 01:21:46 +02:00
|
|
|
return {
|
|
|
|
author
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
streamLibraryItem() {
|
|
|
|
return this.$store.state.streamLibraryItem
|
|
|
|
},
|
|
|
|
currentLibraryId() {
|
|
|
|
return this.$store.state.libraries.currentLibraryId
|
|
|
|
},
|
|
|
|
libraryItems() {
|
|
|
|
return this.author.libraryItems || []
|
|
|
|
},
|
|
|
|
authorSeries() {
|
|
|
|
return this.author.series || []
|
2022-05-09 01:48:57 +02:00
|
|
|
},
|
|
|
|
userCanUpdate() {
|
|
|
|
return this.$store.getters['user/getUserCanUpdate']
|
2022-05-09 01:21:46 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
editAuthor() {
|
|
|
|
this.$store.commit('globals/showEditAuthorModal', this.author)
|
|
|
|
},
|
|
|
|
authorUpdated(author) {
|
|
|
|
if (author.id === this.author.id) {
|
|
|
|
console.log('Author was updated', author)
|
|
|
|
this.author = {
|
|
|
|
...author,
|
|
|
|
series: this.authorSeries,
|
|
|
|
libraryItems: this.libraryItems
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
authorRemoved(author) {
|
|
|
|
if (author.id === this.author.id) {
|
|
|
|
console.warn('Author was removed')
|
|
|
|
this.$router.replace(`/library/${this.currentLibraryId}/authors`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
if (!this.author) this.$router.replace('/')
|
|
|
|
|
|
|
|
this.$root.socket.on('author_updated', this.authorUpdated)
|
|
|
|
this.$root.socket.on('author_removed', this.authorRemoved)
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
this.$root.socket.off('author_updated', this.authorUpdated)
|
|
|
|
this.$root.socket.off('author_removed', this.authorRemoved)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|