diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2020-06-02 22:21:36 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2020-06-02 22:21:36 +0200 |
| commit | 70a29089cdb05df27cf50b50fcbc2e53d8975571 (patch) | |
| tree | 052e7b81291d8ac0c5639c32e4a6f98ce593ba38 /frontend | |
| parent | 097e54d4c0646a809eba4ed69929b2a16b682754 (diff) | |
updating after dragging
Diffstat (limited to 'frontend')
| -rw-r--r-- | frontend/types.js | 1 | ||||
| -rw-r--r-- | frontend/views/graph/components/graph.editor.js | 21 | ||||
| -rw-r--r-- | frontend/views/graph/graph.actions.js | 4 | ||||
| -rw-r--r-- | frontend/views/index/graph.reducer.js | 20 |
4 files changed, 38 insertions, 8 deletions
diff --git a/frontend/types.js b/frontend/types.js index 1431e06..1c0de90 100644 --- a/frontend/types.js +++ b/frontend/types.js @@ -4,6 +4,7 @@ export const api = crud_type('api', []) export const graph = crud_type('graph', [ 'show_add_page_form', 'hide_add_page_form', 'show_edit_page_form', 'hide_edit_page_form', + 'update_graph_page', ]) export const page = crud_type('page', []) export const tile = crud_type('tile', []) diff --git a/frontend/views/graph/components/graph.editor.js b/frontend/views/graph/components/graph.editor.js index d4da2b6..1b2d446 100644 --- a/frontend/views/graph/components/graph.editor.js +++ b/frontend/views/graph/components/graph.editor.js @@ -4,6 +4,8 @@ import { bindActionCreators } from 'redux' import { connect } from 'react-redux' import { session } from '../../../session' +import actions from '../../../actions' +import * as graphActions from '../graph.actions' import { Loader } from '../../../common' import { clamp } from '../../../util' @@ -114,8 +116,8 @@ class GraphEditor extends Component { } handleMouseUp(e) { - const { actions } = this.props - const { dragging, draggingBox, bounds, box } = this.state + // const { actions } = this.props + const { dragging, draggingBox, bounds, box, page } = this.state if (!dragging && !draggingBox) return e.preventDefault() const { x, y, w, h } = box @@ -127,11 +129,16 @@ class GraphEditor extends Component { dragging: false, draggingBox: false, }) - if (w < 10 / bounds.width || h < 10 / bounds.height) { - // too small... - } else { - // update page, settings.x/y + // console.log(page) + const updatedPage = { + ...page, + settings: { + ...page.settings, + x, y, + } } + this.props.graphActions.updateGraphPage(updatedPage) + actions.page.update(updatedPage) } render(){ @@ -182,7 +189,7 @@ const mapStateToProps = state => ({ }) const mapDispatchToProps = dispatch => ({ - // uploadActions: bindActionCreators({ ...uploadActions }, dispatch), + graphActions: bindActionCreators({ ...graphActions }, dispatch), }) export default connect(mapStateToProps, mapDispatchToProps)(GraphEditor) diff --git a/frontend/views/graph/graph.actions.js b/frontend/views/graph/graph.actions.js index 2e6ca54..90d0f96 100644 --- a/frontend/views/graph/graph.actions.js +++ b/frontend/views/graph/graph.actions.js @@ -7,3 +7,7 @@ export const showAddPageForm = () => dispatch => { export const hideAddPageForm = () => dispatch => { dispatch({ type: types.graph.hide_add_page_form }) } + +export const updateGraphPage = page => dispatch => { + dispatch({ type: types.graph.update_graph_page, page }) +} diff --git a/frontend/views/index/graph.reducer.js b/frontend/views/index/graph.reducer.js index e0ded41..9f42f52 100644 --- a/frontend/views/index/graph.reducer.js +++ b/frontend/views/index/graph.reducer.js @@ -15,9 +15,27 @@ const initialState = crudState('graph', { const reducer = crudReducer('graph') export default function graphReducer(state = initialState, action) { - // console.log(action.type, action) + console.log(action.type, action) state = reducer(state, action) switch (action.type) { + case types.graph.update_graph_page: + return { + ...state, + show: { + ...state.show, + res: { + ...state.show.res, + pages: state.show.res.pages.map(page => { + if (page.id === action.page.id) { + return { ...action.page } + } else { + return page + } + }), + } + } + } + case types.graph.show_add_page_form: return { ...state, |
