import { Action , ActionTypes } from '../reducers/Publish' ; import { AppState } from '../reducers' ; import { Base64Message } from '../../../backend/src/Model/Base64Message' ; import { Dispatch } from 'redux' ; import { makePublishEvent , rendererEvents } from '../../../events' ; export const setTopic = ( topic ? ) : Action => { return { topic , type : ActionTypes . PUBLISH_SET_TOPIC , } ; } ; export const setPayload = ( payload ? ) : Action => { return { payload , type : ActionTypes . PUBLISH_SET_PAYLOAD , } ; } ; export const setQoS = ( qos ) : Action => { return { qos , type : ActionTypes . PUBLISH_SET_QOS , } ; } ; export const setEditorMode = ( editorMode ) : Action => { return { editorMode , type : ActionTypes . PUBLISH_SET_EDITOR_MODE , } ; } ; export const publish = ( connectionId ) => ( dispatch , getState ) => { const state = getState ( ) ; const topic = state . publish . manualTopic ?? state . tree . get ( 'selectedTopic' ) ?. path ( ) ; if ( ! topic ) { return ; } const publishEvent = makePublishEvent ( connectionId ) ; const mqttMessage = { topic , payload : state . publish . payload ? Base64Message . fromString ( state . publish . payload ) : null , retain : state . publish . retain , qos : state . publish . qos , } ; rendererEvents . emit ( publishEvent , mqttMessage ) ; } ; export const toggleRetain = ( ) : Action => { return { type : ActionTypes . PUBLISH_TOGGLE_RETAIN , } ; } ;