Files: c8ebe98ed356a8b95e516ca561f755e05ed43156 / book / html / create.js
1805 bytesRaw
1 | const { h, when, Value } = require('mutant') |
2 | const nest = require('depnest') |
3 | |
4 | exports.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 | |
13 | exports.gives = nest('book.html.create') |
14 | |
15 | exports.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 | images({images: book.images, isEditing: true, onUpdate: book.images.add }), |
32 | h('div.authors', [h('label', 'Authors'), |
33 | h('input', {'ev-input': e => book.authors.set(e.target.value), |
34 | value: '' })]), |
35 | h('div.description', [h('label', 'Description'), |
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