summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2020-06-14 19:56:33 +0200
committerJules Laplace <julescarbon@gmail.com>2020-06-14 19:56:33 +0200
commitff134ba1809fe3f96b806051ac6f4afb52c4304e (patch)
treed50778ab72825d0bd6eeccd769b211a46fba87b1
parenteb5136e2023fb0999995befff60624d5d4c51c94 (diff)
properly sorting and deleting tiles
-rw-r--r--cli/app/controllers/crud_controller.py1
-rw-r--r--frontend/views/page/components/page.editor.js4
-rw-r--r--frontend/views/page/components/tile.form.js9
-rw-r--r--frontend/views/page/page.reducer.js13
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 (
<div className='page' ref={this.pageRef} style={pageStyle}>
{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 {