2021-10-16 15:51:27 +00:00
|
|
|
import {createStore} from 'vuex'
|
2020-11-01 17:36:00 +00:00
|
|
|
import {
|
2021-10-16 15:51:27 +00:00
|
|
|
BACKGROUND,
|
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,
|
2021-05-30 18:30:08 +00:00
|
|
|
ONLINE, 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
|
|
|
|
2020-05-31 19:17:10 +00:00
|
|
|
import ListService from '../services/list'
|
2021-10-31 20:04:00 +00:00
|
|
|
import {checkAndSetApiUrl} from '../helpers/checkAndSetApiUrl'
|
2020-09-05 20:35:52 +00:00
|
|
|
|
2021-08-20 13:32:53 +00:00
|
|
|
export const store = createStore({
|
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
|
|
|
},
|
|
|
|
state: {
|
|
|
|
loading: false,
|
2021-01-09 14:24:06 +00:00
|
|
|
loadingModule: null,
|
2020-05-08 18:43:51 +00:00
|
|
|
online: true,
|
2020-05-08 19:07:33 +00:00
|
|
|
// This is used to highlight the current list in menu for all list related views
|
2020-05-31 19:17:10 +00:00
|
|
|
currentList: {id: 0},
|
|
|
|
background: '',
|
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,
|
2021-10-31 19:42:09 +00:00
|
|
|
vikunjaReady: false,
|
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 18:43:51 +00:00
|
|
|
[ONLINE](state, online) {
|
2021-09-11 15:53:03 +00:00
|
|
|
if (import.meta.env.VITE_IS_ONLINE) {
|
|
|
|
console.log('Setting fake online state', import.meta.env.VITE_IS_ONLINE)
|
|
|
|
}
|
|
|
|
state.online = !!import.meta.env.VITE_IS_ONLINE || online
|
2020-05-08 18:43:51 +00:00
|
|
|
},
|
2020-05-08 19:07:33 +00:00
|
|
|
[CURRENT_LIST](state, currentList) {
|
2021-10-17 13:16:26 +00: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 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
|
|
|
|
},
|
2021-10-31 19:42:09 +00:00
|
|
|
vikunjaReady(state, ready) {
|
|
|
|
state.vikunjaReady = ready
|
2021-10-31 21:01:33 +00:00
|
|
|
},
|
2021-10-16 15:51:27 +00:00
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
async [CURRENT_LIST]({state, commit}, currentList) {
|
2020-07-07 20:07:13 +00:00
|
|
|
|
2021-05-30 18:30:08 +00:00
|
|
|
if (currentList === null) {
|
2021-10-16 15:51:27 +00:00
|
|
|
commit(CURRENT_LIST, {})
|
|
|
|
commit(BACKGROUND, null)
|
2021-05-30 18:30:08 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-05-31 19:17:10 +00:00
|
|
|
// Not sure if this is the right way to do it but hey, it works
|
|
|
|
if (
|
2020-05-31 19:38:07 +00:00
|
|
|
// List changed
|
2020-05-31 19:17:10 +00:00
|
|
|
currentList.id !== state.currentList.id ||
|
2020-05-31 19:38:07 +00: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 19:17:10 +00:00
|
|
|
(
|
|
|
|
currentList.backgroundInformation &&
|
|
|
|
currentList.backgroundInformation.unsplashId &&
|
2020-05-31 19:38:07 +00:00
|
|
|
state.currentList &&
|
|
|
|
state.currentList.backgroundInformation &&
|
|
|
|
state.currentList.backgroundInformation.unsplashId &&
|
2020-05-31 19:17:10 +00:00
|
|
|
currentList.backgroundInformation.unsplashId !== state.currentList.backgroundInformation.unsplashId
|
2020-06-11 17:27:21 +00: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 19:17:10 +00:00
|
|
|
)
|
|
|
|
) {
|
|
|
|
if (currentList.backgroundInformation) {
|
2021-10-16 15:51:27 +00:00
|
|
|
try {
|
|
|
|
const listService = new ListService()
|
|
|
|
const background = await listService.background(currentList)
|
|
|
|
commit(BACKGROUND, background)
|
|
|
|
} catch(e) {
|
|
|
|
console.error('Error getting background image for list', currentList.id, e)
|
|
|
|
}
|
2020-05-31 19:17:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-21 17:11:24 +00:00
|
|
|
if (typeof currentList.backgroundInformation === 'undefined' || currentList.backgroundInformation === null) {
|
2021-10-16 15:51:27 +00:00
|
|
|
commit(BACKGROUND, null)
|
2021-03-21 17:11:24 +00:00
|
|
|
}
|
|
|
|
|
2021-10-16 15:51:27 +00:00
|
|
|
commit(CURRENT_LIST, currentList)
|
2021-05-30 18:30:08 +00:00
|
|
|
},
|
2021-10-31 19:42:09 +00:00
|
|
|
async loadApp({commit, dispatch}) {
|
2021-10-31 20:04:00 +00:00
|
|
|
await checkAndSetApiUrl(window.API_URL, () => dispatch('config/update'))
|
2021-10-31 19:42:09 +00:00
|
|
|
await dispatch('auth/checkAuth')
|
|
|
|
commit('vikunjaReady', true)
|
|
|
|
},
|
2020-05-08 18:43:51 +00:00
|
|
|
},
|
2021-07-09 08:22:20 +00:00
|
|
|
})
|