Commit fd2459df8b46e1e0fe589fc20f3d16020399d671
Add comments to subjective, wip
Anders Rune Jensen committed on 12/29/2017, 9:00:01 PMParent: 1d5d3beb765e9f7bb08097a0896eb8ea83eeccca
Files changed
book/async/get.js | changed |
book/html/layout/detail.js | changed |
book/html/layout/detail.mcss | changed |
book/obs/book.js | changed |
book/async/get.js | ||
---|---|---|
@@ -32,24 +32,57 @@ | ||
32 | 32 … | key, |
33 | 33 … | common: msg.content, |
34 | 34 … | subjective: { |
35 | 35 … | [api.keys.sync.id()]: { |
36 | - rating: '', ratingType: '', review: '', shelve: '', genre: '' | |
36 … | + key: '', rating: '', ratingType: '', review: '', shelve: '', genre: '', comments: [] | |
37 | 37 … | } |
38 | 38 … | } |
39 | 39 … | } |
40 | 40 … | |
41 | 41 … | cb(book) |
42 | 42 … | |
43 | - applyAmends(book, cb) | |
43 … | + applyAmends(book, updatedBook => | |
44 … | + getCommentsOnSubjective(updatedBook, cb)) | |
44 | 45 … | } |
45 | 46 … | |
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 … | + | |
46 | 73 … | function applyAmends(book, cb) { |
47 | 74 … | 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 | |
49 | 79 … | pull.filter(data => data.key), |
50 | 80 … | 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 … | + }) | |
52 | 85 … | }), |
53 | 86 … | sort((a, b) => a.timestamp - b.timestamp), |
54 | 87 … | pull.drain(msg => { |
55 | 88 … | if (msg.content.type !== "about") return |
@@ -57,13 +90,15 @@ | ||
57 | 90 … | const { rating, ratingType, shelve, genre, review } = msg.content |
58 | 91 … | |
59 | 92 … | if (rating || ratingType || shelve || genre || review) { |
60 | 93 … | book.subjective[msg.author] = { |
94 … | + key: msg.key, | |
61 | 95 … | rating, |
62 | 96 … | ratingType, |
63 | 97 … | shelve, |
64 | 98 … | genre, |
65 | - review | |
99 … | + review, | |
100 … | + comments: [] | |
66 | 101 … | } |
67 | 102 … | } else |
68 | 103 … | book.common = Object.assign({}, book.common, msg.content) |
69 | 104 … |
book/html/layout/detail.js | |||
---|---|---|---|
@@ -1,6 +1,6 @@ | |||
1 | 1 … | const nest = require('depnest') | |
2 | -const { h, when, computed, Value } = require('mutant') | ||
2 … | +const { h, when, computed, Value, map } = require('mutant') | ||
3 | 3 … | const addSuggest = require('suggest-box') | |
4 | 4 … | ||
5 | 5 … | exports.needs = nest({ | |
6 | 6 … | 'book.obs.book': 'first', | |
@@ -130,8 +130,14 @@ | |||
130 | 130 … | ratingTypeEdit(isOwnEditingSubj, subjective.ratingType)]), | |
131 | 131 … | simpleEdit(isOwnEditingSubj, 'Shelve', subjective.shelve), | |
132 | 132 … | simpleEdit(isOwnEditingSubj, 'Genre', subjective.genre), | |
133 | 133 … | 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 … | + })), | ||
134 | 140 … | h('section.actions', | |
135 | 141 … | when(isMe, [ | |
136 | 142 … | h('button.subjective', { 'ev-click': editRatingClick }, | |
137 | 143 … | when(isEditingSubjective, 'Cancel', 'Edit my rating')), |
book/html/layout/detail.mcss | ||
---|---|---|
@@ -87,8 +87,29 @@ | ||
87 | 87 … | margin-top: -0.2em; |
88 | 88 … | } |
89 | 89 … | } |
90 | 90 … | } |
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 … | + } | |
91 | 112 … | } |
92 | 113 … | |
93 | 114 … | section.title { |
94 | 115 … | font-size: 2rem |
book/obs/book.js | ||
---|---|---|
@@ -76,7 +76,19 @@ | ||
76 | 76 … | |
77 | 77 … | api.sbot.async.publish(msg, cb) |
78 | 78 … | } |
79 | 79 … | |
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 … | + | |
80 | 92 … | return book |
81 | 93 … | }) |
82 | 94 … | } |
Built with git-ssb-web