diff --git a/app/src/actions/Tree.ts b/app/src/actions/Tree.ts index 6fe8149..db1cccb 100644 --- a/app/src/actions/Tree.ts +++ b/app/src/actions/Tree.ts @@ -1,9 +1,18 @@ -import { ActionTypes, CustomAction } from '../reducers' +import { ActionTypes, CustomAction, AppState } from '../reducers' import * as q from '../../../backend/src/Model' +import { Dispatch } from 'redux' +import { setTopic } from './Publish' -export const selectTopic = (topic: q.TreeNode): CustomAction => { - return { +export const selectTopic = (topic: q.TreeNode) => (dispatch: Dispatch, getState: () => AppState) => { + const { selectedTopic } = getState().tooBigReducer + + // Update publish topic + if (selectedTopic && (selectedTopic.path() === getState().publish.topic || !getState().publish.topic)) { + dispatch(setTopic(topic.path())) + } + + dispatch({ selectedTopic: topic, type: ActionTypes.selectTopic, - } + }) } diff --git a/app/src/components/Sidebar/Publish/Publish.tsx b/app/src/components/Sidebar/Publish/Publish.tsx index 025aecd..9ef1cb6 100644 --- a/app/src/components/Sidebar/Publish/Publish.tsx +++ b/app/src/components/Sidebar/Publish/Publish.tsx @@ -74,9 +74,9 @@ class Publish extends React.Component { } 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) { this.addMessageToHistory(topic, payload) } @@ -100,19 +100,12 @@ class Publish extends React.Component { ) } - private currentTopic(): string | undefined { - const { node, topic } = this.props - const selectedNodePath = (node ? node.path() : undefined) - - return (topic !== undefined) ? topic : selectedNodePath - } - private clearTopic = () => { this.props.actions.setTopic('') } private topic() { - const topicStr = this.currentTopic() || '' + const topicStr = this.props.topic || '' return (