2021-11-07 02:31:46 +01:00
|
|
|
<template>
|
|
|
|
<div class="w-full bg-primary bg-opacity-40">
|
2022-08-05 01:06:39 +02:00
|
|
|
<div class="w-full h-14 flex items-center px-4 md:px-6 py-2 bg-primary">
|
|
|
|
<p class="pr-4">Collection List</p>
|
|
|
|
|
|
|
|
<div class="w-6 h-6 md:w-7 md:h-7 bg-white bg-opacity-10 rounded-full flex items-center justify-center">
|
|
|
|
<span class="text-xs md:text-sm font-mono leading-none">{{ books.length }}</span>
|
2021-11-07 02:31:46 +01:00
|
|
|
</div>
|
|
|
|
<div class="flex-grow" />
|
2022-08-05 01:22:35 +02:00
|
|
|
<p v-if="totalDuration" class="text-sm text-gray-200">{{ totalDurationPretty }}</p>
|
2021-11-07 02:31:46 +01:00
|
|
|
</div>
|
2021-11-08 01:11:29 +01:00
|
|
|
<draggable v-model="booksCopy" v-bind="dragOptions" class="list-group" handle=".drag-handle" draggable=".item" tag="div" @start="drag = true" @end="drag = false" @update="draggableUpdate">
|
|
|
|
<transition-group type="transition" :name="!drag ? 'collection-book' : null">
|
|
|
|
<template v-for="book in booksCopy">
|
2021-12-03 02:02:38 +01:00
|
|
|
<tables-collection-book-table-row :key="book.id" :is-dragging="drag" :book="book" :collection-id="collectionId" :book-cover-aspect-ratio="bookCoverAspectRatio" class="item" :class="drag ? '' : 'collection-book-item'" @edit="editBook" />
|
2021-11-07 22:28:06 +01:00
|
|
|
</template>
|
|
|
|
</transition-group>
|
|
|
|
</draggable>
|
2021-11-07 02:31:46 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-11-07 22:28:06 +01:00
|
|
|
import draggable from 'vuedraggable'
|
|
|
|
|
2021-11-07 02:31:46 +01:00
|
|
|
export default {
|
2021-11-07 22:28:06 +01:00
|
|
|
components: {
|
|
|
|
draggable
|
|
|
|
},
|
2021-11-07 02:31:46 +01:00
|
|
|
props: {
|
2021-11-07 22:28:06 +01:00
|
|
|
collectionId: String,
|
2021-11-07 02:31:46 +01:00
|
|
|
books: {
|
|
|
|
type: Array,
|
|
|
|
default: () => []
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
2021-11-07 22:28:06 +01:00
|
|
|
return {
|
|
|
|
drag: false,
|
|
|
|
dragOptions: {
|
|
|
|
animation: 200,
|
|
|
|
group: 'description',
|
|
|
|
ghostClass: 'ghost'
|
2021-11-08 01:11:29 +01:00
|
|
|
},
|
|
|
|
booksCopy: []
|
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
books: {
|
|
|
|
handler(newVal) {
|
|
|
|
this.init()
|
2021-11-07 22:28:06 +01:00
|
|
|
}
|
|
|
|
}
|
2021-11-07 02:31:46 +01:00
|
|
|
},
|
|
|
|
computed: {
|
2021-12-03 02:02:38 +01:00
|
|
|
bookCoverAspectRatio() {
|
2022-08-13 20:56:37 +02:00
|
|
|
return this.$store.getters['libraries/getBookCoverAspectRatio']
|
2022-08-05 01:22:35 +02:00
|
|
|
},
|
|
|
|
totalDuration() {
|
|
|
|
var _total = 0
|
|
|
|
this.books.forEach((book) => {
|
|
|
|
_total += book.media.duration
|
|
|
|
})
|
|
|
|
return _total
|
|
|
|
},
|
|
|
|
totalDurationPretty() {
|
|
|
|
return this.$elapsedPrettyExtended(this.totalDuration)
|
2021-11-07 02:31:46 +01:00
|
|
|
}
|
|
|
|
},
|
2021-11-07 22:28:06 +01:00
|
|
|
methods: {
|
2021-11-08 01:11:29 +01:00
|
|
|
draggableUpdate() {
|
|
|
|
var collectionUpdate = {
|
|
|
|
books: this.booksCopy.map((b) => b.id)
|
|
|
|
}
|
|
|
|
this.$axios
|
2021-11-22 03:00:40 +01:00
|
|
|
.$patch(`/api/collections/${this.collectionId}`, collectionUpdate)
|
2021-11-08 01:11:29 +01:00
|
|
|
.then((collection) => {
|
|
|
|
console.log('Collection updated', collection)
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed to update collection', error)
|
|
|
|
this.$toast.error('Failed to save collection books order')
|
|
|
|
})
|
|
|
|
},
|
2021-11-07 22:28:06 +01:00
|
|
|
editBook(book) {
|
|
|
|
var bookIds = this.books.map((b) => b.id)
|
|
|
|
this.$store.commit('setBookshelfBookIds', bookIds)
|
|
|
|
this.$store.commit('showEditModal', book)
|
2021-11-08 01:11:29 +01:00
|
|
|
},
|
|
|
|
init() {
|
|
|
|
this.booksCopy = this.books.map((b) => ({ ...b }))
|
2021-11-07 22:28:06 +01:00
|
|
|
}
|
|
|
|
},
|
2021-11-08 01:11:29 +01:00
|
|
|
mounted() {
|
|
|
|
this.init()
|
|
|
|
}
|
2021-11-07 02:31:46 +01:00
|
|
|
}
|
2021-11-07 22:28:06 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
2021-11-08 01:11:29 +01:00
|
|
|
.collection-book-item {
|
|
|
|
transition: all 0.4s ease;
|
2021-11-07 22:28:06 +01:00
|
|
|
}
|
|
|
|
|
2021-11-08 01:11:29 +01:00
|
|
|
.collection-book-enter-from,
|
|
|
|
.collection-book-leave-to {
|
2021-11-07 22:28:06 +01:00
|
|
|
opacity: 0;
|
2021-11-08 01:11:29 +01:00
|
|
|
transform: translateX(30px);
|
2021-11-07 22:28:06 +01:00
|
|
|
}
|
|
|
|
|
2021-11-08 01:11:29 +01:00
|
|
|
.collection-book-leave-active {
|
2021-11-07 22:28:06 +01:00
|
|
|
position: absolute;
|
|
|
|
}
|
|
|
|
</style>
|