const m = require('mithril') const client = require('./api/client') const Status = { oninit: function(vnode) { client.registerComponent(this) }, onremove: function(vnode) { client.unregisterComponent(this) }, startClicked() { client.emit('encoder.start') }, stopClicked() { client.emit('encoder.stop') }, view: function(vnode) { let display = client.status.serial_display || { first: '', second: ''} return [ m('pre.status', client.isConnected ? display.first.padEnd(20) + '\n' + display.second : ' \n ' ), m('.status.row', [ m('button.button', { hidden: client.status.encoder_running || client.status.encoder_starting, onclick: this.startClicked.bind(this), }, 'Start'), m('button.button', { hidden: !client.status.encoder_running && !client.status.encoder_starting, onclick: this.stopClicked.bind(this), }, 'Stop'), ]), ] }, } module.exports = Status