Fix publish topic update

This commit is contained in:
Thomas Nordquist
2019-01-20 12:47:46 +01:00
parent fa9def4dd7
commit 4d794205d5
2 changed files with 16 additions and 14 deletions

View File

@@ -1,9 +1,18 @@
import { ActionTypes, CustomAction } from '../reducers' import { ActionTypes, CustomAction, AppState } from '../reducers'
import * as q from '../../../backend/src/Model' import * as q from '../../../backend/src/Model'
import { Dispatch } from 'redux'
import { setTopic } from './Publish'
export const selectTopic = (topic: q.TreeNode): CustomAction => { export const selectTopic = (topic: q.TreeNode) => (dispatch: Dispatch<any>, getState: () => AppState) => {
return { const { selectedTopic } = getState().tooBigReducer
// Update publish topic
if (selectedTopic && (selectedTopic.path() === getState().publish.topic || !getState().publish.topic)) {
dispatch(setTopic(topic.path()))
}
dispatch({
selectedTopic: topic, selectedTopic: topic,
type: ActionTypes.selectTopic, type: ActionTypes.selectTopic,
} })
} }

View File

@@ -74,9 +74,9 @@ class Publish extends React.Component<Props, State> {
} }
this.props.actions.publish(this.props.connectionId) this.props.actions.publish(this.props.connectionId)
const topic = this.currentTopic() || ''
const payload = this.props.payload
const topic = this.props.topic || ''
const payload = this.props.payload
if (this.props.connectionId && topic) { if (this.props.connectionId && topic) {
this.addMessageToHistory(topic, payload) this.addMessageToHistory(topic, payload)
} }
@@ -100,19 +100,12 @@ class Publish extends React.Component<Props, State> {
) )
} }
private currentTopic(): string | undefined {
const { node, topic } = this.props
const selectedNodePath = (node ? node.path() : undefined)
return (topic !== undefined) ? topic : selectedNodePath
}
private clearTopic = () => { private clearTopic = () => {
this.props.actions.setTopic('') this.props.actions.setTopic('')
} }
private topic() { private topic() {
const topicStr = this.currentTopic() || '' const topicStr = this.props.topic || ''
return ( return (
<div> <div>