git ssb

3+

arj / patchbook



Commit fd2459df8b46e1e0fe589fc20f3d16020399d671

Add comments to subjective, wip

Anders Rune Jensen committed on 12/29/2017, 9:00:01 PM
Parent: 1d5d3beb765e9f7bb08097a0896eb8ea83eeccca

Files changed

book/async/get.jschanged
book/html/layout/detail.jschanged
book/html/layout/detail.mcsschanged
book/obs/book.jschanged
book/async/get.jsView
@@ -32,24 +32,57 @@
3232 key,
3333 common: msg.content,
3434 subjective: {
3535 [api.keys.sync.id()]: {
36- rating: '', ratingType: '', review: '', shelve: '', genre: ''
36 + key: '', rating: '', ratingType: '', review: '', shelve: '', genre: '', comments: []
3737 }
3838 }
3939 }
4040
4141 cb(book)
4242
43- applyAmends(book, cb)
43 + applyAmends(book, updatedBook =>
44 + getCommentsOnSubjective(updatedBook, cb))
4445 }
4546
47 + function getCommentsOnSubjective(book, cb)
48 + {
49 + pull(
50 + pull.values(Object.values(book.subjective)),
51 + pull.drain(subj => {
52 + if (subj.key) {
53 + pull(
54 + api.sbot.pull.links({ dest: subj.key }),
55 + pull.filter(data => data.key),
56 + pull.asyncMap((data, cb) => {
57 + api.sbot.async.get(data.key, cb)
58 + }),
59 + sort((a, b) => a.timestamp - b.timestamp),
60 + pull.drain(msg => {
61 + if (msg.content.type !== "post") return
62 +
63 + // FIXME: links is buggy and returns the same message twice
64 + if (!subj.comments.some(c => c.content.text == msg.content.text))
65 + subj.comments.push(msg)
66 + }, () => cb(book))
67 + )
68 + }
69 + }, () => cb(book))
70 + )
71 + }
72 +
4673 function applyAmends(book, cb) {
4774 pull(
48- api.sbot.pull.links({ dest: book.key }), // FIXME: can't do live together with sorting and links doesn't support timestamp
75 + api.sbot.pull.links({ dest: book.key }), // FIXME: can't do live
76 + // together with
77 + // sorting and links
78 + // doesn't support timestamp
4979 pull.filter(data => data.key),
5080 pull.asyncMap((data, cb) => {
51- api.sbot.async.get(data.key, cb)
81 + api.sbot.async.get(data.key, (err, msg) => {
82 + msg.key = data.key
83 + cb(err, msg)
84 + })
5285 }),
5386 sort((a, b) => a.timestamp - b.timestamp),
5487 pull.drain(msg => {
5588 if (msg.content.type !== "about") return
@@ -57,13 +90,15 @@
5790 const { rating, ratingType, shelve, genre, review } = msg.content
5891
5992 if (rating || ratingType || shelve || genre || review) {
6093 book.subjective[msg.author] = {
94 + key: msg.key,
6195 rating,
6296 ratingType,
6397 shelve,
6498 genre,
65- review
99 + review,
100 + comments: []
66101 }
67102 } else
68103 book.common = Object.assign({}, book.common, msg.content)
69104
book/html/layout/detail.jsView
@@ -1,6 +1,6 @@
11 const nest = require('depnest')
2-const { h, when, computed, Value } = require('mutant')
2 +const { h, when, computed, Value, map } = require('mutant')
33 const addSuggest = require('suggest-box')
44
55 exports.needs = nest({
66 'book.obs.book': 'first',
@@ -130,8 +130,14 @@
130130 ratingTypeEdit(isOwnEditingSubj, subjective.ratingType)]),
131131 simpleEdit(isOwnEditingSubj, 'Shelve', subjective.shelve),
132132 simpleEdit(isOwnEditingSubj, 'Genre', subjective.genre),
133133 textEdit(isOwnEditingSubj, 'Review', subjective.review),
134 + h('section.comments', map(subjective.comments, com => {
135 + return h('div',
136 + [api.about.html.image(com.author),
137 + // FIXME: time, in general like cards
138 + h('span.text', computed(com.content.text, api.message.html.markdown))])
139 + })),
134140 h('section.actions',
135141 when(isMe, [
136142 h('button.subjective', { 'ev-click': editRatingClick },
137143 when(isEditingSubjective, 'Cancel', 'Edit my rating')),
book/html/layout/detail.mcssView
@@ -87,8 +87,29 @@
8787 margin-top: -0.2em;
8888 }
8989 }
9090 }
91 +
92 + section.comments {
93 + div {
94 + img.Avatar {
95 + width: 2rem;
96 + height: 2rem;
97 + margin-right: 0.5rem
98 + }
99 +
100 + span.text {
101 + vertical-align: text-bottom
102 +
103 + img.emoji {
104 + height: 1.2em;
105 + width: 1.2em;
106 + vertical-align: middle;
107 + margin-top: -0.2em;
108 + }
109 + }
110 + }
111 + }
91112 }
92113
93114 section.title {
94115 font-size: 2rem
book/obs/book.jsView
@@ -76,7 +76,19 @@
7676
7777 api.sbot.async.publish(msg, cb)
7878 }
7979
80 + book.addCommentToSubjective = function(subjectiveId, comment, cb)
81 + {
82 + /*
83 + "content": {
84 + "type": "post",
85 + "root": "%THGnuD1d3cnVaa9+d6mIxE9dBktlKc3UwrjlKWmVE+M=.sha256", <- about
86 + "branch": "%THGnuD1d3cnVaa9+d6mIxE9dBktlKc3UwrjlKWmVE+M=.sha256", <- prev
87 + "text": "testing comment"
88 + }
89 + */
90 + }
91 +
8092 return book
8193 })
8294 }

Built with git-ssb-web