git ssb

0+

punkmonk / double



Tree: 8f610eca2bb7c82ab4520dcd17f0816be4901f3b

Files: 8f610eca2bb7c82ab4520dcd17f0816be4901f3b / views / accounts.js

1331 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('div.pv2', 'account balances'),
9 Object.keys(state.accounts).map(key => {
10 if (state.accounts[key].archived) {
11 return h('div', [
12 h('div.dib.strike', { onclick: handleAccountArchive }, state.accounts[key].name),
13 h('div.dib.pr2.strike', state.accounts[key].debit - state.accounts[key].credit)
14 ])
15 }
16 return h('div', [
17 h('div.dib.pr2', { onclick: handleAccountArchive }, state.accounts[key].name),
18 h('div.dib', state.accounts[key].debit - state.accounts[key].credit)
19 ])
20 }),
21 h('div', [
22 h('div.pt4', 'create a new account'),
23 h('form.pb3', h('input#account')),
24 h('button', { onclick: handleAccountCreate }, 'create')
25 ])
26 ])
27
28 function handleAccountCreate () {
29 const name = document.getElementById('account').value
30
31 emit('accounts', { type: 'accounts', msg: { name, debit: 0, credit: 0, archived: false } })
32 }
33
34 function handleAccountArchive () {
35 const name = this.innerHTML
36
37 emit('accounts', { type: 'accounts', msg: { name, archived: true } })
38 }
39}
40
41module.exports = accountsView
42

Built with git-ssb-web