From c3a634b2160eff047488d6e8410403cc404d7d36 Mon Sep 17 00:00:00 2001 From: Lukas Martinelli Date: Sat, 31 Dec 2016 14:32:04 +0100 Subject: [PATCH] Show undo/redo message --- src/components/App.jsx | 23 +++++++++++------ src/components/ErrorPanel.jsx | 32 ------------------------ src/components/MessagePanel.jsx | 44 +++++++++++++++++++++++++++++++++ src/libs/diffmessage.js | 13 ++++++++++ 4 files changed, 73 insertions(+), 39 deletions(-) delete mode 100644 src/components/ErrorPanel.jsx create mode 100644 src/components/MessagePanel.jsx create mode 100644 src/libs/diffmessage.js diff --git a/src/components/App.jsx b/src/components/App.jsx index 041d567..662aada 100644 --- a/src/components/App.jsx +++ b/src/components/App.jsx @@ -9,11 +9,12 @@ import LayerList from './layers/LayerList' import LayerEditor from './layers/LayerEditor' import Toolbar from './Toolbar' import AppLayout from './AppLayout' -import ErrorPanel from './ErrorPanel' +import MessagePanel from './MessagePanel' import GlSpec from 'mapbox-gl-style-spec/reference/latest.js' import validateStyleMin from 'mapbox-gl-style-spec/lib/validate_style.min' import style from '../libs/style.js' +import { undoMessages, redoMessages } from '../libs/diffmessage' import { loadDefaultStyle, StyleStore } from '../libs/stylestore' import { ApiStyleStore } from '../libs/apistore' import { RevisionStore } from '../libs/revisions' @@ -36,6 +37,7 @@ export default class App extends React.Component { this.state = { errors: [], + infos: [], mapStyle: style.emptyStyle, selectedLayerIndex: 0, sources: {}, @@ -92,16 +94,22 @@ export default class App extends React.Component { onUndo() { const activeStyle = this.revisionStore.undo() - console.log('Undo revision', this.revisionStore.currentIdx) + const messages = undoMessages(this.state.mapStyle, activeStyle) this.saveStyle(activeStyle) - this.setState({ mapStyle: activeStyle }) + this.setState({ + mapStyle: activeStyle, + infos: messages, + }) } onRedo() { const activeStyle = this.revisionStore.redo() - console.log('Redo revision', this.revisionStore.currentIdx) + const messages = redoMessages(this.state.mapStyle, activeStyle) this.saveStyle(activeStyle) - this.setState({ mapStyle: activeStyle }) + this.setState({ + mapStyle: activeStyle, + infos: messages, + }) } onLayersChange(changedLayers) { @@ -194,8 +202,9 @@ export default class App extends React.Component { onLayerIdChange={this.onLayerIdChange.bind(this)} /> : null - const bottomPanel = this.state.errors.length > 0 ? 0 ? : null return { - return - {m} - - }) - - return
- {errors} -
- } -} - - -export default ErrorPanel diff --git a/src/components/MessagePanel.jsx b/src/components/MessagePanel.jsx new file mode 100644 index 0000000..ce304f1 --- /dev/null +++ b/src/components/MessagePanel.jsx @@ -0,0 +1,44 @@ +import React from 'react' +import Paragraph from './Paragraph' +import colors from '../config/colors' +import { fontSizes, margins } from '../config/scales' + +class MessagePanel extends React.Component { + static propTypes = { + errors: React.PropTypes.array, + infos: React.PropTypes.array, + } + + render() { + const paragraphStyle = { + margin: 0, + lineHeight: 1.2, + } + + const errors = this.props.errors.map((m, i) => { + return {m} + }) + + const infos = this.props.infos.map((m, i) => { + return {m} + }) + + return
+ {errors} + {infos} +
+ } +} + + +export default MessagePanel diff --git a/src/libs/diffmessage.js b/src/libs/diffmessage.js new file mode 100644 index 0000000..502c59e --- /dev/null +++ b/src/libs/diffmessage.js @@ -0,0 +1,13 @@ +import diffStyles from 'mapbox-gl-style-spec/lib/diff' + +export function diffMessages(beforeStyle, afterStyle) { + const changes = diffStyles(beforeStyle, afterStyle) + return changes.map(cmd => cmd.command + ' ' + cmd.args.join(' ')) +} + +export function undoMessages(beforeStyle, afterStyle) { + return diffMessages(beforeStyle, afterStyle).map(m => 'Undo ' + m) +} +export function redoMessages(beforeStyle, afterStyle) { + return diffMessages(beforeStyle, afterStyle).map(m => 'Redo ' + m) +}