git ssb

3+

arj / patchbook



Commit f3fe7055afd7792fb682ade4e2edd1a11fa6b52b

Add subjective, still WIP

Anders Rune Jensen committed on 10/28/2017, 7:08:33 PM
Parent: f646c4d5bfd0bda1440d876918e13f1934de7c7d

Files changed

book/html/layout/card.jschanged
book/html/layout/card.mcsschanged
book/html/layout/detail.jschanged
book/html/layout/detail.mcsschanged
book/obs/book.jschanged
book/obs/struct.jschanged
book/pull/db.jschanged
book/html/layout/card.jsView
@@ -1,7 +1,6 @@
11 const nest = require('depnest')
2-const { h, computed } = require('mutant')
3-const spacetime = require('spacetime')
2 +const { h } = require('mutant')
43
54 exports.needs = nest({
65 'message.html': {
76 backlinks: 'first',
@@ -9,10 +8,8 @@
98 action: 'map',
109 timestamp: 'first'
1110 },
1211 'about.html.image': 'first',
13- 'about.obs.color': 'first',
14- 'blob.sync.url': 'first',
1512 'book.obs.book': 'first',
1613 'book.html': {
1714 description: 'first',
1815 title: 'first',
book/html/layout/card.mcssView
@@ -54,6 +54,5 @@
5454 }
5555 }
5656 }
5757 }
58-}
59-
58 +}
book/html/layout/detail.jsView
@@ -1,11 +1,10 @@
11 const nest = require('depnest')
22 const { h, when, computed } = require('mutant')
33
44 exports.needs = nest({
5- 'about.html.link': 'first',
6- 'blob.sync.url': 'first',
75 'book.obs.book': 'first',
6 + 'about.html.image': 'first',
87 'message.html': {
98 'markdown': 'first'
109 },
1110 'book.html': {
@@ -20,24 +19,65 @@
2019
2120 exports.create = (api) => {
2221 return nest('book.html.layout', bookLayout)
2322
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 +
2439 function bookLayout (msg, opts) {
2540 if (!(opts.layout === undefined || opts.layout === 'detail')) return
2641
2742 const { obs, isEditing, isCard } = opts
2843
2944 const { title, authors, description, images } = api.book.html
3045
46 + let reviews = []
47 +
3148 return h('Message -book-detail', [
3249 title({ title: obs.title, msg, isEditing, onUpdate: obs.title.set }),
3350 authors({authors: obs.authors, isEditing, onUpdate: obs.authors.set}),
3451 h('section.content', [
3552 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})),
3755 ]),
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 + ]),
3877 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')),
4080 when(isEditing, h('button', {'ev-click': () => save(obs)}, 'Update'))
4181 ])
4282 ])
4383
book/html/layout/detail.mcssView
@@ -1,13 +1,30 @@
11 Message -book-detail {
22 display: block
33
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 +
422 section.title {
523 font-size: 2rem
624
725 input {
826 font-size: 2rem
9- border: 1px solid gainsboro
1027 }
1128 }
1229
1330 section.authors {
book/obs/book.jsView
@@ -1,7 +1,7 @@
11 const nest = require('depnest')
22 const ref = require('ssb-ref')
3-const { Value, Struct } = require('mutant')
3 +const { Value, Struct, Dict } = require('mutant')
44
55 exports.needs = nest({
66 'book.pull.get': 'first',
77 'book.obs.struct': 'first',
@@ -15,14 +15,21 @@
1515 if (!ref.isLink(id)) throw new Error('a valid id must be specified')
1616
1717 let book = api.book.obs.struct({ key: id })
1818 api.book.pull.get(id, dbBook => {
19- // FIXME: subjective
2019 Object.keys(dbBook.common).forEach((k) => {
2120 if (dbBook.common[k]) {
2221 book[k].set(dbBook.common[k])
2322 }
2423 })
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 + })
2532 })
2633
2734 book.amend = function(cb)
2835 {
book/obs/struct.jsView
@@ -1,6 +1,6 @@
11 const nest = require('depnest')
2-const { Value, Set, Struct, forEachPair } = require('mutant')
2 +const { Value, Set, Dict, Struct, forEachPair } = require('mutant')
33
44 exports.needs = nest({
55 'sbot.async.publish': 'first'
66 })
@@ -14,9 +14,9 @@
1414 title: Value(''),
1515 authors: Value(''),
1616 description: Value(''),
1717 images: Set([]),
18- subjective: Set([])
18 + subjective: Dict()
1919 })
2020
2121 struct.create = function(cb)
2222 {
book/pull/db.jsView
@@ -60,9 +60,10 @@
6060 key: key,
6161 common: msg.content.common,
6262 subjective: {}
6363 }
64- book.subjective[msg.author] = msg.content.subjective
64 + book.subjective[msg.author] = msg.content.subjective ||
65 + { rating: '', ratingType: '', review: '', shelve: '', genre: '' }
6566
6667 applyAmends(book, cb)
6768 }
6869 }

Built with git-ssb-web