2021-11-06 02:24:02 +01:00
|
|
|
export const state = () => ({
|
2022-02-09 18:19:02 +01:00
|
|
|
isMobile: false,
|
|
|
|
isMobileLandscape: false,
|
2023-01-01 19:41:46 +01:00
|
|
|
isMobilePortrait: false,
|
2022-11-12 00:13:10 +01:00
|
|
|
showBatchCollectionModal: false,
|
|
|
|
showCollectionsModal: false,
|
2021-11-07 02:31:46 +01:00
|
|
|
showEditCollectionModal: false,
|
2022-11-26 23:25:14 +01:00
|
|
|
showPlaylistsModal: false,
|
2022-11-27 18:53:48 +01:00
|
|
|
showEditPlaylistModal: false,
|
2022-04-23 02:31:11 +02:00
|
|
|
showEditPodcastEpisode: false,
|
2022-05-28 18:38:51 +02:00
|
|
|
showViewPodcastEpisodeModal: false,
|
2022-12-31 22:26:37 +01:00
|
|
|
showRSSFeedOpenCloseModal: false,
|
2022-07-30 18:36:04 +02:00
|
|
|
showConfirmPrompt: false,
|
|
|
|
confirmPromptOptions: null,
|
2022-05-09 01:21:46 +02:00
|
|
|
showEditAuthorModal: false,
|
2022-12-31 22:26:37 +01:00
|
|
|
rssFeedEntity: null,
|
2022-04-23 02:31:11 +02:00
|
|
|
selectedEpisode: null,
|
2022-11-26 23:25:14 +01:00
|
|
|
selectedPlaylistItems: null,
|
2022-11-27 18:53:48 +01:00
|
|
|
selectedPlaylist: null,
|
2021-11-28 03:11:35 +01:00
|
|
|
selectedCollection: null,
|
2022-05-09 01:21:46 +02:00
|
|
|
selectedAuthor: null,
|
2022-12-01 00:09:00 +01:00
|
|
|
selectedMediaItems: [],
|
2022-02-23 00:33:55 +01:00
|
|
|
isCasting: false, // Actively casting
|
2022-11-27 18:53:48 +01:00
|
|
|
isChromecastInitialized: false, // Script loadeds
|
2022-09-19 17:29:24 +02:00
|
|
|
showBatchQuickMatchModal: false,
|
2022-06-17 10:26:10 +02:00
|
|
|
dateFormats: [
|
|
|
|
{
|
|
|
|
text: 'MM/DD/YYYY',
|
|
|
|
value: 'MM/dd/yyyy'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'DD/MM/YYYY',
|
|
|
|
value: 'dd/MM/yyyy'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'YYYY-MM-DD',
|
|
|
|
value: 'yyyy-MM-dd'
|
|
|
|
}
|
2022-10-18 19:09:36 +02:00
|
|
|
],
|
2023-02-22 19:22:52 +01:00
|
|
|
podcastTypes: [
|
|
|
|
{ text: 'Episodic', value: 'episodic' },
|
|
|
|
{ text: 'Serial', value: 'serial' }
|
|
|
|
],
|
|
|
|
episodeTypes: [
|
|
|
|
{ text: 'Full', value: 'full' },
|
|
|
|
{ text: 'Trailer', value: 'trailer' },
|
|
|
|
{ text: 'Bonus', value: 'bonus' }
|
|
|
|
],
|
2022-10-18 19:09:36 +02:00
|
|
|
libraryIcons: ['database', 'audiobookshelf', 'books-1', 'books-2', 'book-1', 'microphone-1', 'microphone-3', 'radio', 'podcast', 'rss', 'headphones', 'music', 'file-picture', 'rocket', 'power', 'star', 'heart']
|
2021-11-06 02:24:02 +01:00
|
|
|
})
|
|
|
|
|
2022-03-14 01:34:31 +01:00
|
|
|
export const getters = {
|
2022-10-01 23:07:30 +02:00
|
|
|
getLibraryItemCoverSrc: (state, getters, rootState, rootGetters) => (libraryItem, placeholder = null) => {
|
|
|
|
if (!placeholder) placeholder = `${rootState.routerBasePath}/book_placeholder.jpg`
|
2022-03-14 01:34:31 +01:00
|
|
|
if (!libraryItem) return placeholder
|
|
|
|
var media = libraryItem.media
|
|
|
|
if (!media || !media.coverPath || media.coverPath === placeholder) return placeholder
|
|
|
|
|
|
|
|
// Absolute URL covers (should no longer be used)
|
|
|
|
if (media.coverPath.startsWith('http:') || media.coverPath.startsWith('https:')) return media.coverPath
|
|
|
|
|
2022-09-26 00:11:39 +02:00
|
|
|
const userToken = rootGetters['user/getToken']
|
|
|
|
const lastUpdate = libraryItem.updatedAt || Date.now()
|
|
|
|
const libraryItemId = libraryItem.libraryItemId || libraryItem.id // Workaround for /users/:id page showing media progress covers
|
2022-03-14 01:34:31 +01:00
|
|
|
|
|
|
|
if (process.env.NODE_ENV !== 'production') { // Testing
|
2022-10-01 23:07:30 +02:00
|
|
|
return `http://localhost:3333${rootState.routerBasePath}/api/items/${libraryItemId}/cover?token=${userToken}&ts=${lastUpdate}`
|
2022-03-14 01:34:31 +01:00
|
|
|
}
|
2022-09-26 00:11:39 +02:00
|
|
|
|
2022-10-01 23:07:30 +02:00
|
|
|
return `${rootState.routerBasePath}/api/items/${libraryItemId}/cover?token=${userToken}&ts=${lastUpdate}`
|
2022-08-28 20:12:38 +02:00
|
|
|
},
|
2022-10-01 23:07:30 +02:00
|
|
|
getLibraryItemCoverSrcById: (state, getters, rootState, rootGetters) => (libraryItemId, placeholder = null) => {
|
|
|
|
if (!placeholder) placeholder = `${rootState.routerBasePath}/book_placeholder.jpg`
|
2022-08-28 20:12:38 +02:00
|
|
|
if (!libraryItemId) return placeholder
|
|
|
|
var userToken = rootGetters['user/getToken']
|
|
|
|
if (process.env.NODE_ENV !== 'production') { // Testing
|
2022-10-01 23:07:30 +02:00
|
|
|
return `http://localhost:3333${rootState.routerBasePath}/api/items/${libraryItemId}/cover?token=${userToken}`
|
2022-08-28 20:12:38 +02:00
|
|
|
}
|
2022-10-01 23:07:30 +02:00
|
|
|
return `${rootState.routerBasePath}/api/items/${libraryItemId}/cover?token=${userToken}`
|
2022-12-01 00:09:00 +01:00
|
|
|
},
|
|
|
|
getIsBatchSelectingMediaItems: (state) => {
|
|
|
|
return state.selectedMediaItems.length
|
2022-03-14 01:34:31 +01:00
|
|
|
}
|
|
|
|
}
|
2021-11-06 02:24:02 +01:00
|
|
|
|
|
|
|
export const mutations = {
|
2022-02-09 18:19:02 +01:00
|
|
|
updateWindowSize(state, { width, height }) {
|
2022-02-11 15:50:28 +01:00
|
|
|
state.isMobile = width < 640 || height < 640
|
2023-01-01 19:41:46 +01:00
|
|
|
state.isMobileLandscape = state.isMobile && height < width
|
|
|
|
state.isMobilePortrait = state.isMobile && height >= width
|
2022-02-09 18:19:02 +01:00
|
|
|
},
|
2022-11-12 00:13:10 +01:00
|
|
|
setShowCollectionsModal(state, val) {
|
|
|
|
state.showBatchCollectionModal = false
|
|
|
|
state.showCollectionsModal = val
|
2021-11-27 23:01:53 +01:00
|
|
|
},
|
2022-11-12 00:13:10 +01:00
|
|
|
setShowBatchCollectionsModal(state, val) {
|
|
|
|
state.showBatchCollectionModal = true
|
|
|
|
state.showCollectionsModal = val
|
2021-11-07 02:31:46 +01:00
|
|
|
},
|
|
|
|
setShowEditCollectionModal(state, val) {
|
|
|
|
state.showEditCollectionModal = val
|
|
|
|
},
|
2022-11-26 23:25:14 +01:00
|
|
|
setShowPlaylistsModal(state, val) {
|
|
|
|
state.showPlaylistsModal = val
|
|
|
|
},
|
2022-11-27 18:53:48 +01:00
|
|
|
setShowEditPlaylistModal(state, val) {
|
|
|
|
state.showEditPlaylistModal = val
|
|
|
|
},
|
2022-04-23 02:31:11 +02:00
|
|
|
setShowEditPodcastEpisodeModal(state, val) {
|
|
|
|
state.showEditPodcastEpisode = val
|
|
|
|
},
|
2022-05-28 18:38:51 +02:00
|
|
|
setShowViewPodcastEpisodeModal(state, val) {
|
|
|
|
state.showViewPodcastEpisodeModal = val
|
|
|
|
},
|
2022-12-31 22:26:37 +01:00
|
|
|
setShowRSSFeedOpenCloseModal(state, val) {
|
|
|
|
state.showRSSFeedOpenCloseModal = val
|
|
|
|
},
|
|
|
|
setRSSFeedOpenCloseModal(state, entity) {
|
|
|
|
state.rssFeedEntity = entity
|
|
|
|
state.showRSSFeedOpenCloseModal = true
|
|
|
|
},
|
2022-07-30 18:36:04 +02:00
|
|
|
setShowConfirmPrompt(state, val) {
|
|
|
|
state.showConfirmPrompt = val
|
|
|
|
},
|
|
|
|
setConfirmPrompt(state, options) {
|
|
|
|
state.confirmPromptOptions = options
|
|
|
|
state.showConfirmPrompt = true
|
|
|
|
},
|
2021-11-07 02:31:46 +01:00
|
|
|
setEditCollection(state, collection) {
|
|
|
|
state.selectedCollection = collection
|
|
|
|
state.showEditCollectionModal = true
|
2021-11-28 03:11:35 +01:00
|
|
|
},
|
2022-11-27 18:53:48 +01:00
|
|
|
setEditPlaylist(state, playlist) {
|
|
|
|
state.selectedPlaylist = playlist
|
|
|
|
state.showEditPlaylistModal = true
|
|
|
|
},
|
2022-04-23 02:31:11 +02:00
|
|
|
setSelectedEpisode(state, episode) {
|
|
|
|
state.selectedEpisode = episode
|
|
|
|
},
|
2022-11-26 23:25:14 +01:00
|
|
|
setSelectedPlaylistItems(state, items) {
|
|
|
|
state.selectedPlaylistItems = items
|
|
|
|
},
|
2022-05-09 01:21:46 +02:00
|
|
|
showEditAuthorModal(state, author) {
|
|
|
|
state.selectedAuthor = author
|
|
|
|
state.showEditAuthorModal = true
|
|
|
|
},
|
|
|
|
setShowEditAuthorModal(state, val) {
|
|
|
|
state.showEditAuthorModal = val
|
|
|
|
},
|
|
|
|
setSelectedAuthor(state, author) {
|
|
|
|
state.selectedAuthor = author
|
|
|
|
},
|
2022-02-23 00:33:55 +01:00
|
|
|
setChromecastInitialized(state, val) {
|
|
|
|
state.isChromecastInitialized = val
|
|
|
|
},
|
|
|
|
setCasting(state, val) {
|
|
|
|
state.isCasting = val
|
2022-09-19 17:29:24 +02:00
|
|
|
},
|
|
|
|
setShowBatchQuickMatchModal(state, val) {
|
|
|
|
state.showBatchQuickMatchModal = val
|
2022-12-01 00:09:00 +01:00
|
|
|
},
|
|
|
|
resetSelectedMediaItems(state) {
|
|
|
|
state.selectedMediaItems = []
|
|
|
|
},
|
|
|
|
toggleMediaItemSelected(state, item) {
|
|
|
|
if (state.selectedMediaItems.some(i => i.id === item.id)) {
|
|
|
|
state.selectedMediaItems = state.selectedMediaItems.filter(i => i.id !== item.id)
|
|
|
|
} else {
|
|
|
|
state.selectedMediaItems.push(item)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
setMediaItemSelected(state, { item, selected }) {
|
2022-12-02 00:39:23 +01:00
|
|
|
const isAlreadySelected = state.selectedMediaItems.some(i => i.id === item.id)
|
|
|
|
if (isAlreadySelected && !selected) {
|
2022-12-01 00:09:00 +01:00
|
|
|
state.selectedMediaItems = state.selectedMediaItems.filter(i => i.id !== item.id)
|
2022-12-02 00:39:23 +01:00
|
|
|
|
|
|
|
} else if (selected && !isAlreadySelected) {
|
|
|
|
state.selectedMediaItems.push(item)
|
2022-12-01 00:09:00 +01:00
|
|
|
}
|
2021-11-06 02:24:02 +01:00
|
|
|
}
|
2023-02-22 19:22:52 +01:00
|
|
|
}
|