2020-05-08 20:43:51 +02:00
|
|
|
import Vue from 'vue'
|
|
|
|
import Vuex from 'vuex'
|
2020-11-01 18:36:00 +01:00
|
|
|
import {
|
|
|
|
CURRENT_LIST,
|
|
|
|
ERROR_MESSAGE,
|
|
|
|
HAS_TASKS,
|
|
|
|
KEYBOARD_SHORTCUTS_ACTIVE,
|
|
|
|
LOADING,
|
2021-01-09 15:24:06 +01:00
|
|
|
LOADING_MODULE,
|
2020-11-01 18:36:00 +01:00
|
|
|
MENU_ACTIVE,
|
2021-05-30 20:30:08 +02:00
|
|
|
ONLINE, QUICK_ACTIONS_ACTIVE,
|
2020-11-01 18:36:00 +01:00
|
|
|
} 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-07-14 21:26:05 +02:00
|
|
|
import attachments from './modules/attachments'
|
2021-06-03 22:23:04 +02:00
|
|
|
import labels from './modules/labels'
|
2020-07-14 21:26:05 +02:00
|
|
|
|
2020-05-31 21:17:10 +02:00
|
|
|
import ListService from '../services/list'
|
2020-09-05 22:35:52 +02:00
|
|
|
|
|
|
|
Vue.use(Vuex)
|
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-07-14 21:26:05 +02:00
|
|
|
attachments,
|
2021-06-03 22:23:04 +02:00
|
|
|
labels,
|
2020-05-08 20:43:51 +02:00
|
|
|
},
|
|
|
|
state: {
|
|
|
|
loading: false,
|
2021-01-09 15:24:06 +01:00
|
|
|
loadingModule: null,
|
2020-05-08 20:43:51 +02:00
|
|
|
errorMessage: '',
|
|
|
|
online: true,
|
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-06-15 18:47:17 +02:00
|
|
|
hasTasks: false,
|
2020-11-01 18:36:00 +01:00
|
|
|
menuActive: true,
|
|
|
|
keyboardShortcutsActive: false,
|
2021-05-30 20:30:08 +02:00
|
|
|
quickActionsActive: false,
|
2020-05-08 20:43:51 +02:00
|
|
|
},
|
|
|
|
mutations: {
|
|
|
|
[LOADING](state, loading) {
|
|
|
|
state.loading = loading
|
|
|
|
},
|
2021-01-09 15:24:06 +01:00
|
|
|
[LOADING_MODULE](state, module) {
|
|
|
|
state.loadingModule = module
|
|
|
|
},
|
2020-05-08 20:43:51 +02:00
|
|
|
[ERROR_MESSAGE](state, error) {
|
|
|
|
state.errorMessage = error
|
|
|
|
},
|
|
|
|
[ONLINE](state, online) {
|
|
|
|
state.online = online
|
|
|
|
},
|
2020-05-08 21:07:33 +02:00
|
|
|
[CURRENT_LIST](state, currentList) {
|
2020-07-07 22:07:13 +02:00
|
|
|
|
2021-05-30 20:30:08 +02:00
|
|
|
if (currentList === null) {
|
|
|
|
state.currentList = {}
|
|
|
|
state.background = null
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
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
|
2020-06-11 19:27:21 +02:00
|
|
|
) ||
|
|
|
|
// The new list has a background which is not an unsplash one and did not have one previously
|
|
|
|
(
|
|
|
|
currentList.backgroundInformation &&
|
|
|
|
currentList.backgroundInformation.type &&
|
|
|
|
state.currentList &&
|
|
|
|
state.currentList.backgroundInformation &&
|
|
|
|
state.currentList.backgroundInformation.type
|
2020-05-31 21:17:10 +02:00
|
|
|
)
|
|
|
|
) {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-21 18:11:24 +01:00
|
|
|
if (typeof currentList.backgroundInformation === 'undefined' || currentList.backgroundInformation === null) {
|
|
|
|
state.background = null
|
|
|
|
}
|
|
|
|
|
2021-01-09 15:09:26 +01:00
|
|
|
// Server updates don't return the right. Therefore the right is reset after updating the list which is
|
|
|
|
// confusing because all the buttons will disappear in that case. To prevent this, we're keeping the right
|
|
|
|
// when updating the list in global state.
|
2021-07-10 12:45:36 +02:00
|
|
|
if (typeof state.currentList.maxRight !== 'undefined' && (typeof currentList.maxRight === 'undefined' || currentList.maxRight === null)) {
|
2021-01-09 15:09:26 +01:00
|
|
|
currentList.maxRight = state.currentList.maxRight
|
|
|
|
}
|
2020-05-08 21:07:33 +02:00
|
|
|
state.currentList = currentList
|
|
|
|
},
|
2020-06-15 18:47:17 +02:00
|
|
|
[HAS_TASKS](state, hasTasks) {
|
|
|
|
state.hasTasks = hasTasks
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
2020-11-01 18:36:00 +01:00
|
|
|
[MENU_ACTIVE](state, menuActive) {
|
|
|
|
state.menuActive = menuActive
|
|
|
|
},
|
|
|
|
toggleMenu(state) {
|
|
|
|
state.menuActive = !state.menuActive
|
|
|
|
},
|
|
|
|
[KEYBOARD_SHORTCUTS_ACTIVE](state, active) {
|
|
|
|
state.keyboardShortcutsActive = active
|
|
|
|
},
|
2021-05-30 20:30:08 +02:00
|
|
|
[QUICK_ACTIONS_ACTIVE](state, active) {
|
|
|
|
state.quickActionsActive = active
|
|
|
|
},
|
2020-05-08 20:43:51 +02:00
|
|
|
},
|
2021-07-09 10:22:20 +02:00
|
|
|
})
|