export default {
  setAppTask: ({
    commit
  }, task) => {
    commit('setAppTask', task)
  },

  dismissSnackbar: ({
    commit
  }) => {
    commit('dismissSnackbar')
  },

  activateSnackbar: ({
    commit
  }, payload) => {
    commit('activateSnackbar', payload)
  },

  synchroniseAnnotationAndOSDCanvas: ({
    commit,
    rootState
  }) => {
    commit('synchroniseAnnotationAndOSDCanvas', rootState.image.OSDviewer)
  },

  setActiveStepAndLayer: ({
    dispatch
  }, index) => {
    dispatch('setActiveLayer', index)
    dispatch('setActiveStep', index)
  },

  setActiveStep: ({
    commit,
    dispatch
  }, step) => {
    if (typeof step.specificLayer === 'number') {
      dispatch('annotation/setActiveLayer', (step.specificLayer), {
        root: true
      })
    }
    commit('setActiveStep', (step.id - 1))
  },

  setActiveLayer: ({
    commit
  }, layerIndex) => {
    commit('setActiveLayer', layerIndex)
  },

  toggleSettings: ({
    commit
  }) => {
    commit('toggleSettings')
  },

  setActiveValidationIndex: ({
    commit
  }, payload) => {
    commit('setActiveValidationIndex', payload)
  },

  setupForValidation: ({
    commit
  }) => {
    commit('setupForValidation')
  },

  loadProject: async ({
    dispatch
  }) => {
    const getAnnotation = dispatch('backend/getAnnotation', null, { root: true })
    const setOSDImageSource = dispatch('backend/setOSDImageSource', null, { root: true })
    await Promise.all([getAnnotation, setOSDImageSource])
    dispatch('synchroniseAnnotationAndOSDCanvas')
  },

  toggleToolsDrawer: ({
    commit
  }) => {
    commit('toggleToolsDrawer')
  },

  setToolsDrawerState: ({
    commit
  }, payload) => {
    commit('setToolsDrawerState', payload)
  },

  toggleStudioDrawer: ({
    commit
  }) => {
    commit('toggleStudioDrawer')
  },

  setStudioDrawerState: ({
    commit
  }, payload) => {
    commit('setStudioDrawerState', payload)
  },

  createNewItem: ({
    state,
    rootState,
    commit
  }, payload) => {
    payload['studyName'] = state.studyName
    payload['imageName'] = rootState.image.imageName
    commit('createNewItem', payload)
  }
}

@@ -1260,29 +1260,63 @@
     
-const getAnnotation =
+await dispatch('synchroniseAnnotationAndOSDCanvas')%0A   
  dis
@@ -1375,34 +1375,8 @@
 %0A   
- const setOSDImageSource =
  dis
@@ -1436,116 +1436,8 @@
  %7D)%0A
-    await Promise.all(%5BgetAnnotation, setOSDImageSource%5D)%0A    dispatch('synchroniseAnnotationAndOSDCanvas')%0A
   %7D,

add canvas synchronise event handlers before adding images and annotations