git ssb

3+

arj / patchbook



Tree: 40aa5761d29866aa4ab08ff139a33262cbc14177

Files: 40aa5761d29866aa4ab08ff139a33262cbc14177 / book / html / create.js

1803 bytesRaw
1const { h, when, Value } = require('mutant')
2const nest = require('depnest')
3
4exports.needs = nest({
5 'blob.html.input': 'first',
6 'message.html.confirm': 'first',
7 'book.obs.struct': 'first',
8 'book.html': {
9 'images': 'first'
10 }
11})
12
13exports.gives = nest('book.html.create')
14
15exports.create = function (api) {
16 var showCreate = Value(false)
17
18 return nest({ 'book.html.create': create })
19
20 function createBook() {
21 let book = api.book.obs.struct()
22
23 const { images } = api.book.html
24
25 return h('Create -book',
26 { classList: when(showCreate, '-expanded', '-contracted') }, [
27 h('section.content', [
28 h('div.title', [h('label', 'Title:'),
29 h('input', {'ev-input': e => book.title.set(e.target.value),
30 value: '' })]),
31 h('div.authors', [h('label', 'Authors:'),
32 h('input', {'ev-input': e => book.authors.set(e.target.value),
33 value: '' })]),
34 images({images: book.images, isEditing: true, onUpdate: book.images.add }),
35 h('div.description', [h('div', 'Synopsis:'),
36 h('textarea', {'ev-input': e => book.description.set(e.target.value),
37 value: '' }) ])
38 ]),
39 h('section.actions', [
40 h('button', {'ev-click': () => showCreate.set(false) }, 'Cancel'),
41 h('button', {'ev-click': () => save(book)}, 'Create book')
42 ])
43 ])
44
45 function save (book) {
46 book.create()
47
48 showCreate.set(false)
49 }
50 }
51
52 function create () {
53 const actions = h('button', {'ev-click': () => showCreate.set(true) }, 'Create')
54 const composer = h('div', [
55 actions,
56 createBook()
57 ])
58 return composer
59 }
60}
61

Built with git-ssb-web