2021-11-14 19:59:34 -06:00
|
|
|
<template>
|
|
|
|
<div class="w-full h-full">
|
2021-11-19 10:29:26 -06:00
|
|
|
<div class="w-full h-full" v-show="!isListView">
|
|
|
|
<template v-for="(shelf, index) in shelves">
|
|
|
|
<bookshelf-library-shelf :key="shelf.id" :books="shelf.books" :style="{ zIndex: shelves.length - index }" />
|
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
<div class="w-full h-full px-4 py-2" v-show="isListView">
|
|
|
|
<template v-for="book in books">
|
|
|
|
<app-bookshelf-list-row :key="book.id" :audiobook="book" :page-width="pageWidth" class="my-2" />
|
|
|
|
</template>
|
|
|
|
</div>
|
2021-11-14 19:59:34 -06:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
2021-11-19 10:29:26 -06:00
|
|
|
booksPerRow: 3,
|
|
|
|
pageWidth: 0
|
2021-11-14 19:59:34 -06:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2021-11-19 10:29:26 -06:00
|
|
|
bookshelfView() {
|
|
|
|
return this.$store.state.bookshelfView
|
|
|
|
},
|
|
|
|
isListView() {
|
|
|
|
return this.bookshelfView === 'list'
|
|
|
|
},
|
2021-11-14 19:59:34 -06:00
|
|
|
books() {
|
|
|
|
return this.$store.getters['audiobooks/getFilteredAndSorted']()
|
|
|
|
},
|
|
|
|
shelves() {
|
|
|
|
var shelves = []
|
|
|
|
var shelf = {
|
|
|
|
id: 0,
|
|
|
|
books: []
|
|
|
|
}
|
|
|
|
for (let i = 0; i < this.books.length; i++) {
|
|
|
|
var shelfNum = Math.floor((i + 1) / this.booksPerRow)
|
|
|
|
shelf.id = shelfNum
|
|
|
|
shelf.books.push(this.books[i])
|
|
|
|
|
|
|
|
if ((i + 1) % this.booksPerRow === 0) {
|
|
|
|
shelves.push(shelf)
|
|
|
|
shelf = {
|
|
|
|
id: 0,
|
|
|
|
books: []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (shelf.books.length) {
|
2021-11-19 10:29:26 -06:00
|
|
|
shelf.id++
|
2021-11-14 19:59:34 -06:00
|
|
|
shelves.push(shelf)
|
|
|
|
}
|
|
|
|
return shelves
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {},
|
2021-11-19 10:29:26 -06:00
|
|
|
mounted() {
|
|
|
|
this.pageWidth = window.innerWidth
|
|
|
|
}
|
2021-11-14 19:59:34 -06:00
|
|
|
}
|
2021-11-19 10:29:26 -06:00
|
|
|
</script>
|