2021-12-03 02:02:38 +01:00
|
|
|
<template>
|
2022-03-14 01:34:31 +01:00
|
|
|
<div class="page" :class="streamLibraryItem ? 'streaming' : ''">
|
2022-05-29 19:15:39 +02:00
|
|
|
<app-book-shelf-toolbar page="authors" is-home :authors="authors" />
|
2022-05-14 00:40:43 +02:00
|
|
|
<div id="bookshelf" class="w-full h-full p-8 overflow-y-auto">
|
|
|
|
<div class="flex flex-wrap justify-center">
|
2024-03-07 19:26:04 +01:00
|
|
|
<template v-for="author in authorsSorted">
|
2024-06-03 08:04:03 +02:00
|
|
|
<cards-author-card :key="author.id" :author="author" class="p-3" @edit="editAuthor" />
|
2022-05-14 00:40:43 +02:00
|
|
|
</template>
|
2021-12-03 02:02:38 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
async asyncData({ store, params, redirect, query, app }) {
|
|
|
|
var libraryId = params.library
|
2022-04-14 19:57:34 +02:00
|
|
|
var libraryData = await store.dispatch('libraries/fetch', libraryId)
|
|
|
|
if (!libraryData) {
|
2021-12-03 02:02:38 +01:00
|
|
|
return redirect('/oops?message=Library not found')
|
|
|
|
}
|
|
|
|
|
2022-04-14 19:57:34 +02:00
|
|
|
const library = libraryData.library
|
|
|
|
if (library.mediaType === 'podcast') {
|
|
|
|
return redirect(`/library/${libraryId}`)
|
|
|
|
}
|
|
|
|
|
2021-12-03 02:02:38 +01:00
|
|
|
return {
|
|
|
|
libraryId
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
loading: true,
|
2022-05-09 01:21:46 +02:00
|
|
|
authors: []
|
2021-12-03 02:02:38 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2022-03-14 01:34:31 +01:00
|
|
|
streamLibraryItem() {
|
|
|
|
return this.$store.state.streamLibraryItem
|
2021-12-03 02:02:38 +01:00
|
|
|
},
|
|
|
|
currentLibraryId() {
|
|
|
|
return this.$store.state.libraries.currentLibraryId
|
2022-05-09 01:21:46 +02:00
|
|
|
},
|
|
|
|
selectedAuthor() {
|
|
|
|
return this.$store.state.globals.selectedAuthor
|
2024-03-07 19:26:04 +01:00
|
|
|
},
|
|
|
|
authorSortBy() {
|
|
|
|
return this.$store.getters['user/getUserSetting']('authorSortBy') || 'name'
|
|
|
|
},
|
|
|
|
authorSortDesc() {
|
|
|
|
return !!this.$store.getters['user/getUserSetting']('authorSortDesc')
|
|
|
|
},
|
|
|
|
authorsSorted() {
|
|
|
|
const sortProp = this.authorSortBy
|
|
|
|
const bDesc = this.authorSortDesc ? -1 : 1
|
|
|
|
return this.authors.sort((a, b) => {
|
|
|
|
if (typeof a[sortProp] === 'number' && typeof b[sortProp] === 'number') {
|
|
|
|
return a[sortProp] > b[sortProp] ? bDesc : -bDesc
|
|
|
|
}
|
|
|
|
return a[sortProp].localeCompare(b[sortProp], undefined, { sensitivity: 'base' }) * bDesc
|
|
|
|
})
|
2021-12-03 02:02:38 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
async init() {
|
2022-12-13 00:33:59 +01:00
|
|
|
this.authors = await this.$axios
|
|
|
|
.$get(`/api/libraries/${this.currentLibraryId}/authors`)
|
2024-03-07 19:26:04 +01:00
|
|
|
.then((response) => response.authors)
|
2022-12-13 00:33:59 +01:00
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed to load authors', error)
|
|
|
|
return []
|
|
|
|
})
|
2021-12-03 02:02:38 +01:00
|
|
|
this.loading = false
|
2022-03-13 16:35:35 +01:00
|
|
|
},
|
|
|
|
authorAdded(author) {
|
|
|
|
if (!this.authors.some((au) => au.id === author.id)) {
|
|
|
|
this.authors.push(author)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
authorUpdated(author) {
|
|
|
|
this.authors = this.authors.map((au) => {
|
|
|
|
if (au.id === author.id) {
|
|
|
|
return author
|
|
|
|
}
|
|
|
|
return au
|
|
|
|
})
|
|
|
|
},
|
|
|
|
authorRemoved(author) {
|
|
|
|
this.authors = this.authors.filter((au) => au.id !== author.id)
|
2022-03-15 00:53:49 +01:00
|
|
|
},
|
|
|
|
editAuthor(author) {
|
2022-05-09 01:21:46 +02:00
|
|
|
this.$store.commit('globals/showEditAuthorModal', author)
|
2021-12-03 02:02:38 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.init()
|
2022-03-13 16:35:35 +01:00
|
|
|
this.$root.socket.on('author_added', this.authorAdded)
|
|
|
|
this.$root.socket.on('author_updated', this.authorUpdated)
|
|
|
|
this.$root.socket.on('author_removed', this.authorRemoved)
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
this.$root.socket.off('author_added', this.authorAdded)
|
|
|
|
this.$root.socket.off('author_updated', this.authorUpdated)
|
|
|
|
this.$root.socket.off('author_removed', this.authorRemoved)
|
2021-12-03 02:02:38 +01:00
|
|
|
}
|
|
|
|
}
|
2024-05-07 00:17:35 +02:00
|
|
|
</script>
|