`
const submit = html`
submit
`
const entries = html`
account
debit
credit
${state.entries.map(entry => ['debit', 'credit'].map(i => i === 'debit'
? html`
${entry.msg.debit}
${entry.msg.amount}
-
`
: html`
${entry.msg.credit}
-
${entry.msg.amount}
`
))}
`
return html`
double
${form}
${entries}
${submit}
create account
${Object.keys(state.accounts).map(key => {
if (state.accounts[key].archived) return html`
${state.accounts[key].name}
`
return html`
${state.accounts[key].name}
`
})}
`
function generateAccountList () {
return Object.keys(state.accounts).map(key => {
if (state.accounts[key].archived) return
const name = state.accounts[key].name
return html`
${name} `
})
}
function handleEntry () {
const amount = document.getElementById('amount').value
const debit = document.getElementById('debit').value
const credit = document.getElementById('credit').value
const description = document.getElementById('description').value
emit('entries', { type: 'entries', msg: { amount, debit, credit, description } })
}
function handleAccountCreate () {
const account = document.getElementById('account').value
emit('accounts', { type: 'accounts', msg: { name: account, archived: false } })
}
function handleAccountArchive () {
const name = this.innerHTML
emit('accounts', { type: 'accounts', msg: { name, type: 'TOGGLE' } })
}
}
module.exports = view