Files
mqtt-explorer/app/src/actions/Tree.ts
2019-01-22 12:17:59 +01:00

35 lines
1008 B
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { AppState } from '../reducers'
import { ActionTypes } from '../reducers/Tree'
import * as q from '../../../backend/src/Model'
import { Dispatch } from 'redux'
import { setTopic } from './Publish'
export const selectTopic = (topic: q.TreeNode) => (dispatch: Dispatch<any>, getState: () => AppState) => {
const { selectedTopic } = getState().tree
// Update publish topic
if (selectedTopic && (selectedTopic.path() === getState().publish.topic || !getState().publish.topic)) {
dispatch(setTopic(topic.path()))
}
dispatch({
selectedTopic: topic,
type: ActionTypes.TREE_SELECT_TOPIC,
})
}
export const showTree = (tree?: q.Tree) => (dispatch: Dispatch<any>, getState: () => AppState) => {
const visibleTree = getState().tree.tree
const connectionTree = getState().connection.tree
// Stop updates of old tree
if (visibleTree !== connectionTree && visibleTree) {
visibleTree.stopUpdating()
}
dispatch({
tree,
type: ActionTypes.TREE_SHOW_TREE,
})
}