From ff134ba1809fe3f96b806051ac6f4afb52c4304e Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sun, 14 Jun 2020 19:56:33 +0200 Subject: properly sorting and deleting tiles --- cli/app/controllers/crud_controller.py | 1 + frontend/views/page/components/page.editor.js | 4 +++- frontend/views/page/components/tile.form.js | 9 ++++++--- frontend/views/page/page.reducer.js | 13 +++++++++++++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/cli/app/controllers/crud_controller.py b/cli/app/controllers/crud_controller.py index c1bde8d..17d9494 100644 --- a/cli/app/controllers/crud_controller.py +++ b/cli/app/controllers/crud_controller.py @@ -143,6 +143,7 @@ class CrudView(FlaskView): session.commit() res = { 'status': 'ok', + 'id': id, } else: res = { diff --git a/frontend/views/page/components/page.editor.js b/frontend/views/page/components/page.editor.js index 24e2075..bee86a0 100644 --- a/frontend/views/page/components/page.editor.js +++ b/frontend/views/page/components/page.editor.js @@ -152,6 +152,7 @@ class PageEditor extends Component { this.props.tileActions.updateTemporaryTile(updatedTile) } if (tile.id !== 'new') { + console.log(updatedTile) this.props.pageActions.updatePageTile(updatedTile) actions.tile.update(updatedTile) } @@ -167,7 +168,8 @@ class PageEditor extends Component { const currentTile = this.state.tile const currentBox = this.state.box const { res } = this.props.page.show - const pageStyle = { backgroundColor: res.settings.background_color || '#000000' } + const { settings } = res + const pageStyle = { backgroundColor: settings ? settings.background_color : '#000000' } return (
{res.tiles.map(tile => { diff --git a/frontend/views/page/components/tile.form.js b/frontend/views/page/components/tile.form.js index 8d26173..dd8da96 100644 --- a/frontend/views/page/components/tile.form.js +++ b/frontend/views/page/components/tile.form.js @@ -3,6 +3,7 @@ import { connect } from 'react-redux' import { bindActionCreators } from 'redux' import { Link } from 'react-router-dom' +import actions from '../../../actions' import { session } from '../../../session' import { @@ -288,10 +289,12 @@ class TileForm extends Component { } handleDelete() { - const { temporaryTile, isNew } = this.props - const tile_id = temporaryTile.id + const { temporaryTile, isNew, onClose } = this.props if (confirm('Really delete this tile?')) { - actions.tile.delete(temporaryTile.id) + actions.tile.destroy(temporaryTile) + .then(() => { + onClose() + }) } } diff --git a/frontend/views/page/page.reducer.js b/frontend/views/page/page.reducer.js index 2d80551..bbbe6f9 100644 --- a/frontend/views/page/page.reducer.js +++ b/frontend/views/page/page.reducer.js @@ -58,6 +58,7 @@ export default function pageReducer(state = initialState, action) { } case types.page.update_page_tile: + console.log(action.tile) return { ...state, show: { @@ -75,6 +76,18 @@ export default function pageReducer(state = initialState, action) { } } + case types.tile.destroy: + return { + ...state, + show: { + ...state.show, + res: { + ...state.show.res, + tiles: state.show.res.tiles.filter(tile => tile.id !== action.data.id) + } + } + } + // add tile UI case types.page.show_add_tile_form: return { -- cgit v1.2.3-70-g09d2