2021-10-16 17:51:27 +02:00
|
|
|
import {createStore} from 'vuex'
|
2022-04-02 17:05:30 +02:00
|
|
|
import {getBlobFromBlurHash} from '../helpers/getBlobFromBlurHash'
|
2020-11-01 18:36:00 +01:00
|
|
|
import {
|
2021-10-16 17:51:27 +02:00
|
|
|
BACKGROUND,
|
2022-04-02 17:05:30 +02:00
|
|
|
BLUR_HASH,
|
2020-11-01 18:36:00 +01:00
|
|
|
CURRENT_LIST,
|
|
|
|
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,
|
2022-01-01 13:43:24 +01:00
|
|
|
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
|
|
|
|
2022-01-30 16:47:23 +01:00
|
|
|
import ListModel from '@/models/list'
|
|
|
|
|
2020-05-31 21:17:10 +02:00
|
|
|
import ListService from '../services/list'
|
2021-11-13 20:49:02 +01:00
|
|
|
import {checkAndSetApiUrl} from '@/helpers/checkAndSetApiUrl'
|
2020-09-05 22:35:52 +02:00
|
|
|
|
2021-08-20 15:32:53 +02:00
|
|
|
export const store = createStore({
|
2021-08-23 21:24:52 +02:00
|
|
|
strict: import.meta.env.DEV,
|
2020-05-08 20:43:51 +02:00
|
|
|
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 21:07:33 +02:00
|
|
|
// This is used to highlight the current list in menu for all list related views
|
2022-01-30 16:47:23 +01:00
|
|
|
currentList: new ListModel({
|
2022-01-30 14:05:39 +01:00
|
|
|
id: 0,
|
|
|
|
isArchived: false,
|
2022-01-30 16:47:23 +01:00
|
|
|
}),
|
2020-05-31 21:17:10 +02:00
|
|
|
background: '',
|
2022-04-02 17:05:30 +02:00
|
|
|
blurHash: '',
|
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,
|
2022-04-02 17:05:30 +02:00
|
|
|
modalActive: 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 21:07:33 +02:00
|
|
|
[CURRENT_LIST](state, currentList) {
|
2021-10-17 15:16:26 +02: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.
|
|
|
|
if (typeof state.currentList.maxRight !== 'undefined' && (typeof currentList.maxRight === 'undefined' || currentList.maxRight === null)) {
|
|
|
|
currentList.maxRight = state.currentList.maxRight
|
|
|
|
}
|
2021-10-16 17:51:27 +02:00
|
|
|
state.currentList = currentList
|
|
|
|
},
|
|
|
|
[HAS_TASKS](state, hasTasks) {
|
|
|
|
state.hasTasks = hasTasks
|
|
|
|
},
|
|
|
|
[MENU_ACTIVE](state, menuActive) {
|
|
|
|
state.menuActive = menuActive
|
|
|
|
},
|
|
|
|
toggleMenu(state) {
|
|
|
|
state.menuActive = !state.menuActive
|
|
|
|
},
|
|
|
|
[KEYBOARD_SHORTCUTS_ACTIVE](state, active) {
|
|
|
|
state.keyboardShortcutsActive = active
|
|
|
|
},
|
|
|
|
[QUICK_ACTIONS_ACTIVE](state, active) {
|
|
|
|
state.quickActionsActive = active
|
|
|
|
},
|
|
|
|
[BACKGROUND](state, background) {
|
|
|
|
state.background = background
|
|
|
|
},
|
2022-04-02 17:05:30 +02:00
|
|
|
[BLUR_HASH](state, blurHash) {
|
|
|
|
state.blurHash = blurHash
|
|
|
|
},
|
|
|
|
modalActive(state, active) {
|
|
|
|
state.modalActive = active
|
|
|
|
},
|
2021-10-16 17:51:27 +02:00
|
|
|
},
|
|
|
|
actions: {
|
2022-04-03 14:20:16 +02:00
|
|
|
async [CURRENT_LIST]({state, commit}, {list, forceUpdate = false}) {
|
2020-07-07 22:07:13 +02:00
|
|
|
|
2022-04-03 14:20:16 +02:00
|
|
|
if (list === null) {
|
2021-10-16 17:51:27 +02:00
|
|
|
commit(CURRENT_LIST, {})
|
|
|
|
commit(BACKGROUND, null)
|
2022-04-02 17:05:30 +02:00
|
|
|
commit(BLUR_HASH, null)
|
2021-05-30 20:30:08 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-04-03 14:20:16 +02:00
|
|
|
// The forceUpdate parameter is used only when updating a list background directly because in that case
|
|
|
|
// the current list stays the same, but we want to show the new background right away.
|
|
|
|
if (list.id !== state.currentList.id || forceUpdate) {
|
|
|
|
if (list.backgroundInformation) {
|
2021-10-16 17:51:27 +02:00
|
|
|
try {
|
2022-04-03 14:20:16 +02:00
|
|
|
const blurHash = await getBlobFromBlurHash(list.backgroundBlurHash)
|
2022-04-02 17:05:30 +02:00
|
|
|
if (blurHash) {
|
|
|
|
commit(BLUR_HASH, window.URL.createObjectURL(blurHash))
|
|
|
|
}
|
|
|
|
|
2021-10-16 17:51:27 +02:00
|
|
|
const listService = new ListService()
|
2022-04-03 14:20:16 +02:00
|
|
|
const background = await listService.background(list)
|
2021-10-16 17:51:27 +02:00
|
|
|
commit(BACKGROUND, background)
|
2022-04-02 17:05:30 +02:00
|
|
|
} catch (e) {
|
2022-04-03 14:20:16 +02:00
|
|
|
console.error('Error getting background image for list', list.id, e)
|
2021-10-16 17:51:27 +02:00
|
|
|
}
|
2020-05-31 21:17:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-03 14:20:16 +02:00
|
|
|
if (typeof list.backgroundInformation === 'undefined' || list.backgroundInformation === null) {
|
2021-10-16 17:51:27 +02:00
|
|
|
commit(BACKGROUND, null)
|
2022-04-02 17:05:30 +02:00
|
|
|
commit(BLUR_HASH, null)
|
2021-03-21 18:11:24 +01:00
|
|
|
}
|
|
|
|
|
2022-04-03 14:20:16 +02:00
|
|
|
commit(CURRENT_LIST, list)
|
2021-05-30 20:30:08 +02:00
|
|
|
},
|
2022-01-08 15:44:33 +01:00
|
|
|
async loadApp({dispatch}) {
|
2021-11-13 20:49:02 +01:00
|
|
|
await checkAndSetApiUrl(window.API_URL)
|
|
|
|
await dispatch('auth/checkAuth')
|
|
|
|
},
|
2020-05-08 20:43:51 +02:00
|
|
|
},
|
2021-07-09 10:22:20 +02:00
|
|
|
})
|