git ssb

2+

ev / mvd



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 PM
Parent: d7d4e4991854c117c786361a707e0ae793c73562

Files changed

tools.jschanged
tools.jsView
@@ -10,56 +10,44 @@
1010 var config = require('./config')()
1111
1212 var id = require('./keys').id
1313
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')
2816
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'})))
3924 }
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)
4227 var remove = document.getElementById(lookFor)
4328 remove.parentNode.removeChild(remove)
44- }
29 + }
4530 })
46- )
47- }
31 + })
32 + )
33 +
4834 return votes
4935 }
5036
5137 module.exports.star = function (msg) {
38 +
5239 var votebutton = h('span#star:' + msg.key.substring(0, 44))
40 +
41 +
5342 var vote = {
5443 type: 'vote',
5544 vote: { link: msg.key, expression: 'Star' }
5645 }
5746
58- var star = h('button.btn.right',
47 + var star = h('button.btn.right', 'Star ',
5948 h('img.emoji', {src: config.emojiUrl + 'star.png'}), {
6049 onclick: function () {
61- console.log(vote)
6250 vote.vote.value = 1
6351 sbot.publish(vote, function (err, voted) {
6452 if(err) throw err
6553 console.log('Starred!', voted)
@@ -68,9 +56,9 @@
6856 }
6957 }
7058 )
7159
72- var unstar = h('button.btn.right',
60 + var unstar = h('button.btn.right ', 'Unstar ',
7361 h('img.emoji', {src: config.emojiUrl + 'stars.png'}), {
7462 onclick: function () {
7563 vote.vote.value = -1
7664 sbot.publish(vote, function (err, voted) {
@@ -81,33 +69,28 @@
8169 }
8270 }
8371 )
8472
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 +
9775 /*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 + })
10690 })
10791 )*/
10892
109- votebutton.appendChild(star)
11093 return votebutton
11194 }
11295
11396 module.exports.timestamp = function (msg, edited) {

Built with git-ssb-web