git ssb

0+

punkmonk / double



Tree: 98f461d19e74598f16307611691908bfb204ccad

Files: 98f461d19e74598f16307611691908bfb204ccad / views / accounts.js

1385 bytesRaw
1const h = require('hyperscript')
2const TITLE = 'double - acounts'
3const Nav = require('../components/nav')
4
5function accountsView (state, emit) {
6 return h('body.code.ph3.lh-copy', [
7 state.cache(Nav, 'nav').render(),
8 h('table', [
9 h('thead', h('tr', [
10 h('td.pr2.red', 'account'),
11 h('td.pr2', 'balance')
12 ])),
13 h('tbody', Object.keys(state.accounts).map(key => {
14 return state.accounts[key].archived
15 ? h('tr', [
16 h('td.strike', state.accounts[key].name),
17 h('td.tr.strike', state.accounts[key].debit - state.accounts[key].credit)
18 ])
19 : h('tr', [
20 h('td', {onclick: handleAccountArchive}, state.accounts[key].name),
21 h('td.tr', state.accounts[key].debit - state.accounts[key].credit)
22 ])
23 }))
24 ]),
25 h('div', [
26 h('div.pt4', 'create a new account'),
27 h('form.pb3', h('input#account')),
28 h('button', { onclick: handleAccountCreate }, 'create')
29 ])
30 ])
31
32 function handleAccountCreate () {
33 const name = document.getElementById('account').value
34
35 emit('accounts', { type: 'accounts', msg: { name, debit: 0, credit: 0, archived: false } })
36 }
37
38 function handleAccountArchive () {
39 const name = this.innerHTML
40
41 emit('accounts', { type: 'accounts', msg: { name, archived: true } })
42 }
43}
44
45module.exports = accountsView
46

Built with git-ssb-web