Newer
Older
This file handles actions for the editor redux state
*/
import { AppDispatch, RootState } from './../store'
/** Save competition in editor state from input id */
export const getEditorCompetition = (id: string) => async (dispatch: AppDispatch, getState: () => RootState) => {
.then((res) => {
dispatch({
type: Types.SET_EDITOR_COMPETITION,
if (getState().editor.activeSlideId === -1 && res.data.slides[0]) {
setEditorSlideId(res.data.slides[0].id)(dispatch)
}
const defaultViewType = getState().types.viewTypes.find((viewType) => viewType.name === 'Audience')
if (getState().editor.activeViewTypeId === -1 && defaultViewType) {
setEditorViewId(defaultViewType.id)(dispatch)
}
})
.catch((err) => {
console.log(err)
})
}
/** Set activeSlideId in editor state */
export const setEditorSlideId = (id: number) => (dispatch: AppDispatch) => {
dispatch({
type: Types.SET_EDITOR_SLIDE_ID,
payload: id,
})
}
/** Set activeViewTypeId in editor state */
export const setEditorViewId = (id: number) => (dispatch: AppDispatch) => {
dispatch({
type: Types.SET_EDITOR_VIEW_ID,
payload: id,
})
}