git ssb

16+

Dominic / patchbay



Commit 7c22ec2ce201b04fa7c787e4f7833eb28065327b

meta message styling, more legible raw message

mix irving committed on 2/4/2017, 8:57:02 AM
Parent: 652e17c6ca36341c8b5f36c66780d9bae9bfc721

Files changed

modules_basic/like.jschanged
modules_basic/message/render.jschanged
modules_basic/message/render.mcsschanged
modules_extra/channel.jschanged
modules_extra/raw.jschanged
modules_basic/like.jsView
@@ -39,20 +39,20 @@
3939 ))
4040 votes.push({source: CACHE[k].author, dest: k, rel: 'vote'})
4141 }
4242
43- if(votes.length === 1)
44- digs.textContent = ' 1 Dig'
45- else if(votes.length > 1)
46- digs.textContent = ' ' + votes.length + ' Digs'
43 + if (votes.length === 0) return
4744
45 + digs.textContent = votes.length > 4
46 + ? votes.length + ' 🗸'
47 + : Array(votes.length).fill('🗸').join('')
48 +
4849 pull(
49- pull.values(votes.map(vote => {
50- return api.avatar_name(vote.source)
51- })),
52- pull.collect(function (err, ary) {
53- digs.title = ary.map(x => x.innerHTML).join(" ")
54- })
50 + pull.values(votes.map(vote => api.avatar_name(vote.source))),
51 + pull.collect((err, ary) => {
52 + if (err) console.error(err)
53 + digs.title = 'Dug by:\n' + ary.map(x => x.innerHTML).join("\n")
54 + })
5555 )
5656
5757 return digs
5858 }
modules_basic/message/render.jsView
@@ -41,8 +41,9 @@
4141 h('header.author', api.message_author(msg)),
4242 h('section.title', api.message_title(msg)),
4343 h('section.meta', api.message_meta(msg)),
4444 h('section.content', content),
45 + h('section.raw-content'),
4546 h('section.action', api.message_action(msg)),
4647 h('footer.backlinks', api.message_backlinks(msg))
4748 ])
4849 return msgEl
@@ -74,9 +75,10 @@
7475 }
7576 }, [
7677 h('header.author', api.message_author(msg, { size: 'mini' })),
7778 h('section.meta', api.message_meta(msg)),
78- h('section.content', el)
79 + h('section.content', el),
80 + h('section.raw-content')
7981 ])
8082 }
8183 }
8284
modules_basic/message/render.mcssView
@@ -19,17 +19,16 @@
1919 }
2020
2121 section.meta {
2222 display: flex
23 + align-items: center
24 + * {
25 + margin-left: .4rem
26 + }
27 +
2328 a {
24- margin-left: .2rem
2529 $textSubtle
2630 }
27-
28- input{
29- margin-right: 0
30- order: 99
31- }
3231 }
3332
3433 section.content {
3534 flex-basis: 100%
@@ -38,8 +37,24 @@
3837 max-width: 100%
3938 }
4039 }
4140
41 + section.raw-content {
42 + margin-left: -7rem
43 + flex-basis: 130%
44 + pre {
45 + border: 1px gainsboro solid
46 + padding: .8rem
47 +
48 + span {
49 + font-weight: 600
50 + }
51 + a {
52 + word-break: break-all
53 + }
54 + }
55 + }
56 +
4257 section.action {
4358 flex-basis: 100%
4459 display: flex
4560 justify-content: flex-end
@@ -75,6 +90,11 @@
7590
7691 section.meta {
7792 order: 2
7893 }
94 +
95 + section.raw-content {
96 + order: 3
97 + margin-left: 0
98 + }
7999 }
80100 }
modules_extra/channel.jsView
@@ -40,9 +40,12 @@
4040
4141 function message_meta (msg) {
4242 var chan = msg.value.content.channel
4343 if (chan)
44- return h('a', {href: '##'+chan}, '#'+chan)
44 + return h('a', {
45 + href: '##'+chan,
46 + order: 98
47 + }, '#'+chan)
4548 }
4649
4750 function screen_view (path) {
4851 if(path[0] === '#') {
modules_extra/raw.jsView
@@ -1,40 +1,37 @@
11 var h = require('hyperscript')
22
3-// from ssb-ref
4-var refRegex = /((?:@|%|&)[A-Za-z0-9\/+]{43}=\.[\w\d]+)/g
5-
63 exports.gives = 'message_meta'
74
8-function linkify (text) {
9- var arr = text.split(refRegex)
10- for (var i = 1; i < arr.length; i += 2) {
11- arr[i] = h('a', {href: '#' + arr[i]}, arr[i])
12- }
13- return arr
14-}
155
166 exports.create = function (api) {
177 return function (msg) {
188 var tmp = h('div')
199 var el
2010 var pre
21- return h('input', {
22- type: 'checkbox',
23- title: 'View Data',
11 + const symbol = '⛭'
12 + var clicked = false
13 +
14 + return h('a', {
15 + title: 'View raw data',
16 + style: {
17 + order: 99,
18 + color: 'gray',
19 + 'font-size': '1rem',
20 + cursor: 'pointer',
21 + },
2422 onclick: function () {
23 + clicked = !clicked
24 +
2525 // HACK (mw) yo we need a better way to replace the content
2626 var msgEl = this.parentNode.parentNode
27- var msgContentEl = msgEl.querySelector('.\\.content')
28- if (this.checked) {
27 + var msgContentEl = msgEl.querySelector('.\\.raw-content')
28 + if (clicked) {
2929 // move away the content
3030 while (el = msgContentEl.firstChild)
3131 tmp.appendChild(el)
3232 // show the raw stuff
33- if (!pre) pre = h('pre', linkify(JSON.stringify({
34- key: msg.key,
35- value: msg.value
36- }, 0, 2)))
33 + if (!pre) pre = h('pre', buildRawMsg(msg) )
3734 msgContentEl.appendChild(pre)
3835 } else {
3936 // hide the raw stuff
4037 msgContentEl.removeChild(pre)
@@ -42,8 +39,45 @@
4239 while (el = tmp.firstChild)
4340 msgContentEl.appendChild(el)
4441 }
4542 }
46- })
43 + }, symbol)
4744 }
4845 }
4946
47 +
48 +function buildRawMsg (msg) {
49 + return colorKeys(linkify(
50 + JSON.stringify({
51 + key: msg.key,
52 + value: msg.value
53 + }, 0, 2)
54 + ))
55 +}
56 +
57 +function colorKeys (chunks) {
58 + var newArray = []
59 + chunks.forEach(chunk => {
60 + if (typeof chunk !== 'string') return newArray.push(chunk)
61 +
62 + var arr = chunk.split(/("[^"]+":)/)
63 + for (var i = 1; i < arr.length; i += 2) {
64 + arr[i] = h('span', arr[i])
65 + }
66 + newArray = [...newArray, ...arr]
67 + })
68 +
69 + return newArray
70 +}
71 +
72 +function linkify (text) {
73 + // from ssb-ref
74 + var refRegex = /((?:@|%|&)[A-Za-z0-9\/+]{43}=\.[\w\d]+)/g
75 +
76 + var arr = text.split(refRegex)
77 + for (var i = 1; i < arr.length; i += 2) {
78 + arr[i] = h('a', {href: '#' + arr[i]}, arr[i])
79 + }
80 + return arr
81 +}
82 +
83 +

Built with git-ssb-web