This commit is contained in:
advplyr 2021-08-17 17:01:11 -05:00
commit 6930e69b55
106 changed files with 26925 additions and 0 deletions

View file

@ -0,0 +1,67 @@
export const state = () => ({
audiobooks: [],
listeners: []
})
export const getters = {
}
export const actions = {
load({ commit }) {
this.$axios
.$get(`/api/audiobooks`)
.then((data) => {
commit('set', data)
})
.catch((error) => {
console.error('Failed', error)
commit('set', [])
})
}
}
export const mutations = {
set(state, audiobooks) {
console.log('Set Audiobooks', audiobooks)
state.audiobooks = audiobooks
state.listeners.forEach((listener) => {
listener.meth()
})
},
addUpdate(state, audiobook) {
var index = state.audiobooks.findIndex(a => a.id === audiobook.id)
if (index >= 0) {
console.log('Audiobook Updated', audiobook)
state.audiobooks.splice(index, 1, audiobook)
} else {
console.log('Audiobook Added', audiobook)
state.audiobooks.push(audiobook)
}
state.listeners.forEach((listener) => {
if (!listener.audiobookId || listener.audiobookId === audiobook.id) {
listener.meth()
}
})
},
remove(state, audiobook) {
console.log('Audiobook removed', audiobook)
state.audiobooks = state.audiobooks.filter(a => a.id !== audiobook.id)
state.listeners.forEach((listener) => {
if (!listener.audiobookId || listener.audiobookId === audiobook.id) {
listener.meth()
}
})
},
addListener(state, listener) {
var index = state.listeners.findIndex(l => l.id === listener.id)
if (index >= 0) state.listeners.splice(index, 1, listener)
else state.listeners.push(listener)
},
removeListener(state, listenerId) {
state.listeners = state.listeners.filter(l => l.id !== listenerId)
}
}

63
client/store/index.js Normal file
View file

@ -0,0 +1,63 @@
export const state = () => ({
user: null,
streamAudiobook: null,
showEditModal: false,
selectedAudiobook: null,
playOnLoad: false,
isScanning: false,
scanProgress: null
})
export const getters = {
getToken: (state) => {
return state.user ? state.user.token : null
},
getUserAudiobook: (state) => (audiobookId) => {
return state.user && state.user.audiobooks ? state.user.audiobooks[audiobookId] || null : null
}
}
export const actions = {
}
export const mutations = {
setUser(state, user) {
state.user = user
console.log('SETUSER', user)
if (user.token) {
localStorage.setItem('token', user.token)
}
},
setStreamAudiobook(state, audiobook) {
state.playOnLoad = true
state.streamAudiobook = audiobook
},
setStream(state, stream) {
state.playOnLoad = false
state.streamAudiobook = stream ? stream.audiobook : null
},
clearStreamAudiobook(state, audiobookId) {
if (state.streamAudiobook && state.streamAudiobook.id === audiobookId) {
state.playOnLoad = false
state.streamAudiobook = null
}
},
setPlayOnLoad(state, val) {
state.playOnLoad = val
},
showEditModal(state, audiobook) {
state.selectedAudiobook = audiobook
state.showEditModal = true
},
setShowEditModal(state, val) {
state.showEditModal = val
},
setIsScanning(state, isScanning) {
state.isScanning = isScanning
},
setScanProgress(state, progress) {
state.scanProgress = progress
}
}