git ssb

2+

ev / mvd



Commit 8311621405027acca27d723deb46b8a202575b94

make everything work even if vote button isn\'t quite aware yet

Ev Bogue committed on 6/1/2018, 10:38:00 PM
Parent: 9945dff06b2cabb1aae9a03a535ea7cfc45729ea

Files changed

render.jschanged
tools.jschanged
render.jsView
@@ -84,8 +84,9 @@
8484 var compose = h('div#edit:' + msg.key.substring(0, 44), composer(opts, fallback))
8585 message.replaceChild(compose, message.lastElementChild)
8686 }
8787 }))
88 +
8889 buttons.appendChild(tools.star(msg))
8990 message.appendChild(buttons)
9091 return message
9192
tools.jsView
@@ -10,36 +10,11 @@
1010 var config = require('./config')()
1111
1212 var id = require('./keys').id
1313
14-function votes (msg) {
15- var votes = h('div.votes')
16-
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'})))
24- }
25- else if (data.content.vote.value == -1) {
26- var lookFor = 'vote:' + data.author.substring(0, 44)
27- var remove = document.getElementById(lookFor)
28- remove.parentNode.removeChild(remove)
29- }
30- })
31- })
32- )
33-
34- return votes
35-}
36-
3714 module.exports.star = function (msg) {
15 + var votebutton = h('span.star:' + msg.key.substring(0,44))
3816
39- var votebutton = h('span#star:' + msg.key.substring(0, 44))
40-
41-
4217 var vote = {
4318 type: 'vote',
4419 vote: { link: msg.key, expression: 'Star' }
4520 }
@@ -50,16 +25,16 @@
5025 vote.vote.value = 1
5126 sbot.publish(vote, function (err, voted) {
5227 if(err) throw err
5328 console.log('Starred!', voted)
54- votebutton.replaceChild(unstar, star)
29 + votebutton.replaceChild(unstar, star)
5530 })
5631 }
5732 }
5833 )
59-
60- var unstar = h('button.btn.right ', 'Unstar ',
61- h('img.emoji', {src: config.emojiUrl + 'stars.png'}), {
34 +
35 + var unstar = h('button.btn.right ', 'Unstar ',
36 + h('img.emoji', {src: config.emojiUrl + 'stars.png'}), {
6237 onclick: function () {
6338 vote.vote.value = -1
6439 sbot.publish(vote, function (err, voted) {
6540 if(err) throw err
@@ -69,29 +44,56 @@
6944 }
7045 }
7146 )
7247
73- votebutton.appendChild(star)
48 + votebutton.appendChild(star)
49 + /*if (votebutton) {
50 + if (votebutton.firstChild) {
51 + console.log(votebutton.firstChild)
52 + votebutton.removeChild(votebutton.firstChild)
53 + }
54 + if (msg.value.content.passedVote) {
55 + console.log(msg.value.content.passedVote)
56 + if (msg.value.content.passedVote == 1) {
57 + votebutton.appendChild(unstar)
58 + } else { votebutton.appendChild(star) }
59 + } else {
60 + }
61 + }*/
62 + return votebutton
63 +}
7464
75- /*pull(
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- }
65 +function votes (msg) {
66 + var votes = h('div.votes')
67 + if (msg.key) {
68 + pull(
69 + sbot.links({rel: 'vote', dest: msg.key, live: true }),
70 + pull.drain(function (link) {
71 + if (link.key) {
72 + sbot.get(link.key, function (err, data) {
73 + if (err) throw err
74 + if (data.author == id) {
75 + msg.value.content.passedVote = data.content.vote.value
76 + exports.star(msg)
77 + }
78 + if (data.content.vote.value == 1) {
79 + if (localStorage[data.author + 'name'])
80 + name = localStorage[data.author + 'name']
81 + else
82 + name = data.author
83 + votes.appendChild(h('a#vote:' + data.author.substring(0, 44), {href:'#' + data.author, title: name}, h('img.emoji', {src: config.emojiUrl + 'star.png'})))
84 + }
85 + else if (data.content.vote.value == -1) {
86 + var lookFor = 'vote:' + data.author.substring(0, 44)
87 + var remove = document.getElementById(lookFor)
88 + remove.parentNode.removeChild(remove)
89 + }
90 + })
91 + }
8992 })
90- })
91- )*/
92-
93- return votebutton
93 + )
94 + }
95 + return votes
9496 }
9597
9698 module.exports.timestamp = function (msg, edited) {
9799 var timestamp

Built with git-ssb-web