Update:Rename UserCollections to Collections

This commit is contained in:
advplyr 2022-11-11 17:13:10 -06:00
parent fdf67e17a0
commit 4cbc8676c6
11 changed files with 30 additions and 37 deletions

View File

@ -208,7 +208,7 @@ export default {
this.$router.push('/batch') this.$router.push('/batch')
}, },
batchAddToCollectionClick() { batchAddToCollectionClick() {
this.$store.commit('globals/setShowBatchUserCollectionsModal', true) this.$store.commit('globals/setShowBatchCollectionsModal', true)
}, },
setBookshelfTotalEntities(totalEntities) { setBookshelfTotalEntities(totalEntities) {
this.totalEntities = totalEntities this.totalEntities = totalEntities

View File

@ -668,7 +668,7 @@ export default {
}, },
openCollections() { openCollections() {
this.store.commit('setSelectedLibraryItem', this.libraryItem) this.store.commit('setSelectedLibraryItem', this.libraryItem)
this.store.commit('globals/setShowUserCollectionsModal', true) this.store.commit('globals/setShowCollectionsModal', true)
}, },
createMoreMenu() { createMoreMenu() {
if (!this.$refs.moreIcon) return if (!this.$refs.moreIcon) return

View File

@ -9,7 +9,7 @@
<div ref="container" class="w-full rounded-lg bg-primary box-shadow-md overflow-y-auto overflow-x-hidden" style="max-height: 80vh"> <div ref="container" class="w-full rounded-lg bg-primary box-shadow-md overflow-y-auto overflow-x-hidden" style="max-height: 80vh">
<div v-if="show" class="w-full h-full"> <div v-if="show" class="w-full h-full">
<div class="py-4 px-4"> <div class="py-4 px-4">
<h1 v-if="!showBatchUserCollectionModal" class="text-2xl">{{ $strings.LabelAddToCollection }}</h1> <h1 v-if="!showBatchCollectionModal" class="text-2xl">{{ $strings.LabelAddToCollection }}</h1>
<h1 v-else class="text-2xl">{{ $getString('LabelAddToCollectionBatch', [selectedBookIds.length]) }}</h1> <h1 v-else class="text-2xl">{{ $getString('LabelAddToCollectionBatch', [selectedBookIds.length]) }}</h1>
</div> </div>
<div class="w-full overflow-y-auto overflow-x-hidden max-h-96"> <div class="w-full overflow-y-auto overflow-x-hidden max-h-96">
@ -57,14 +57,14 @@ export default {
computed: { computed: {
show: { show: {
get() { get() {
return this.$store.state.globals.showUserCollectionsModal return this.$store.state.globals.showCollectionsModal
}, },
set(val) { set(val) {
this.$store.commit('globals/setShowUserCollectionsModal', val) this.$store.commit('globals/setShowCollectionsModal', val)
} }
}, },
title() { title() {
if (this.showBatchUserCollectionModal) { if (this.showBatchCollectionModal) {
return this.$getString('MessageItemsSelected', [this.selectedBookIds.length]) return this.$getString('MessageItemsSelected', [this.selectedBookIds.length])
} }
return this.selectedLibraryItem ? this.selectedLibraryItem.media.metadata.title : '' return this.selectedLibraryItem ? this.selectedLibraryItem.media.metadata.title : ''
@ -85,7 +85,7 @@ export default {
return this.collections return this.collections
.map((c) => { .map((c) => {
var includesBook = false var includesBook = false
if (this.showBatchUserCollectionModal) { if (this.showBatchCollectionModal) {
// Only show collection added if all books are in the collection // Only show collection added if all books are in the collection
var collectionBookIds = c.books.map((b) => b.id) var collectionBookIds = c.books.map((b) => b.id)
includesBook = !this.selectedBookIds.find((id) => !collectionBookIds.includes(id)) includesBook = !this.selectedBookIds.find((id) => !collectionBookIds.includes(id))
@ -100,8 +100,8 @@ export default {
}) })
.sort((a, b) => (a.isBookIncluded ? -1 : 1)) .sort((a, b) => (a.isBookIncluded ? -1 : 1))
}, },
showBatchUserCollectionModal() { showBatchCollectionModal() {
return this.$store.state.globals.showBatchUserCollectionModal return this.$store.state.globals.showBatchCollectionModal
}, },
selectedBookIds() { selectedBookIds() {
return this.$store.state.selectedLibraryItems || [] return this.$store.state.selectedLibraryItems || []
@ -112,13 +112,13 @@ export default {
}, },
methods: { methods: {
loadCollections() { loadCollections() {
this.$store.dispatch('user/loadUserCollections') this.$store.dispatch('user/loadCollections')
}, },
removeFromCollection(collection) { removeFromCollection(collection) {
if (!this.selectedLibraryItemId && !this.selectedBookIds.length) return if (!this.selectedLibraryItemId && !this.selectedBookIds.length) return
this.processing = true this.processing = true
if (this.showBatchUserCollectionModal) { if (this.showBatchCollectionModal) {
// BATCH Remove books // BATCH Remove books
this.$axios this.$axios
.$post(`/api/collections/${collection.id}/batch/remove`, { books: this.selectedBookIds }) .$post(`/api/collections/${collection.id}/batch/remove`, { books: this.selectedBookIds })
@ -152,7 +152,7 @@ export default {
if (!this.selectedLibraryItemId && !this.selectedBookIds.length) return if (!this.selectedLibraryItemId && !this.selectedBookIds.length) return
this.processing = true this.processing = true
if (this.showBatchUserCollectionModal) { if (this.showBatchCollectionModal) {
// BATCH Remove books // BATCH Remove books
this.$axios this.$axios
.$post(`/api/collections/${collection.id}/batch/add`, { books: this.selectedBookIds }) .$post(`/api/collections/${collection.id}/batch/add`, { books: this.selectedBookIds })
@ -189,7 +189,7 @@ export default {
} }
this.processing = true this.processing = true
var books = this.showBatchUserCollectionModal ? this.selectedBookIds : [this.selectedLibraryItemId] var books = this.showBatchCollectionModal ? this.selectedBookIds : [this.selectedLibraryItemId]
var newCollection = { var newCollection = {
books: books, books: books,
libraryId: this.currentLibraryId, libraryId: this.currentLibraryId,

View File

@ -10,7 +10,7 @@
<app-stream-container ref="streamContainer" /> <app-stream-container ref="streamContainer" />
<modals-item-edit-modal /> <modals-item-edit-modal />
<modals-user-collections-modal /> <modals-collections-add-create-modal />
<modals-edit-collection-modal /> <modals-edit-collection-modal />
<modals-podcast-edit-episode /> <modals-podcast-edit-episode />
<modals-podcast-view-episode /> <modals-podcast-view-episode />

View File

@ -582,7 +582,7 @@ export default {
}, },
collectionsClick() { collectionsClick() {
this.$store.commit('setSelectedLibraryItem', this.libraryItem) this.$store.commit('setSelectedLibraryItem', this.libraryItem)
this.$store.commit('globals/setShowUserCollectionsModal', true) this.$store.commit('globals/setShowCollectionsModal', true)
}, },
clickRSSFeed() { clickRSSFeed() {
this.showRssFeedModal = true this.showRssFeedModal = true

View File

@ -1,8 +1,8 @@
export const state = () => ({ export const state = () => ({
isMobile: false, isMobile: false,
isMobileLandscape: false, isMobileLandscape: false,
showBatchUserCollectionModal: false, showBatchCollectionModal: false,
showUserCollectionsModal: false, showCollectionsModal: false,
showEditCollectionModal: false, showEditCollectionModal: false,
showEditPodcastEpisode: false, showEditPodcastEpisode: false,
showViewPodcastEpisodeModal: false, showViewPodcastEpisodeModal: false,
@ -68,13 +68,13 @@ export const mutations = {
state.isMobile = width < 640 || height < 640 state.isMobile = width < 640 || height < 640
state.isMobileLandscape = state.isMobile && height > width state.isMobileLandscape = state.isMobile && height > width
}, },
setShowUserCollectionsModal(state, val) { setShowCollectionsModal(state, val) {
state.showBatchUserCollectionModal = false state.showBatchCollectionModal = false
state.showUserCollectionsModal = val state.showCollectionsModal = val
}, },
setShowBatchUserCollectionsModal(state, val) { setShowBatchCollectionsModal(state, val) {
state.showBatchUserCollectionModal = true state.showBatchCollectionModal = true
state.showUserCollectionsModal = val state.showCollectionsModal = val
}, },
setShowEditCollectionModal(state, val) { setShowEditCollectionModal(state, val) {
state.showEditCollectionModal = val state.showEditCollectionModal = val

View File

@ -114,7 +114,7 @@ export const actions = {
return false return false
}) })
}, },
loadUserCollections({ state, commit }) { loadCollections({ state, commit }) {
if (state.collectionsLoaded) { if (state.collectionsLoaded) {
console.log('Collections already loaded') console.log('Collections already loaded')
return state.collections return state.collections

View File

@ -4,7 +4,7 @@ const Logger = require('./Logger')
const { version } = require('../package.json') const { version } = require('../package.json')
const LibraryItem = require('./objects/LibraryItem') const LibraryItem = require('./objects/LibraryItem')
const User = require('./objects/user/User') const User = require('./objects/user/User')
const UserCollection = require('./objects/UserCollection') const Collection = require('./objects/Collection')
const Library = require('./objects/Library') const Library = require('./objects/Library')
const Author = require('./objects/entities/Author') const Author = require('./objects/entities/Author')
const Series = require('./objects/entities/Series') const Series = require('./objects/entities/Series')
@ -180,7 +180,7 @@ class Db {
} }
}) })
var p5 = this.collectionsDb.select(() => true).then((results) => { var p5 = this.collectionsDb.select(() => true).then((results) => {
this.collections = results.data.map(l => new UserCollection(l)) this.collections = results.data.map(l => new Collection(l))
Logger.info(`[DB] ${this.collections.length} Collections Loaded`) Logger.info(`[DB] ${this.collections.length} Collections Loaded`)
}) })
var p6 = this.authorsDb.select(() => true).then((results) => { var p6 = this.authorsDb.select(() => true).then((results) => {

View File

@ -1,11 +1,11 @@
const Logger = require('../Logger') const Logger = require('../Logger')
const UserCollection = require('../objects/UserCollection') const Collection = require('../objects/Collection')
class CollectionController { class CollectionController {
constructor() { } constructor() { }
async create(req, res) { async create(req, res) {
var newCollection = new UserCollection() var newCollection = new Collection()
req.body.userId = req.user.id req.body.userId = req.user.id
var success = newCollection.setData(req.body) var success = newCollection.setData(req.body)
if (!success) { if (!success) {

View File

@ -105,13 +105,6 @@ class UserController {
} }
var user = req.reqUser var user = req.reqUser
// delete user collections
var userCollections = this.db.collections.filter(c => c.userId === user.id)
var collectionsToRemove = userCollections.map(uc => uc.id)
for (let i = 0; i < collectionsToRemove.length; i++) {
await this.db.removeEntity('collection', collectionsToRemove[i])
}
// Todo: check if user is logged in and cancel streams // Todo: check if user is logged in and cancel streams
var userJson = user.toJSONForBrowser() var userJson = user.toJSONForBrowser()

View File

@ -1,7 +1,7 @@
const Logger = require('../Logger') const Logger = require('../Logger')
const { getId } = require('../utils/index') const { getId } = require('../utils/index')
class UserCollection { class Collection {
constructor(collection) { constructor(collection) {
this.id = null this.id = null
this.libraryId = null this.libraryId = null
@ -105,4 +105,4 @@ class UserCollection {
return hasUpdates return hasUpdates
} }
} }
module.exports = UserCollection module.exports = Collection