diff options
| -rw-r--r-- | frontend/views/graph/components/page.edit.js | 22 | ||||
| -rw-r--r-- | frontend/views/graph/graph.actions.js | 12 | ||||
| -rw-r--r-- | frontend/views/graph/graph.reducer.js | 10 | ||||
| -rw-r--r-- | frontend/views/page/components/page.header.js | 5 | ||||
| -rw-r--r-- | frontend/views/page/page.reducer.js | 23 |
5 files changed, 65 insertions, 7 deletions
diff --git a/frontend/views/graph/components/page.edit.js b/frontend/views/graph/components/page.edit.js index 1e59647..5bc64d6 100644 --- a/frontend/views/graph/components/page.edit.js +++ b/frontend/views/graph/components/page.edit.js @@ -1,9 +1,12 @@ import React, { Component } from 'react' import { Link } from 'react-router-dom' import { connect } from 'react-redux' +import { bindActionCreators } from 'redux' import { history } from '../../../store' import actions from '../../../actions' +import * as siteActions from '../../site/site.actions' +import * as graphActions from '../../graph/graph.actions' import { Loader } from '../../../common' @@ -11,16 +14,22 @@ import PageForm from '../components/page.form' class PageEdit extends Component { componentDidMount() { - console.log(this.props.match.params.id) - actions.page.show(this.props.match.params.id) + // actions.page.show(this.props.match.params.id) } handleSubmit(data) { + const { path: graphPath } = this.props.graph.show.res + const { path: oldPagePath } = this.props.page.show.res + const { path: newPagePath } = data actions.page.update(data) .then(response => { - // response - console.log(response) - // history.push('/' + data.path) + // console.log(response) + actions.site.setSiteTitle(response.res.title) + this.props.graphActions.hideEditPageForm() + if (oldPagePath !== newPagePath) { + const newPath = '/' + graphPath + '/' + newPagePath + history.push(newPath) + } }) } @@ -49,7 +58,8 @@ const mapStateToProps = state => ({ }) const mapDispatchToProps = dispatch => ({ - // searchActions: bindActionCreators({ ...searchActions }, dispatch), + siteActions: bindActionCreators({ ...siteActions }, dispatch), + graphActions: bindActionCreators({ ...graphActions }, dispatch), }) export default connect(mapStateToProps, mapDispatchToProps)(PageEdit) diff --git a/frontend/views/graph/graph.actions.js b/frontend/views/graph/graph.actions.js index 1ee6999..03ea217 100644 --- a/frontend/views/graph/graph.actions.js +++ b/frontend/views/graph/graph.actions.js @@ -12,6 +12,18 @@ export const toggleAddPageForm = () => dispatch => { dispatch({ type: types.graph.toggle_add_page_form }) } +export const showEditPageForm = () => dispatch => { + dispatch({ type: types.graph.show_edit_page_form }) +} + +export const hideEditPageForm = () => dispatch => { + dispatch({ type: types.graph.hide_edit_page_form }) +} + +export const toggleEditPageForm = () => dispatch => { + dispatch({ type: types.graph.toggle_edit_page_form }) +} + export const updateGraphPage = page => dispatch => { dispatch({ type: types.graph.update_graph_page, page }) } diff --git a/frontend/views/graph/graph.reducer.js b/frontend/views/graph/graph.reducer.js index 336257d..60f52ee 100644 --- a/frontend/views/graph/graph.reducer.js +++ b/frontend/views/graph/graph.reducer.js @@ -84,6 +84,16 @@ export default function graphReducer(state = initialState, action) { } } + case types.graph.toggle_edit_page_form: + return { + ...state, + editor: { + ...state.editor, + addingPage: false, + editingPage: true, + } + } + default: return state } diff --git a/frontend/views/page/components/page.header.js b/frontend/views/page/components/page.header.js index 2898f86..eb1c3b9 100644 --- a/frontend/views/page/components/page.header.js +++ b/frontend/views/page/components/page.header.js @@ -3,6 +3,7 @@ import { bindActionCreators } from 'redux' import { connect } from 'react-redux' import { Link } from 'react-router-dom' +import * as graphActions from '../../graph/graph.actions' import * as pageActions from '../page.actions' function PageHeader(props) { @@ -13,7 +14,8 @@ function PageHeader(props) { </div> <div> <button onClick={() => props.pageActions.toggleAddTileForm()}>+ Add tile</button> - <button onClick={() => props.pageActions.toggleTileList()}>+ Sort tiles</button> + <button onClick={() => props.pageActions.toggleTileList()}>Sort tiles</button> + <button onClick={() => props.graphActions.toggleEditPageForm()}>Edit page</button> </div> </header> ) @@ -27,6 +29,7 @@ const mapStateToProps = (state) => ({ }) const mapDispatchToProps = (dispatch) => ({ + graphActions: bindActionCreators({ ...graphActions }, dispatch), pageActions: bindActionCreators({ ...pageActions }, dispatch), }) diff --git a/frontend/views/page/page.reducer.js b/frontend/views/page/page.reducer.js index 1c66491..7bffe8e 100644 --- a/frontend/views/page/page.reducer.js +++ b/frontend/views/page/page.reducer.js @@ -33,6 +33,18 @@ export default function pageReducer(state = initialState, action) { } } + case types.page.update: + return { + ...state, + show: { + ...state.show, + res: { + ...action.data.res, + tiles: state.show.res.tiles, + } + } + } + case types.page.update_page_tile: return { ...state, @@ -137,6 +149,17 @@ export default function pageReducer(state = initialState, action) { } } + case types.graph.toggle_edit_page_form: + return { + ...state, + editor: { + ...state.editor, + addingTile: false, + editingTile: false, + tileList: false, + } + } + case types.page.set_tile_sort_order: return { ...state, |
