2020-05-08 20:43:51 +02:00
|
|
|
import Vue from 'vue'
|
|
|
|
import Vuex from 'vuex'
|
2020-05-31 21:17:10 +02:00
|
|
|
|
2020-05-08 20:43:51 +02:00
|
|
|
Vue.use(Vuex)
|
|
|
|
|
2020-05-11 16:52:58 +02:00
|
|
|
import {CURRENT_LIST, ERROR_MESSAGE, IS_FULLPAGE, LOADING, ONLINE} from './mutation-types'
|
2020-05-08 20:43:51 +02:00
|
|
|
import config from './modules/config'
|
|
|
|
import auth from './modules/auth'
|
|
|
|
import namespaces from './modules/namespaces'
|
2020-05-09 19:00:54 +02:00
|
|
|
import kanban from './modules/kanban'
|
|
|
|
import tasks from './modules/tasks'
|
2020-05-11 16:52:58 +02:00
|
|
|
import lists from './modules/lists'
|
2020-05-31 21:17:10 +02:00
|
|
|
import ListService from '../services/list'
|
2020-05-08 20:43:51 +02:00
|
|
|
|
|
|
|
export const store = new Vuex.Store({
|
|
|
|
modules: {
|
|
|
|
config,
|
|
|
|
auth,
|
|
|
|
namespaces,
|
2020-05-09 19:00:54 +02:00
|
|
|
kanban,
|
|
|
|
tasks,
|
2020-05-11 16:52:58 +02:00
|
|
|
lists,
|
2020-05-08 20:43:51 +02:00
|
|
|
},
|
|
|
|
state: {
|
|
|
|
loading: false,
|
|
|
|
errorMessage: '',
|
|
|
|
online: true,
|
|
|
|
isFullpage: false,
|
2020-05-08 21:07:33 +02:00
|
|
|
// This is used to highlight the current list in menu for all list related views
|
2020-05-31 21:17:10 +02:00
|
|
|
currentList: {id: 0},
|
|
|
|
background: '',
|
2020-05-08 20:43:51 +02:00
|
|
|
},
|
|
|
|
mutations: {
|
|
|
|
[LOADING](state, loading) {
|
|
|
|
state.loading = loading
|
|
|
|
},
|
|
|
|
[ERROR_MESSAGE](state, error) {
|
|
|
|
state.errorMessage = error
|
|
|
|
},
|
|
|
|
[ONLINE](state, online) {
|
|
|
|
state.online = online
|
|
|
|
},
|
|
|
|
[IS_FULLPAGE](state, fullpage) {
|
|
|
|
state.isFullpage = fullpage
|
2020-05-08 21:07:33 +02:00
|
|
|
},
|
|
|
|
[CURRENT_LIST](state, currentList) {
|
2020-05-31 21:17:10 +02:00
|
|
|
// Not sure if this is the right way to do it but hey, it works
|
|
|
|
if (
|
2020-05-31 21:38:07 +02:00
|
|
|
// List changed
|
2020-05-31 21:17:10 +02:00
|
|
|
currentList.id !== state.currentList.id ||
|
2020-05-31 21:38:07 +02:00
|
|
|
// The current list got a new background and didn't have one previously
|
|
|
|
(
|
|
|
|
currentList.backgroundInformation &&
|
|
|
|
!state.currentList.backgroundInformation
|
|
|
|
) ||
|
|
|
|
// The current list got a new background and had one previously
|
2020-05-31 21:17:10 +02:00
|
|
|
(
|
|
|
|
currentList.backgroundInformation &&
|
|
|
|
currentList.backgroundInformation.unsplashId &&
|
2020-05-31 21:38:07 +02:00
|
|
|
state.currentList &&
|
|
|
|
state.currentList.backgroundInformation &&
|
|
|
|
state.currentList.backgroundInformation.unsplashId &&
|
2020-05-31 21:17:10 +02:00
|
|
|
currentList.backgroundInformation.unsplashId !== state.currentList.backgroundInformation.unsplashId
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
if (currentList.backgroundInformation) {
|
|
|
|
const listService = new ListService()
|
|
|
|
listService.background(currentList)
|
|
|
|
.then(b => {
|
|
|
|
state.background = b
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
console.error('Error getting background image for list', currentList.id, e)
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
state.background = null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-08 21:07:33 +02:00
|
|
|
state.currentList = currentList
|
|
|
|
},
|
2020-05-08 20:43:51 +02:00
|
|
|
},
|
|
|
|
})
|