2020-03-27 02:50:02 +00:00
|
|
|
import electron from 'electron'
|
2020-02-16 18:30:00 +00:00
|
|
|
import Datastore from 'nedb'
|
2020-03-27 02:50:02 +00:00
|
|
|
// TODO: Add logic for database when electron is not in use
|
|
|
|
const localDataStorage = electron.remote.app.getPath('userData')
|
2020-02-16 18:30:00 +00:00
|
|
|
|
|
|
|
const subDb = new Datastore({
|
|
|
|
filename: localDataStorage + '/subscriptions.db',
|
|
|
|
autoload: true
|
|
|
|
})
|
|
|
|
|
|
|
|
const state = {
|
|
|
|
subscriptions: []
|
|
|
|
}
|
|
|
|
|
|
|
|
const mutations = {
|
|
|
|
addSubscription (state, payload) {
|
|
|
|
state.subscriptions.push(payload)
|
|
|
|
},
|
|
|
|
setSubscriptions (state, payload) {
|
|
|
|
state.subscriptions = payload
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const actions = {
|
|
|
|
addSubscriptions ({ commit }, payload) {
|
|
|
|
subDb.insert(payload, (err, payload) => {
|
|
|
|
if (!err) {
|
|
|
|
commit('addSubscription', payload)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
getSubscriptions ({ commit }, payload) {
|
|
|
|
subDb.find({}, (err, payload) => {
|
|
|
|
if (!err) {
|
|
|
|
commit('setSubscriptions', payload)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
removeSubscription ({ commit }, channelId) {
|
|
|
|
subDb.remove({ channelId: channelId }, {}, () => {
|
|
|
|
commit('setSubscriptions', this.state.subscriptions.filter(sub => sub.channelId !== channelId))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const getters = {}
|
|
|
|
export default {
|
|
|
|
state,
|
|
|
|
getters,
|
|
|
|
actions,
|
|
|
|
mutations
|
|
|
|
}
|