const h = require('hyperscript') const TITLE = 'double - acounts' const Nav = require('../components/nav') function accountsView (state, emit) { return h('body.code.ph3.lh-copy', [ state.cache(Nav, 'nav').render(), h('div.pv2', 'account balances'), Object.keys(state.accounts).map(key => { if (state.accounts[key].archived) { return h('div', [ h('div.dib.strike', { onclick: handleAccountArchive }, state.accounts[key].name), h('div.dib.pr2.strike', state.accounts[key].debit - state.accounts[key].credit) ]) } return h('div', [ h('div.dib.pr2', { onclick: handleAccountArchive }, state.accounts[key].name), h('div.dib', state.accounts[key].debit - state.accounts[key].credit) ]) }), h('div', [ h('div.pt4', 'create a new account'), h('form.pb3', h('input#account')), h('button', { onclick: handleAccountCreate }, 'create') ]) ]) function handleAccountCreate () { const name = document.getElementById('account').value emit('accounts', { type: 'accounts', msg: { name, debit: 0, credit: 0, archived: false } }) } function handleAccountArchive () { const name = this.innerHTML emit('accounts', { type: 'accounts', msg: { name, archived: true } }) } } module.exports = accountsView