Skip to content

Commit

Permalink
dix: Populate photosLocationFolder on init
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge committed Jul 3, 2024
1 parent 4f30505 commit ca99130
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,18 @@ import folders from './folders.js'
import systemtags from './systemtags.js'
import userConfig, { getFolder } from './userConfig.js'

/**
* Get the information of photosLocation and store it as photosLocationFolder
* @param store
* @param state
*/
async function initPhotosLocationFolder(store, state) {
const photosLocationFolder = await getFolder(state.userConfig.photosLocation)
store.commit('updateUserConfig', { key: 'photosLocationFolder', value: photosLocationFolder })
}

Vue.use(Vuex)
export default new Store({
const photosStore = new Store({
modules: {
files,
folders,
Expand All @@ -34,14 +44,17 @@ export default new Store({

plugins: [
(store) => {
initPhotosLocationFolder(store, store.state)

store.subscribe(async (mutation, state) => {
if (mutation.type === 'updateUserConfig' && mutation.payload.key === 'photosLocation') {
const photosLocationFolder = await getFolder(state.userConfig.photosLocation)
store.commit('updateUserConfig', { key: 'photosLocationFolder', value: photosLocationFolder })
initPhotosLocationFolder(store, state)
}
})
},
],

strict: process.env.NODE_ENV !== 'production',
})

export default photosStore

0 comments on commit ca99130

Please sign in to comment.