2022-07-21 16:45:58 +00:00
|
|
|
import type {InjectionKey} from 'vue'
|
|
|
|
import {createStore, useStore as baseUseStore, Store} from 'vuex'
|
|
|
|
|
2022-04-02 15:05:30 +00:00
|
|
|
import {getBlobFromBlurHash} from '../helpers/getBlobFromBlurHash'
|
2020-11-01 17:36:00 +00:00
|
|
|
import {
|
2021-10-16 15:51:27 +00:00
|
|
|
BACKGROUND,
|
2022-04-02 15:05:30 +00:00
|
|
|
BLUR_HASH,
|
2020-11-01 17:36:00 +00:00
|
|
|
CURRENT_LIST,
|
|
|
|
HAS_TASKS,
|
|
|
|
KEYBOARD_SHORTCUTS_ACTIVE,
|
|
|
|
LOADING,
|
2021-01-09 14:24:06 +00:00
|
|
|
LOADING_MODULE,
|
2020-11-01 17:36:00 +00:00
|
|
|
MENU_ACTIVE,
|
2022-01-01 12:43:24 +00:00
|
|
|
QUICK_ACTIONS_ACTIVE,
|
2020-11-01 17:36:00 +00:00
|
|
|
} from './mutation-types'
|
2020-05-08 18:43:51 +00:00
|
|
|
import config from './modules/config'
|
|
|
|
import auth from './modules/auth'
|
|
|
|
import namespaces from './modules/namespaces'
|
2020-05-09 17:00:54 +00:00
|
|
|
import kanban from './modules/kanban'
|
|
|
|
import tasks from './modules/tasks'
|
2020-05-11 14:52:58 +00:00
|
|
|
import lists from './modules/lists'
|
2020-07-14 19:26:05 +00:00
|
|
|
import attachments from './modules/attachments'
|
2021-06-03 20:23:04 +00:00
|
|
|
import labels from './modules/labels'
|
2020-07-14 19:26:05 +00:00
|
|
|
|
2022-01-30 15:47:23 +00:00
|
|
|
import ListModel from '@/models/list'
|
|
|
|
|
2020-05-31 19:17:10 +00:00
|
|
|
import ListService from '../services/list'
|
2021-11-13 19:49:02 +00:00
|
|
|
import {checkAndSetApiUrl} from '@/helpers/checkAndSetApiUrl'
|
2020-09-05 20:35:52 +00:00
|
|
|
|
2022-07-21 16:45:58 +00:00
|
|
|
import type { RootStoreState, StoreState } from './types'
|
|
|
|
|
|
|
|
export const key: InjectionKey<Store<StoreState>> = Symbol()
|
|
|
|
|
|
|
|
// define your own `useStore` composition function
|
|
|
|
export function useStore () {
|
|
|
|
return baseUseStore(key)
|
|
|
|
}
|
2022-07-20 22:42:36 +00:00
|
|
|
|
|
|
|
export const store = createStore<RootStoreState>({
|
2021-08-23 19:24:52 +00:00
|
|
|
strict: import.meta.env.DEV,
|
2020-05-08 18:43:51 +00:00
|
|
|
modules: {
|
|
|
|
config,
|
|
|
|
auth,
|
|
|
|
namespaces,
|
2020-05-09 17:00:54 +00:00
|
|
|
kanban,
|
|
|
|
tasks,
|
2020-05-11 14:52:58 +00:00
|
|
|
lists,
|
2020-07-14 19:26:05 +00:00
|
|
|
attachments,
|
2021-06-03 20:23:04 +00:00
|
|
|
labels,
|
2020-05-08 18:43:51 +00:00
|
|
|
},
|
2022-07-20 22:42:36 +00:00
|
|
|
state: () => ({
|
2020-05-08 18:43:51 +00:00
|
|
|
loading: false,
|
2021-01-09 14:24:06 +00:00
|
|
|
loadingModule: null,
|
2020-05-08 19:07:33 +00:00
|
|
|
// This is used to highlight the current list in menu for all list related views
|
2022-01-30 15:47:23 +00:00
|
|
|
currentList: new ListModel({
|
2022-01-30 13:05:39 +00:00
|
|
|
id: 0,
|
|
|
|
isArchived: false,
|
2022-01-30 15:47:23 +00:00
|
|
|
}),
|
2020-05-31 19:17:10 +00:00
|
|
|
background: '',
|
2022-04-02 15:05:30 +00:00
|
|
|
blurHash: '',
|
2020-06-15 16:47:17 +00:00
|
|
|
hasTasks: false,
|
2020-11-01 17:36:00 +00:00
|
|
|
menuActive: true,
|
|
|
|
keyboardShortcutsActive: false,
|
2021-05-30 18:30:08 +00:00
|
|
|
quickActionsActive: false,
|
2022-07-20 22:42:36 +00:00
|
|
|
}),
|
2020-05-08 18:43:51 +00:00
|
|
|
mutations: {
|
|
|
|
[LOADING](state, loading) {
|
|
|
|
state.loading = loading
|
|
|
|
},
|
2021-01-09 14:24:06 +00:00
|
|
|
[LOADING_MODULE](state, module) {
|
|
|
|
state.loadingModule = module
|
|
|
|
},
|
2020-05-08 19:07:33 +00:00
|
|
|
[CURRENT_LIST](state, currentList) {
|
2022-06-30 16:04:41 +00:00
|
|
|
// Server updates don't return the right. Therefore, the right is reset after updating the list which is
|
2021-10-17 13:16:26 +00:00
|
|
|
// 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 15:51:27 +00: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 15:05:30 +00:00
|
|
|
[BLUR_HASH](state, blurHash) {
|
|
|
|
state.blurHash = blurHash
|
|
|
|
},
|
2021-10-16 15:51:27 +00:00
|
|
|
},
|
|
|
|
actions: {
|
2022-04-03 12:20:16 +00:00
|
|
|
async [CURRENT_LIST]({state, commit}, {list, forceUpdate = false}) {
|
2020-07-07 20:07:13 +00:00
|
|
|
|
2022-04-03 12:20:16 +00:00
|
|
|
if (list === null) {
|
2021-10-16 15:51:27 +00:00
|
|
|
commit(CURRENT_LIST, {})
|
|
|
|
commit(BACKGROUND, null)
|
2022-04-02 15:05:30 +00:00
|
|
|
commit(BLUR_HASH, null)
|
2021-05-30 18:30:08 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-04-03 12:20:16 +00: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 15:51:27 +00:00
|
|
|
try {
|
2022-04-03 12:20:16 +00:00
|
|
|
const blurHash = await getBlobFromBlurHash(list.backgroundBlurHash)
|
2022-04-02 15:05:30 +00:00
|
|
|
if (blurHash) {
|
|
|
|
commit(BLUR_HASH, window.URL.createObjectURL(blurHash))
|
|
|
|
}
|
|
|
|
|
2021-10-16 15:51:27 +00:00
|
|
|
const listService = new ListService()
|
2022-04-03 12:20:16 +00:00
|
|
|
const background = await listService.background(list)
|
2021-10-16 15:51:27 +00:00
|
|
|
commit(BACKGROUND, background)
|
2022-04-02 15:05:30 +00:00
|
|
|
} catch (e) {
|
2022-04-03 12:20:16 +00:00
|
|
|
console.error('Error getting background image for list', list.id, e)
|
2021-10-16 15:51:27 +00:00
|
|
|
}
|
2020-05-31 19:17:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-03 12:20:16 +00:00
|
|
|
if (typeof list.backgroundInformation === 'undefined' || list.backgroundInformation === null) {
|
2021-10-16 15:51:27 +00:00
|
|
|
commit(BACKGROUND, null)
|
2022-04-02 15:05:30 +00:00
|
|
|
commit(BLUR_HASH, null)
|
2021-03-21 17:11:24 +00:00
|
|
|
}
|
|
|
|
|
2022-04-03 12:20:16 +00:00
|
|
|
commit(CURRENT_LIST, list)
|
2021-05-30 18:30:08 +00:00
|
|
|
},
|
2022-01-08 14:44:33 +00:00
|
|
|
async loadApp({dispatch}) {
|
2021-11-13 19:49:02 +00:00
|
|
|
await checkAndSetApiUrl(window.API_URL)
|
|
|
|
await dispatch('auth/checkAuth')
|
|
|
|
},
|
2020-05-08 18:43:51 +00:00
|
|
|
},
|
2021-07-09 08:22:20 +00:00
|
|
|
})
|