git ssb

3+

arj / patchbook



Commit 24301103fc79102ebc4d71e1454571b15c58592e

Move operations on book to book obs

Anders Rune Jensen committed on 10/21/2017, 7:38:11 PM
Parent: 6f235a7cc8f659d8d2ad8c0d4b0815d19b749970

Files changed

book/html/layout/detail.jsadded
book/html/layout/detail.mcssadded
book/html/authors.jsadded
book/obs/book.jschanged
book/obs/struct.jsadded
book/pull/db.jschanged
book/html/layout/detail.jsView
@@ -1,0 +1,57 @@
1 +const nest = require('depnest')
2 +const { h, when, computed } = require('mutant')
3 +
4 +exports.needs = nest({
5 + 'about.html.link': 'first',
6 + 'blob.sync.url': 'first',
7 + 'book.obs.book': 'first',
8 + 'message.html': {
9 + 'markdown': 'first'
10 + },
11 + 'book.html': {
12 + 'title': 'first',
13 + 'description': 'first'
14 + }
15 +})
16 +
17 +exports.gives = nest('book.html.layout')
18 +
19 +exports.create = (api) => {
20 + return nest('book.html.layout', bookLayout)
21 +
22 + function bookLayout (msg, opts) {
23 + if (!(opts.layout === undefined || opts.layout === 'detail')) return
24 +
25 + const { obs, isEditing, isCard } = opts
26 +
27 + const { title, authors, description } = api.book.html
28 + let book = api.book.obs.book(msg.key)
29 +
30 + return h('Message -book-detail', [
31 + h('.toggle-layout', {
32 + 'ev-click': e => {
33 + e.preventDefault()
34 + isCard.set(true)
35 + }
36 + }, '-'),
37 + title({ title: obs.title, msg, isEditing, onUpdate: book.title.set }),
38 + h('section.content', [
39 + //images({images: obs.images, msg, isEditing, onUpdate: book.images.add}),
40 + h('section.authors', authors({authors: obs.authors, isEditing, onUpdate: book.authors.set})),
41 + h('section.description', description({description: obs.description, isEditing, onUpdate: book.description.set})),
42 + //h('section.time', startDateTime({startDateTime: obs.startDateTime, msg, isEditing, onUpdate: editedGathering.startDateTime.set})),
43 + ]),
44 + h('section.actions', [
45 + h('button.edit', { 'ev-click': () => isEditing.set(!isEditing()) }, when(isEditing, 'Cancel', 'Edit')),
46 + when(isEditing, h('button', {'ev-click': () => save(book)}, 'Update'))
47 + ])
48 + ])
49 +
50 + function save (obs) {
51 + // FIXME: check if anything changed
52 + book.amend()
53 +
54 + isEditing.set(false)
55 + }
56 + }
57 +}
book/html/layout/detail.mcssView
@@ -1,0 +1,78 @@
1 +Message -book-detail {
2 + div.toggle-layout {
3 + font-size: 1rem
4 + cursor: pointer
5 + position: absolute
6 + top: 2rem
7 +
8 + width: 1rem
9 + display: flex
10 + justify-content: center
11 +
12 + border: 1px solid #fff
13 +
14 + :hover {
15 + border: 1px solid gainsboro
16 + }
17 + }
18 +
19 + section.title {
20 + font-size: 2rem
21 +
22 + input {
23 + font-size: 2rem
24 + border: 1px solid gainsboro
25 + }
26 + }
27 +
28 + section.content {
29 + section {
30 + margin-bottom: 1rem
31 + }
32 + section.images {
33 + }
34 +
35 + section.description {
36 + min-height: 3rem
37 + }
38 +
39 + section.time {
40 + min-height: 4rem
41 + (input) {
42 + font-size: 1rem
43 + border: 1px solid gainsboro
44 + }
45 +
46 + }
47 +
48 + section.actions {
49 + display: flex
50 + flex-basis: 100%
51 + justify-content: flex-end
52 + }
53 + }
54 +
55 + section.actions {
56 + display: flex
57 + justify-content: flex-start
58 +
59 + button.attend {
60 + margin-left: 0
61 + }
62 +
63 + button.edit {
64 + margin-left: auto
65 + }
66 +
67 + }
68 +}
69 +
70 +StartDateTime {
71 + div {
72 + input {
73 + border: 1px solid gainsboro
74 + font-size: 1em
75 + width: 16rem
76 + }
77 + }
78 +}
book/html/authors.jsView
@@ -1,0 +1,22 @@
1 +const nest = require('depnest')
2 +const { h, when } = require('mutant')
3 +
4 +exports.needs = nest({
5 + 'blob.sync.url': 'first'
6 +})
7 +
8 +exports.gives = nest(
9 + 'book.html.authors'
10 +)
11 +
12 +exports.create = (api) => {
13 + return nest('book.html.authors', authors)
14 + function authors ({authors, isEditing, onUpdate}) {
15 + return h('section.authors',
16 + when(isEditing,
17 + h('input', {'ev-input': e => onUpdate(e.target.value), value: authors}),
18 + h('span', authors)
19 + )
20 + )
21 + }
22 +}
book/obs/book.jsView
@@ -3,24 +3,57 @@
33 const { Value, Struct } = require('mutant')
44
55 exports.needs = nest({
66 'book.pull.get': 'first',
7- 'blob.sync.url': 'first'
7 + 'book.obs.struct': 'first',
8 + 'blob.sync.url': 'first',
9 + 'sbot.async.publish': 'first'
810 })
911
1012 exports.gives = nest('book.obs.book')
1113
1214 exports.create = function (api) {
1315 return nest('book.obs.book', function (id) {
1416 if (!ref.isLink(id)) throw new Error('a valid id must be specified')
1517
16- let book = api.book.pull.get(id)
17- const s = Struct()
18-
19- Object.keys(book).forEach(k => {
20- if (book[k])
21- s[k].set(book[k])
18 + let book = api.book.obs.struct({ key: id })
19 + api.book.pull.get(id, dbBook => {
20 + // FIXME: subjective
21 + Object.keys(dbBook.common).forEach((k) => {
22 + if (dbBook.common[k]) {
23 + book.common[k].set(dbBook.common[k])
24 + }
25 + })
2226 })
2327
24- return s
28 + // FIXME: usage
29 + book.create = function(commonObj, subjectiveObj, cb)
30 + {
31 + api.sbot.async.publish({ type: 'bookclub',
32 + common: commonObj,
33 + subjective: subjectiveObj }, cb)
34 + }
35 +
36 + book.amend = function(cb)
37 + {
38 + let msg = { type: 'bookclub-update', root: id }
39 +
40 + if (book.common) {
41 + msg.common = {}
42 + Object.keys(book.common).forEach((k) => {
43 + if (book.common[k]) {
44 + msg.common[k] = book.common[k]()
45 + }
46 + })
47 + }
48 +
49 + /* FIXME
50 + if (book.subjective)
51 + msg.subjective = subjectiveObj
52 + */
53 +
54 + api.sbot.async.publish(msg, cb)
55 + }
56 +
57 + return book
2558 })
2659 }
book/obs/struct.jsView
@@ -1,0 +1,28 @@
1 +const nest = require('depnest')
2 +const { Value, Set, Struct, forEachPair } = require('mutant')
3 +
4 +exports.gives = nest('book.obs.struct')
5 +
6 +exports.create = function (api) {
7 + return nest('book.obs.struct', function (opts = {}) {
8 + const struct = Struct({
9 + key: Value(''),
10 + common: {
11 + title: Value(''),
12 + authors: Value(''),
13 + description: Value(''),
14 + images: Set([])
15 + },
16 + subjective: Set([])
17 + })
18 +
19 + // FIXME: subjective
20 + Object.keys(opts.common).forEach((k) => {
21 + if (opts.common[k]) {
22 + struct.common[k].set(opts.common[k])
23 + }
24 + })
25 +
26 + return struct
27 + })
28 +}
book/pull/db.jsView
@@ -7,39 +7,18 @@
77
88 exports.needs = nest({
99 'sbot.pull.messagesByType': 'first',
1010 'sbot.pull.links': 'first',
11- 'sbot.async.get': 'first',
12- 'sbot.async.publish': 'first'
11 + 'sbot.async.get': 'first'
1312 })
1413
1514 exports.create = function (api) {
1615
1716 return nest({
1817 'book.pull.get': get,
19- 'book.pull.getAll': getAll,
20- 'book.pull.create': create,
21- 'book.pull.amend': amend
18 + 'book.pull.getAll': getAll
2219 })
2320
24- function create(commonObj, subjectiveObj, cb)
25- {
26- api.sbot.async.publish({ type: 'bookclub',
27- common: commonObj,
28- subjective: subjectiveObj }, cb)
29- }
30-
31- function amend(id, commonObj, subjectiveObj, cb)
32- {
33- let msg = { type: 'bookclub-update', root: id }
34- if (commonObj)
35- msg.common = commonObj
36- if (subjectiveObj)
37- msg.subjective = subjectiveObj
38-
39- api.sbot.async.publish(msg, cb)
40- }
41-
4221 function get(key, cb) {
4322 pull(
4423 api.sbot.async.get(key),
4524 pull.asyncMap(hydrate),

Built with git-ssb-web