diff options
Diffstat (limited to 'web/src/js/ducks')
-rw-r--r-- | web/src/js/ducks/flows.js | 5 | ||||
-rw-r--r-- | web/src/js/ducks/ui/flow.js | 37 |
2 files changed, 24 insertions, 18 deletions
diff --git a/web/src/js/ducks/flows.js b/web/src/js/ducks/flows.js index f18e48e6..f96653a9 100644 --- a/web/src/js/ducks/flows.js +++ b/web/src/js/ducks/flows.js @@ -112,10 +112,9 @@ export function update(flow, data) { return dispatch => fetchApi.put(`/flows/${flow.id}`, data) } -export function updateContent(flow, file, type) { +export function uploadContent(flow, file, type) { const body = new FormData() - if (typeof file !== File) - file = new Blob([file], {type: 'plain/text'}) + file = new Blob([file], {type: 'plain/text'}) body.append('file', file) return dispatch => fetchApi(`/flows/${flow.id}/${type}/content`, {method: 'post', body} ) } diff --git a/web/src/js/ducks/ui/flow.js b/web/src/js/ducks/ui/flow.js index b1fe535f..c9435676 100644 --- a/web/src/js/ducks/ui/flow.js +++ b/web/src/js/ducks/ui/flow.js @@ -1,4 +1,6 @@ import * as flowsActions from '../flows' +import { getDiff } from "../../utils" + import _ from 'lodash' export const SET_CONTENT_VIEW = 'UI_FLOWVIEW_SET_CONTENT_VIEW', @@ -6,7 +8,7 @@ export const SET_CONTENT_VIEW = 'UI_FLOWVIEW_SET_CONTENT_VIEW', SET_TAB = "UI_FLOWVIEW_SET_TAB", START_EDIT = 'UI_FLOWVIEW_START_EDIT', UPDATE_EDIT = 'UI_FLOWVIEW_UPDATE_EDIT', - STOP_EDIT = 'UI_FLOWVIEW_STOP_EDIT' + UPLOAD_CONTENT = 'UI_FLOWVIEW_UPLOAD_CONTENT' const defaultState = { @@ -22,7 +24,7 @@ export default function reducer(state = defaultState, action) { case START_EDIT: return { ...state, - modifiedFlow: action.flow + modifiedFlow: action.flow, } case UPDATE_EDIT: @@ -31,12 +33,6 @@ export default function reducer(state = defaultState, action) { modifiedFlow: _.merge({}, state.modifiedFlow, action.update) } - case STOP_EDIT: - return { - ...state, - modifiedFlow: false - } - case flowsActions.SELECT: return { ...state, @@ -44,6 +40,21 @@ export default function reducer(state = defaultState, action) { displayLarge: false, } + case flowsActions.UPDATE: + // There is no explicit "stop edit" event. + // We stop editing when we receive an update for + // the currently edited flow from the server + if (action.item.id === state.modifiedFlow.id) { + return { + ...state, + modifiedFlow: false, + displayLarge: false, + } + } else { + return state + } + + case SET_TAB: return { ...state, @@ -87,11 +98,7 @@ export function updateEdit(update) { return { type: UPDATE_EDIT, update } } -export function stopEdit(flow) { - return (dispatch) => { - dispatch(flowsActions.update(flow, flow)).then(() => { - dispatch(flowsActions.updateFlow(flow)) - dispatch({ type: STOP_EDIT }) - }) - } +export function stopEdit(flow, modifiedFlow) { + let diff = getDiff(flow, modifiedFlow) + return flowsActions.update(flow, diff) } |