Commit 9945dff06b2cabb1aae9a03a535ea7cfc45729ea
votes render, but the star button doesn't quite reflect if you've voted yet
Ev Bogue committed on 6/1/2018, 8:43:25 PMParent: d7d4e4991854c117c786361a707e0ae793c73562
Files changed
tools.js | changed |
tools.js | ||
---|---|---|
@@ -10,56 +10,44 @@ | ||
10 | 10 … | var config = require('./config')() |
11 | 11 … | |
12 | 12 … | var id = require('./keys').id |
13 | 13 … | |
14 | -/*function votes (msg) { | |
15 | - var votes = h('div.votes') | |
16 | - if (msg.key) { | |
17 | - pull( | |
18 | - sbot.links({dest: msg.key, rel: 'vote'}), | |
19 | - pull.drain(function (data) { | |
20 | - if (data) { | |
21 | - votes.appendChild(h('a', {href:'#' + data.key}, h('img.emoji', {src: config.emojiUrl + 'star.png'}))) | |
22 | - } else {console.log(data)} | |
23 | - }) | |
24 | - ) | |
25 | - } | |
26 | - return votes | |
27 | -}*/ | |
14 … | +function votes (msg) { | |
15 … | + var votes = h('div.votes') | |
28 | 16 … | |
29 | -function votes (msg) { | |
30 | - var votes = h('div.votes') | |
31 | - if (msg.key) { | |
32 | - console.log('Looking for votes') | |
33 | - pull( | |
34 | - sbot.backlinks({query: [{$filter: {value: {content: {type: 'vote', vote: {link: msg.key}}}}}], live: true}), | |
35 | - pull.drain(function (data) { | |
36 | - if (data.sync) { console.log('waiting for new votes')} | |
37 | - else if (data.value.content.vote.value == 1) { | |
38 | - votes.appendChild(h('a#vote:' + data.value.author.substring(0, 44), {href:'#' + data.value.author}, h('img.emoji', {src: config.emojiUrl + 'star.png'}))) | |
17 … | + pull( | |
18 … | + sbot.links({rel: 'vote', dest: msg.key }), | |
19 … | + pull.drain(function (link) { | |
20 … | + sbot.get(link.key, function (err, data) { | |
21 … | + if (err) throw err | |
22 … | + if (data.content.vote.value == 1) { | |
23 … | + votes.appendChild(h('a#vote:' + data.author.substring(0, 44), {href:'#' + data.author, title: avatar.name(data.author)}, h('img.emoji', {src: config.emojiUrl + 'star.png'}))) | |
39 | 24 … | } |
40 | - else if (data.value.content.vote.value == -1) { | |
41 | - var lookFor = 'vote:' + data.value.author.substring(0, 44) | |
25 … | + else if (data.content.vote.value == -1) { | |
26 … | + var lookFor = 'vote:' + data.author.substring(0, 44) | |
42 | 27 … | var remove = document.getElementById(lookFor) |
43 | 28 … | remove.parentNode.removeChild(remove) |
44 | - } | |
29 … | + } | |
45 | 30 … | }) |
46 | - ) | |
47 | - } | |
31 … | + }) | |
32 … | + ) | |
33 … | + | |
48 | 34 … | return votes |
49 | 35 … | } |
50 | 36 … | |
51 | 37 … | module.exports.star = function (msg) { |
38 … | + | |
52 | 39 … | var votebutton = h('span#star:' + msg.key.substring(0, 44)) |
40 … | + | |
41 … | + | |
53 | 42 … | var vote = { |
54 | 43 … | type: 'vote', |
55 | 44 … | vote: { link: msg.key, expression: 'Star' } |
56 | 45 … | } |
57 | 46 … | |
58 | - var star = h('button.btn.right', | |
47 … | + var star = h('button.btn.right', 'Star ', | |
59 | 48 … | h('img.emoji', {src: config.emojiUrl + 'star.png'}), { |
60 | 49 … | onclick: function () { |
61 | - console.log(vote) | |
62 | 50 … | vote.vote.value = 1 |
63 | 51 … | sbot.publish(vote, function (err, voted) { |
64 | 52 … | if(err) throw err |
65 | 53 … | console.log('Starred!', voted) |
@@ -68,9 +56,9 @@ | ||
68 | 56 … | } |
69 | 57 … | } |
70 | 58 … | ) |
71 | 59 … | |
72 | - var unstar = h('button.btn.right', | |
60 … | + var unstar = h('button.btn.right ', 'Unstar ', | |
73 | 61 … | h('img.emoji', {src: config.emojiUrl + 'stars.png'}), { |
74 | 62 … | onclick: function () { |
75 | 63 … | vote.vote.value = -1 |
76 | 64 … | sbot.publish(vote, function (err, voted) { |
@@ -81,33 +69,28 @@ | ||
81 | 69 … | } |
82 | 70 … | } |
83 | 71 … | ) |
84 | 72 … | |
85 | - pull( | |
86 | - sbot.backlinks({query: [{$filter: {value: {content: {type: 'vote', vote: {link: msg.key}}}}}]}), | |
87 | - pull.drain(function (data) { | |
88 | - if (data.sync) { } | |
89 | - else if (data.value.content.vote.value == 1) { | |
90 | - votebutton.replaceChild(unstar, star) | |
91 | - } | |
92 | - else if (data.value.content.vote.value == -1) { | |
93 | - votebutton.replaceChild(star, unstar) | |
94 | - } | |
95 | - }) | |
96 | - ) | |
73 … | + votebutton.appendChild(star) | |
74 … | + | |
97 | 75 … | /*pull( |
98 | - sbot.links({dest: msg.key, rel: 'vote', author: id}), | |
99 | - pull.drain(function (data) { | |
100 | - if (data) | |
101 | - console.log(data) | |
102 | - if (data.value.vote.value == 1) | |
103 | - votebutton.replaceChild(unstar, star) | |
104 | - else if (data.value.vote.value == -1) | |
105 | - votebutton.replaceChild(star, unstar) | |
76 … | + sbot.links({rel: 'vote', dest: msg.key}), | |
77 … | + pull.drain(function (link) { | |
78 … | + sbot.get(link.key, function (err, data) { | |
79 … | + if (err) throw err | |
80 … | + if (data.author == id) | |
81 … | + console.log(newbutton) | |
82 … | + console.log(data) | |
83 … | + if (data.content.vote.value == 1) { | |
84 … | + console.log(unstar) | |
85 … | + } | |
86 … | + else if (data.content.vote.value == -1) { | |
87 … | + console.log(star) | |
88 … | + } | |
89 … | + }) | |
106 | 90 … | }) |
107 | 91 … | )*/ |
108 | 92 … | |
109 | - votebutton.appendChild(star) | |
110 | 93 … | return votebutton |
111 | 94 … | } |
112 | 95 … | |
113 | 96 … | module.exports.timestamp = function (msg, edited) { |
Built with git-ssb-web