Commit 634cfef04dcecb5941cb11eaaaa31fb511844f72
Create more or less working
Anders Rune Jensen committed on 10/22/2017, 7:56:37 PMParent: 06122043fa2db0b00c35584e6635056adfa5cf63
Files changed
book/html/create.js | changed |
book/html/layout/detail.mcss | changed |
book/html/create.mcss | added |
book/obs/book.js | changed |
book/obs/struct.js | changed |
book/html/create.js | ||
---|---|---|
@@ -1,5 +1,5 @@ | ||
1 | -const { h } = require('mutant') | |
1 … | +const { h, when, Value } = require('mutant') | |
2 | 2 … | const nest = require('depnest') |
3 | 3 … | |
4 | 4 … | exports.needs = nest({ |
5 | 5 … | 'blob.html.input': 'first', |
@@ -14,44 +14,48 @@ | ||
14 | 14 … | |
15 | 15 … | exports.gives = nest('book.html.create') |
16 | 16 … | |
17 | 17 … | exports.create = function (api) { |
18 … | + var showCreate = Value(false) | |
19 … | + | |
18 | 20 … | return nest({ 'book.html.create': create }) |
19 | 21 … | |
20 | 22 … | function createBook() { |
21 | - const { title, authors, description } = api.book.html | |
22 | 23 … | let book = api.book.obs.struct() |
23 | 24 … | |
24 | - return h('Message -book-detail', [ | |
25 | - title({ title: '', msg: { key: '' }, isEditing: true, onUpdate: book().common.title.set }), | |
25 … | + return h('Create -book', | |
26 … | + { classList: when(showCreate, '-expanded', '-contracted') }, [ | |
26 | 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: '' })]), | |
27 | 31 … | //images({images: obs.images, msg, isEditing, onUpdate: book.images.add}), |
28 | - h('section.authors', authors({authors: '', isEditing: true, | |
29 | - onUpdate: book().common.authors.set})), | |
30 | - h('section.description', description({description: '', | |
31 | - isEditing: true, | |
32 | - onUpdate: book().common.description.set})), | |
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: '' }) ]) | |
33 | 38 … | //h('section.time', startDateTime({startDateTime: obs.startDateTime, msg, isEditing, onUpdate: editedGathering.startDateTime.set})), |
34 | 39 … | ]), |
35 | 40 … | h('section.actions', [ |
36 | - h('button.edit', { 'ev-click': () => { | |
37 | - // FIXME: close? | |
38 | - }}, 'Cancel'), | |
41 … | + h('button', { 'ev-click': () => showCreate.set(false) }, 'Cancel'), | |
39 | 42 … | h('button', {'ev-click': () => save(book)}, 'Create book') |
40 | 43 … | ]) |
41 | 44 … | ]) |
42 | 45 … | |
43 | 46 … | function save (book) { |
44 | 47 … | book.create() |
45 | 48 … | |
46 | - // FIXME: close/update? | |
49 … | + showCreate.set(false) | |
47 | 50 … | } |
48 | 51 … | } |
49 | 52 … | |
50 | 53 … | function create () { |
51 | - const actions = h('button', {'ev-click': () => createBook()}, 'Create') | |
54 … | + const actions = h('button', {'ev-click': () => showCreate.set(true) }, 'Create') | |
52 | 55 … | const composer = h('div', [ |
53 | - actions | |
56 … | + actions, | |
57 … | + createBook() | |
54 | 58 … | ]) |
55 | 59 … | return composer |
56 | 60 … | } |
57 | 61 … | } |
book/html/layout/detail.mcss | ||
---|---|---|
@@ -55,16 +55,11 @@ | ||
55 | 55 … | section.actions { |
56 | 56 … | display: flex |
57 | 57 … | justify-content: flex-start |
58 | 58 … | |
59 | - button.attend { | |
60 | - margin-left: 0 | |
61 | - } | |
62 | - | |
63 | 59 … | button.edit { |
64 | 60 … | margin-left: auto |
65 | 61 … | } |
66 | - | |
67 | 62 … | } |
68 | 63 … | } |
69 | 64 … | |
70 | 65 … | StartDateTime { |
book/html/create.mcss | ||
---|---|---|
@@ -1,0 +1,30 @@ | ||
1 … | +Create -book { | |
2 … | + section.content input { | |
3 … | + margin-left: 5px | |
4 … | + border: 1px solid gainsboro | |
5 … | + } | |
6 … | + | |
7 … | + section.content textarea { | |
8 … | + margin-left: 5px | |
9 … | + border: 1px solid gainsboro | |
10 … | + } | |
11 … | + | |
12 … | + -contracted { | |
13 … | + section.actions { | |
14 … | + display: none | |
15 … | + } | |
16 … | + section.content { | |
17 … | + display: none | |
18 … | + } | |
19 … | + } | |
20 … | + | |
21 … | + -expanded { | |
22 … | + section.actions { | |
23 … | + display: block | |
24 … | + } | |
25 … | + section.content { | |
26 … | + display: block | |
27 … | + } | |
28 … | + } | |
29 … | +} | |
30 … | + |
book/obs/book.js | ||
---|---|---|
@@ -19,26 +19,28 @@ | ||
19 | 19 … | api.book.pull.get(id, dbBook => { |
20 | 20 … | // FIXME: subjective |
21 | 21 … | Object.keys(dbBook.common).forEach((k) => { |
22 | 22 … | if (dbBook.common[k]) { |
23 | - book.common[k].set(dbBook.common[k]) | |
23 … | + book[k].set(dbBook.common[k]) | |
24 | 24 … | } |
25 | 25 … | }) |
26 | 26 … | }) |
27 | 27 … | |
28 | 28 … | book.amend = function(cb) |
29 | 29 … | { |
30 | 30 … | let msg = { type: 'bookclub-update', root: id } |
31 | 31 … | |
32 | - if (book.common) { | |
33 | - msg.common = {} | |
34 | - Object.keys(book.common).forEach((k) => { | |
35 | - if (book.common[k]) { | |
36 | - msg.common[k] = book.common[k]() | |
37 | - } | |
38 | - }) | |
32 … | + let s = book() | |
33 … | + | |
34 … | + msg.common = { | |
35 … | + title: s.title, | |
36 … | + authors: s.authors, | |
37 … | + description: s.description | |
39 | 38 … | } |
40 | 39 … | |
40 … | + console.log(msg) | |
41 … | + return | |
42 … | + | |
41 | 43 … | /* FIXME |
42 | 44 … | if (book.subjective) |
43 | 45 … | msg.subjective = subjectiveObj |
44 | 46 … | */ |
book/obs/struct.js | ||
---|---|---|
@@ -6,35 +6,24 @@ | ||
6 | 6 … | exports.create = function (api) { |
7 | 7 … | return nest('book.obs.struct', function (opts = {}) { |
8 | 8 … | const struct = Struct({ |
9 | 9 … | key: Value(''), |
10 | - common: { | |
11 | - title: Value(''), | |
12 | - authors: Value(''), | |
13 | - description: Value(''), | |
14 | - images: Set([]) | |
15 | - }, | |
10 … | + title: Value(''), | |
11 … | + authors: Value(''), | |
12 … | + description: Value(''), | |
13 … | + images: Set([]), | |
16 | 14 … | subjective: Set([]) |
17 | 15 … | }) |
18 | 16 … | |
19 | - // FIXME: subjective | |
20 | - if (opts.common) { | |
21 | - Object.keys(opts.common).forEach((k) => { | |
22 | - if (opts.common[k]) { | |
23 | - struct.common[k].set(opts.common[k]) | |
24 | - } | |
25 | - }) | |
26 | - } | |
27 | - | |
28 | 17 … | struct.create = function(cb) |
29 | 18 … | { |
30 | - let commonObj = {} | |
31 | - Object.keys(struct.common).forEach((k) => { | |
32 | - if (struct.common[k]) { | |
33 | - commonObj[k] = struct.common[k]() | |
34 | - } | |
35 | - }) | |
19 … | + let s = struct() | |
36 | 20 … | |
21 … | + let commonObj = { | |
22 … | + title: s.title, | |
23 … | + authors: s.authors, | |
24 … | + description: s.description | |
25 … | + } | |
37 | 26 … | let subjectiveObj = null // FIXME |
38 | 27 … | |
39 | 28 … | console.log(commonObj) |
40 | 29 … | return |
Built with git-ssb-web