@@ -31,6 +31,8 @@ export default class extends Component {
3131 this . onMessage = this . onMessage . bind ( this ) ;
3232 this . onSubscribeChange = this . onSubscribeChange . bind ( this ) ;
3333 this . onClickClear = this . onClickClear . bind ( this ) ;
34+ this . _handleKeyDownPub = this . _handleKeyDownPub . bind ( this ) ;
35+ this . _handleKeyDownSub = this . _handleKeyDownSub . bind ( this ) ;
3436 }
3537
3638 componentDidMount ( ) {
@@ -113,6 +115,18 @@ export default class extends Component {
113115 } ) ;
114116 }
115117
118+ _handleKeyDownPub ( event ) {
119+ if ( event . key === 'Enter' ) {
120+ this . onClickPublish ( event ) ;
121+ }
122+ }
123+
124+ _handleKeyDownSub ( ) {
125+ if ( event . key === 'Enter' ) {
126+ this . onClickSubscribe ( event ) ;
127+ }
128+ }
129+
116130 componentDidUpdate ( ) {
117131 let el = ReactDOM . findDOMNode ( this . _ref_messages . current ) ;
118132 el . scrollTop = el . scrollHeight ;
@@ -122,92 +136,73 @@ export default class extends Component {
122136 let isHighlightedMessages = this . props . model . isHighlightedMessages ;
123137 return (
124138 < div id = "mqttlog" >
125- { this . state . highlighted_messages . length > 0 ? < div className = "Console" >
126- < ul >
139+
140+ < div className = "messagesLog" ref = { this . _ref_messages } >
141+ < ul >
127142 {
128- this . state . highlighted_messages . map ( ( item , index ) => {
143+ this . state . messages . map ( ( item , index ) => {
129144 return (
130145 < li key = { item . key } >
131146 < div > { formatTime ( item . time ) } < i title = "Copy topic to Clipboard" onClick = { ( ) => this . onClickCopyTopic ( item ) } className = "fa fa-clipboard" aria-hidden = "true" > </ i > < span style = { { fontWeight : "bold" } } > { item . topic } </ span > </ div >
132147 < div > { item . payload } </ div >
133- < div className = "ConsoleButton" > < i title = "remove" onClick = { ( ) => this . onClickRemove ( item ) } className = "fa fa-remove" aria-hidden = "true" > </ i > </ div >
134- </ li >
135- )
148+ < div className = "ConsoleButton" >
149+ { isHighlightedMessages ( item . topic ) ? null :< i title = "pinned topic" onClick = { ( ) => this . onClickAdd ( item ) } className = "fa fa-thumb-tack" aria-hidden = "true" > </ i > }
150+ </ div >
151+ </ li > )
136152 } )
137153 }
138154 </ ul >
139- </ div > : null }
155+ </ div >
140156
141- < div className = "Console" ref = { this . _ref_messages } style = { { height : "300px" } } >
142- < ul >
157+ { this . state . highlighted_messages . length > 0 ? < div className = "highlightedMessages" >
158+ < ul >
143159 {
144- this . state . messages . map ( ( item , index ) => {
160+ this . state . highlighted_messages . map ( ( item , index ) => {
145161 return (
146162 < li key = { item . key } >
147163 < div > { formatTime ( item . time ) } < i title = "Copy topic to Clipboard" onClick = { ( ) => this . onClickCopyTopic ( item ) } className = "fa fa-clipboard" aria-hidden = "true" > </ i > < span style = { { fontWeight : "bold" } } > { item . topic } </ span > </ div >
148164 < div > { item . payload } </ div >
149- < div className = "ConsoleButton" >
150- { isHighlightedMessages ( item . topic ) ? null :< i title = "pinned topic" onClick = { ( ) => this . onClickAdd ( item ) } className = "fa fa-thumb-tack" aria-hidden = "true" > </ i > }
151- </ div >
152- </ li > )
165+ < div className = "ConsoleButton" > < i title = "remove" onClick = { ( ) => this . onClickRemove ( item ) } className = "fa fa-remove" aria-hidden = "true" > </ i > </ div >
166+ </ li >
167+ )
153168 } )
154169 }
155170 </ ul >
171+ </ div > : null }
172+
173+ < button onClick = { this . onClickClear } className = "btn btn-secondary btn-sm float-right btnClear" > Clear all messages</ button >
174+
175+ < div className = "bottomLog" >
176+
177+ < header className = "h4" > Publish message</ header >
178+ < div className = "input-group mb-3 input-group-sm" >
179+ < input className = "form-control" value = { this . state . pub_topic } onChange = { ( e ) => this . setState ( { pub_topic : e . target . value } ) } onKeyDown = { this . _handleKeyDownPub } type = "text" placeholder = "Enter topic to publish" />
180+ < input className = "form-control" value = { this . state . pub_payload } onChange = { ( e ) => this . setState ( { pub_payload : e . target . value } ) } onKeyDown = { this . _handleKeyDownPub } type = "text" placeholder = "Enter payload to publish" />
181+ < button disabled = { ! this . state . isConnected } onClick = { this . onClickPublish } className = "btn btn-primary btn-sm" > Publish</ button >
156182 </ div >
157183
158- < button onClick = { this . onClickClear } className = "btn btn-secondary btn-sm float-right" > Clear</ button >
159-
160- < form >
161- < div className = "form-group" >
162- < label className = "control-label col-xs-1" >
163- { this . state . checkbox ? "Publish mode" : "Subscribe mode" }
164- </ label >
165- < div className = "col-xs-2" >
166- < label className = "switch" >
167- < input type = "checkbox" onChange = { ( event ) => this . setState ( { checkbox : event . target . checked } ) } />
168- < span className = "slider round" > </ span >
169- </ label >
170- </ div >
171- </ div >
172- { this . state . checkbox ?
173- < div className = "form-group" >
174- < label className = "control-label col-xs-1" > Payload</ label >
175- < div className = "col-xs-8" >
176- < input className = "form-control" value = { this . state . pub_topic } onChange = { ( e ) => this . setState ( { pub_topic : e . target . value } ) } type = "text" placeholder = "Enter topic to publish" />
177- < input className = "form-control" value = { this . state . pub_payload } onChange = { ( e ) => this . setState ( { pub_payload : e . target . value } ) } type = "text" placeholder = "Enter message to publish" />
178- </ div >
179- < div className = "col-xs-2" >
180- < button disabled = { ! this . state . isConnected } onClick = { this . onClickPublish } className = "btn btn-primary btn-sm" > Publish</ button >
181- </ div >
182- </ div >
183- :
184- < div className = "form-group" >
185- < label className = "control-label col-xs-1" > Topic</ label >
186- < div className = "col-xs-8" >
187- < input className = "form-control" placeholder = "Enter topic to subscribe" value = { this . state . sub_topic } onChange = { ( e ) => this . setState ( { sub_topic : e . target . value } ) } type = "text" />
188- </ div >
189- < div className = "col-xs-2" >
190- < button disabled = { ! this . state . isConnected } onClick = { this . onClickSubscribe } className = "btn btn-primary btn-sm" > Subscribe</ button >
191- </ div >
192- </ div >
193- }
194- </ form >
195184 < header className = "h4" > Subscribed topics</ header >
196- < div className = "Console" >
185+ < div className = "input-group input-group-sm" >
186+ < input type = "text" className = "form-control" placeholder = "Enter topic to subscribe" value = { this . state . sub_topic } onChange = { ( e ) => this . setState ( { sub_topic : e . target . value } ) } onKeyDown = { this . _handleKeyDownSub } type = "text" />
187+ < div className = "input-group-append" >
188+ < button type = "submit" className = "btn btn-primary mb-2" disabled = { ! this . state . isConnected } onClick = { this . onClickSubscribe } > Subscribe</ button >
189+ </ div >
190+ </ div >
191+ < div className = "subTable" >
197192 < ul >
198193 {
199194 this . state . subscribed_topics . map ( ( topic , index ) => {
200195 return (
201196 < li key = { index } >
202197 < div > { topic } </ div >
203- < div className = "ConsoleButton" > < button onClick = { ( ) => this . onClickUnsubscribe ( topic ) } > - </ button > </ div >
198+ < div className = "ConsoleButton" > < i title = "remove" onClick = { ( ) => this . onClickUnsubscribe ( topic ) } className = "fa fa-remove" aria-hidden = "true" > </ i > </ div >
204199 </ li >
205200 )
206201 } )
207202 }
208203 </ ul >
209204 </ div >
210- < button disabled = { ! this . state . isConnected } onClick = { this . onClickUnsubscribeAll } className = "btn btn-danger btn-sm" > Unsubscribe all </ button >
205+ </ div >
211206 </ div >
212207
213208 )
0 commit comments