Commit f3fe7055afd7792fb682ade4e2edd1a11fa6b52b
Add subjective, still WIP
Anders Rune Jensen committed on 10/28/2017, 7:08:33 PMParent: f646c4d5bfd0bda1440d876918e13f1934de7c7d
Files changed
book/html/layout/card.js | changed |
book/html/layout/card.mcss | changed |
book/html/layout/detail.js | changed |
book/html/layout/detail.mcss | changed |
book/obs/book.js | changed |
book/obs/struct.js | changed |
book/pull/db.js | changed |
book/html/layout/card.js | ||
---|---|---|
@@ -1,7 +1,6 @@ | ||
1 | 1 … | const nest = require('depnest') |
2 | -const { h, computed } = require('mutant') | |
3 | -const spacetime = require('spacetime') | |
2 … | +const { h } = require('mutant') | |
4 | 3 … | |
5 | 4 … | exports.needs = nest({ |
6 | 5 … | 'message.html': { |
7 | 6 … | backlinks: 'first', |
@@ -9,10 +8,8 @@ | ||
9 | 8 … | action: 'map', |
10 | 9 … | timestamp: 'first' |
11 | 10 … | }, |
12 | 11 … | 'about.html.image': 'first', |
13 | - 'about.obs.color': 'first', | |
14 | - 'blob.sync.url': 'first', | |
15 | 12 … | 'book.obs.book': 'first', |
16 | 13 … | 'book.html': { |
17 | 14 … | description: 'first', |
18 | 15 … | title: 'first', |
book/html/layout/detail.js | |||
---|---|---|---|
@@ -1,11 +1,10 @@ | |||
1 | 1 … | const nest = require('depnest') | |
2 | 2 … | const { h, when, computed } = require('mutant') | |
3 | 3 … | ||
4 | 4 … | exports.needs = nest({ | |
5 | - 'about.html.link': 'first', | ||
6 | - 'blob.sync.url': 'first', | ||
7 | 5 … | 'book.obs.book': 'first', | |
6 … | + 'about.html.image': 'first', | ||
8 | 7 … | 'message.html': { | |
9 | 8 … | 'markdown': 'first' | |
10 | 9 … | }, | |
11 | 10 … | 'book.html': { | |
@@ -20,24 +19,65 @@ | |||
20 | 19 … | ||
21 | 20 … | exports.create = (api) => { | |
22 | 21 … | return nest('book.html.layout', bookLayout) | |
23 | 22 … | ||
23 … | + function simpleEdit(isEditing, name, value) { | ||
24 … | + return h('div', [h('span', name), | ||
25 … | + when(isEditing, | ||
26 … | + h('input', {'ev-input': e => value.set(e.target.value), value: value() }), | ||
27 … | + h('span', value))]) | ||
28 … | + | ||
29 … | + } | ||
30 … | + | ||
31 … | + function textEdit(isEditing, name, value) { | ||
32 … | + const markdown = api.message.html.markdown | ||
33 … | + const input = h('textarea', {'ev-input': e => value.set(e.target.value), value: value() }) | ||
34 … | + | ||
35 … | + return h('div', [h('span', name), | ||
36 … | + when(isEditing, input, computed(value, markdown))]) | ||
37 … | + } | ||
38 … | + | ||
24 | 39 … | function bookLayout (msg, opts) { | |
25 | 40 … | if (!(opts.layout === undefined || opts.layout === 'detail')) return | |
26 | 41 … | ||
27 | 42 … | const { obs, isEditing, isCard } = opts | |
28 | 43 … | ||
29 | 44 … | const { title, authors, description, images } = api.book.html | |
30 | 45 … | ||
46 … | + let reviews = [] | ||
47 … | + | ||
31 | 48 … | return h('Message -book-detail', [ | |
32 | 49 … | title({ title: obs.title, msg, isEditing, onUpdate: obs.title.set }), | |
33 | 50 … | authors({authors: obs.authors, isEditing, onUpdate: obs.authors.set}), | |
34 | 51 … | h('section.content', [ | |
35 | 52 … | images({images: obs.images, isEditing, onUpdate: obs.images.add }), | |
36 | - h('section.description', description({description: obs.description, isEditing, onUpdate: obs.description.set})), | ||
53 … | + h('section.description', | ||
54 … | + description({description: obs.description, isEditing, onUpdate: obs.description.set})), | ||
37 | 55 … | ]), | |
56 … | + h('section.subjective', [ | ||
57 … | + computed(obs.subjective, subjectives => { | ||
58 … | + let i = 0; | ||
59 … | + Object.keys(subjectives).forEach(user => { | ||
60 … | + if (i++ < reviews.length) return | ||
61 … | + let subjective = obs.subjective.get(user) | ||
62 … | + reviews.push([ | ||
63 … | + h('section.avatar', {}, api.about.html.image(user)), | ||
64 … | + h('section', [ | ||
65 … | + textEdit(isEditing, 'Review', subjective.review), | ||
66 … | + simpleEdit(isEditing, 'Rating', subjective.rating), | ||
67 … | + simpleEdit(isEditing, 'Rating type', subjective.ratingType), | ||
68 … | + simpleEdit(isEditing, 'Shelve', subjective.shelve), | ||
69 … | + simpleEdit(isEditing, 'Genre', subjective.genre) | ||
70 … | + ]) | ||
71 … | + ]) | ||
72 … | + }) | ||
73 … | + | ||
74 … | + return reviews | ||
75 … | + }) | ||
76 … | + ]), | ||
38 | 77 … | h('section.actions', [ | |
39 | - h('button.edit', { 'ev-click': () => isEditing.set(!isEditing()) }, when(isEditing, 'Cancel', 'Edit')), | ||
78 … | + h('button.edit', { 'ev-click': () => isEditing.set(!isEditing()) }, | ||
79 … | + when(isEditing, 'Cancel', 'Edit')), | ||
40 | 80 … | when(isEditing, h('button', {'ev-click': () => save(obs)}, 'Update')) | |
41 | 81 … | ]) | |
42 | 82 … | ]) | |
43 | 83 … |
book/html/layout/detail.mcss | ||
---|---|---|
@@ -1,13 +1,30 @@ | ||
1 | 1 … | Message -book-detail { |
2 | 2 … | display: block |
3 | 3 … | |
4 … | + section.title, section.authors { | |
5 … | + input { | |
6 … | + border: 1px solid gainsboro | |
7 … | + } | |
8 … | + } | |
9 … | + | |
10 … | + section.subjective { | |
11 … | + column-count: 2 | |
12 … | + | |
13 … | + section { | |
14 … | + div { | |
15 … | + textarea, input { | |
16 … | + border: 1px solid gainsboro | |
17 … | + } | |
18 … | + } | |
19 … | + } | |
20 … | + } | |
21 … | + | |
4 | 22 … | section.title { |
5 | 23 … | font-size: 2rem |
6 | 24 … | |
7 | 25 … | input { |
8 | 26 … | font-size: 2rem |
9 | - border: 1px solid gainsboro | |
10 | 27 … | } |
11 | 28 … | } |
12 | 29 … | |
13 | 30 … | section.authors { |
book/obs/book.js | ||
---|---|---|
@@ -1,7 +1,7 @@ | ||
1 | 1 … | const nest = require('depnest') |
2 | 2 … | const ref = require('ssb-ref') |
3 | -const { Value, Struct } = require('mutant') | |
3 … | +const { Value, Struct, Dict } = require('mutant') | |
4 | 4 … | |
5 | 5 … | exports.needs = nest({ |
6 | 6 … | 'book.pull.get': 'first', |
7 | 7 … | 'book.obs.struct': 'first', |
@@ -15,14 +15,21 @@ | ||
15 | 15 … | if (!ref.isLink(id)) throw new Error('a valid id must be specified') |
16 | 16 … | |
17 | 17 … | let book = api.book.obs.struct({ key: id }) |
18 | 18 … | api.book.pull.get(id, dbBook => { |
19 | - // FIXME: subjective | |
20 | 19 … | Object.keys(dbBook.common).forEach((k) => { |
21 | 20 … | if (dbBook.common[k]) { |
22 | 21 … | book[k].set(dbBook.common[k]) |
23 | 22 … | } |
24 | 23 … | }) |
24 … | + | |
25 … | + Object.keys(dbBook.subjective).forEach((k) => { | |
26 … | + var d = {} | |
27 … | + Object.keys(dbBook.subjective[k]).forEach((v) => { | |
28 … | + d[v] = Value(dbBook.subjective[k][v]) | |
29 … | + }) | |
30 … | + book.subjective.put(k, Struct(d)) | |
31 … | + }) | |
25 | 32 … | }) |
26 | 33 … | |
27 | 34 … | book.amend = function(cb) |
28 | 35 … | { |
book/obs/struct.js | ||
---|---|---|
@@ -1,6 +1,6 @@ | ||
1 | 1 … | const nest = require('depnest') |
2 | -const { Value, Set, Struct, forEachPair } = require('mutant') | |
2 … | +const { Value, Set, Dict, Struct, forEachPair } = require('mutant') | |
3 | 3 … | |
4 | 4 … | exports.needs = nest({ |
5 | 5 … | 'sbot.async.publish': 'first' |
6 | 6 … | }) |
@@ -14,9 +14,9 @@ | ||
14 | 14 … | title: Value(''), |
15 | 15 … | authors: Value(''), |
16 | 16 … | description: Value(''), |
17 | 17 … | images: Set([]), |
18 | - subjective: Set([]) | |
18 … | + subjective: Dict() | |
19 | 19 … | }) |
20 | 20 … | |
21 | 21 … | struct.create = function(cb) |
22 | 22 … | { |
book/pull/db.js | ||
---|---|---|
@@ -60,9 +60,10 @@ | ||
60 | 60 … | key: key, |
61 | 61 … | common: msg.content.common, |
62 | 62 … | subjective: {} |
63 | 63 … | } |
64 | - book.subjective[msg.author] = msg.content.subjective | |
64 … | + book.subjective[msg.author] = msg.content.subjective || | |
65 … | + { rating: '', ratingType: '', review: '', shelve: '', genre: '' } | |
65 | 66 … | |
66 | 67 … | applyAmends(book, cb) |
67 | 68 … | } |
68 | 69 … | } |
Built with git-ssb-web