Commit 2ffc226a authored by Vladimir Kiryakov's avatar Vladimir Kiryakov
Browse files

open form after disconnect

parent eeb5d563
......@@ -9,6 +9,7 @@ export const MQTT_PUSH_MESSAGE = 'mqtt_push_message';
export const MQTT_PUSH_MESSAGES = 'mqtt_push_messages';
export const MQTT_FORM_TOGGLE = 'mqtt_form_toggle';
export const MQTT_FORM_OPEN = 'mqtt_form_open';
export const MQTT_CHANGE_CONNECTION_STATUS = 'MQTT_CHANGE_CONNECTION_STATUS';
export const GATEWAY_DISCONNECTED = 'GATEWAY_DISCONNECTED';
......@@ -94,4 +95,8 @@ export const pushMessages = (messages) => (dispatch, getState) => {
export const toggleMqttForm = () => ({
type: MQTT_FORM_TOGGLE,
});
export const openMqttForm = () => ({
type: MQTT_FORM_OPEN,
});
\ No newline at end of file
......@@ -19,7 +19,7 @@ const mqttMiddleware = (function () {
store.dispatch(pushMessages(messages));
messages = [];
}
}, 500);
}, 1000);
const subscribe = (newUrl, newTopic, newReconnectPeriod) => {
if (client != null) {
......
......@@ -9,7 +9,7 @@ import LoaderOverlay from '../../../UIKit/components/Overlay/LoaderOverlay';
const SubscribeToTopic = ({
className, startListeningTopic, disconnect, isConnected, reconnectPeriod,
className, startListeningTopic, unsubscribe, isConnected, reconnectPeriod,
topic, url, maxMessageCapture, displayType,
displayForm, toggleMqttForm, isConnectInProcess
}) => {
......@@ -19,7 +19,7 @@ const SubscribeToTopic = ({
<div className={classNames('text-muted', className)}>
<button type="button" className="btn btn-link btn-sm"
onClick={toggleMqttForm}>{displayForm ? 'Hide Subscribe form ▴' : 'Show Subscribe form ▾'}</button>
{isConnected ? <button onClick={disconnect}
{isConnected ? <button onClick={unsubscribe}
type="button"
className="btn btn-outline-secondary btn-sm">
Unsubscribe
......@@ -55,7 +55,7 @@ const SubscribeToTopic = ({
</div>
<div className="col-12 col-md-2">
{isConnected ?
<button onClick={disconnect}
<button onClick={unsubscribe}
type="button"
className="btn btn-outline-secondary">
Unsubscribe from topic
......@@ -91,7 +91,8 @@ SubscribeToTopic.propTypes = {
displayType: PropTypes.string,
displayForm: PropTypes.bool,
isConnectInProcess: PropTypes.bool,
toggleMqttForm: PropTypes.func
toggleMqttForm: PropTypes.func,
unsubscribe: PropTypes.func
};
const DisplayType = ({input: {value, onChange}}) => {
......
import {connect} from 'react-redux';
import _ from 'lodash';
import {connect as mqttConnect, disconnect, toggleMqttForm} from '../../../../actions/mqtt';
import {connect as mqttConnect, disconnect, toggleMqttForm, openMqttForm} from '../../../../actions/mqtt';
import SubscribeToTopicView from '../../components/SubscribeForm';
const mapStateToProps = ({mqtt, form}) => {
......@@ -19,8 +19,9 @@ const mapDispatchToProps = dispatch => ({
startListeningTopic: (url, topic) => {
dispatch(mqttConnect(url, topic));
},
disconnect: () => {
unsubscribe: () => {
dispatch(disconnect());
dispatch(openMqttForm());
},
toggleMqttForm: () => {
dispatch(toggleMqttForm());
......
......@@ -5,6 +5,7 @@ import {
MQTT_CONNECTED,
MQTT_DISCONNECTED,
MQTT_FORM_TOGGLE,
MQTT_FORM_OPEN,
MQTT_CONNECT,
MQTT_CHANGE_CONNECTION_STATUS,
......@@ -59,7 +60,8 @@ export default (state = {
case MQTT_CONNECT:
return {
...state,
isConnectInProcess: true
isConnectInProcess: true,
connectionStatus: GATEWAY_DISCONNECTED
};
case MQTT_CONNECTED:
return {
......@@ -80,6 +82,11 @@ export default (state = {
...state,
displayForm: !state.displayForm,
};
case MQTT_FORM_OPEN:
return {
...state,
displayForm: true,
};
default:
return state
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment