From 87a86b8c0c302dd3afdbf46761e829851e010c5a Mon Sep 17 00:00:00 2001 From: Thomas Nordquist Date: Sun, 3 Mar 2019 06:34:06 +0100 Subject: [PATCH] Add json formatting --- .../components/Sidebar/Publish/Publish.tsx | 28 ++++++++++++++++++- app/src/reducers/Publish.ts | 2 +- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/app/src/components/Sidebar/Publish/Publish.tsx b/app/src/components/Sidebar/Publish/Publish.tsx index 4cb2ba2..4817341 100644 --- a/app/src/components/Sidebar/Publish/Publish.tsx +++ b/app/src/components/Sidebar/Publish/Publish.tsx @@ -19,6 +19,7 @@ import { Checkbox, MenuItem, Tooltip, + Fab, } from '@material-ui/core' // tslint:disable-next-line @@ -27,12 +28,13 @@ import { AppState } from '../../../reducers' import History from '../History' import Message from './Model/Message' import Navigation from '@material-ui/icons/Navigation' -import Clear from '@material-ui/icons/Clear' +import FormatAlignLeft from '@material-ui/icons/FormatAlignLeft' import { bindActionCreators } from 'redux' import { connect } from 'react-redux' import { publishActions } from '../../../actions' import ClearAdornment from '../../helper/ClearAdornment' import { TopicViewModel } from '../../../TopicViewModel' +import CustomIconButton from '../../CustomIconButton'; interface Props { node?: q.TreeNode @@ -151,11 +153,35 @@ class Publish extends React.Component { ) } + private formatJson = () => { + if (this.props.payload) { + try { + const str = JSON.stringify(JSON.parse(this.props.payload), undefined, ' ') + this.updatePayload(str) + } catch { } + } + } + + private renderFormatJson() { + if (this.props.editorMode !== 'json') { + return null + } + + return ( + + + + + + ) + } + private editorMode() { return (
{this.renderEditorModeSelection()} + {this.renderFormatJson()}
{this.publishButton()}
diff --git a/app/src/reducers/Publish.ts b/app/src/reducers/Publish.ts index 1db14c8..22af023 100644 --- a/app/src/reducers/Publish.ts +++ b/app/src/reducers/Publish.ts @@ -44,7 +44,7 @@ export interface ToggleRetain { } const initialState: PublishState = { - editorMode: 'text', + editorMode: 'json', retain: false, qos: 0, }