git ssb

16+

Dominic / patchbay



Commit 103c9cb09aa9eb239d03b8d79511054d4391d90b

Merge pull request #72 from ssbc/scroller_module

Scroller module
mix irving authored on 2/1/2017, 4:55:44 AM
GitHub committed on 2/1/2017, 4:55:44 AM
Parent: b3b3e03454ae24d6652ca73a96c1d03116a8abea
Parent: 32b01f5e6a1ea4c8ceee789f8d6e3375e78b6b39

Files changed

modules_basic/feed.jschanged
modules_basic/index.jschanged
modules_basic/message/confirm.mcsschanged
modules_basic/message/render.mcsschanged
modules_basic/private.jschanged
modules_basic/public.jschanged
modules_basic/setup.jschanged
modules_basic/thread.jschanged
modules_basic/scroller.jsadded
modules_basic/scroller.mcssadded
modules_core/tabs.jschanged
modules_extra/channel.jschanged
modules_extra/git-ssb.jschanged
modules_extra/notifications.jschanged
modules_extra/search.jschanged
modules_basic/feed.jsView
@@ -4,8 +4,9 @@
44 var pull = require('pull-stream')
55 var u = require('../util')
66
77 exports.needs = {
8 + build_scroller: 'first',
89 sbot_user_feed: 'first',
910 message_render: 'first',
1011 avatar_profile: 'first',
1112 signifier: 'first'
@@ -18,44 +19,33 @@
1819
1920 return function (id) {
2021 //TODO: header of user info, avatars, names, follows.
2122
22- if(ref.isFeed(id)) {
23 + if(!ref.isFeed(id)) return
2324
24- var content = h('div.column.scroller__content')
25- var div = h('div.column.scroller',
26- {style: {'overflow':'auto'}},
27- h('div.scroller__wrapper',
28- h('div', api.avatar_profile(id)),
29- h('header', 'Activity'),
30- content
31- )
32- )
25 + const profile = h('div', api.avatar_profile(id))
26 + var { container, content } = api.build_scroller({ prepend: [profile, h('header', 'Activity')] })
27 +
28 + api.signifier(id, function (_, names) {
29 + if(names.length) container.title = names[0].name
30 + })
3331
34- api.signifier(id, function (_, names) {
35- if(names.length) div.title = names[0].name
36- })
32 + pull(
33 + api.sbot_user_feed({id: id, old: false, live: true}),
34 + Scroller(container, content, api.message_render, true, false)
35 + )
3736
37 + //how to handle when have scrolled past the start???
3838
39- pull(
40- api.sbot_user_feed({id: id, old: false, live: true}),
41- Scroller(div, content, api.message_render, true, false)
42- )
39 + pull(
40 + u.next(api.sbot_user_feed, {
41 + id: id, reverse: true,
42 + limit: 50, live: false
43 + }, ['value', 'sequence']),
44 + // pull.through(console.log.bind(console)),
45 + Scroller(container, content, api.message_render, false, false)
46 + )
4347
44- //how to handle when have scrolled past the start???
45-
46- pull(
47- u.next(api.sbot_user_feed, {
48- id: id, reverse: true,
49- limit: 50, live: false
50- }, ['value', 'sequence']),
51- // pull.through(console.log.bind(console)),
52- Scroller(div, content, api.message_render, false, false)
53- )
54-
55- return div
56-
57- }
48 + return container
5849 }
59-
6050 }
6151
modules_basic/index.jsView
@@ -14,8 +14,9 @@
1414 'pub': require('./pub'),
1515 'public': require('./public'),
1616 'relationships': require('./relationships'),
1717 'reply': require('./reply'),
18 + 'scroller': require('./scroller'),
1819 'setup': require('./setup'),
1920 'thread': require('./thread'),
2021 'timestamp': require('./timestamp')
2122 }
modules_basic/message/confirm.mcssView
@@ -6,10 +6,8 @@
66 -message_preview {
77 background-color: white
88
99 div {
10- border: none
11-
1210 header.author {
1311 div {
1412 section {
1513 -timestamp {
modules_basic/message/render.mcssView
@@ -1,7 +1,6 @@
11 Message {
22 padding: 1rem .5rem 1rem 7.5rem
3- border-top: solid 1px gainsboro
43 min-height: 5rem
54
65 position: relative
76 display: flex
modules_basic/private.jsView
@@ -9,8 +9,9 @@
99 if(Array.isArray(ary)) return ary.map(iter)
1010 }
1111
1212 exports.needs = {
13 + build_scroller: 'first',
1314 message_render: 'first',
1415 message_compose: 'first',
1516 message_unbox: 'first',
1617 sbot_log: 'first',
@@ -47,55 +48,50 @@
4748
4849 screen_view: function (path) {
4950 if(path !== '/private') return
5051
51- var div = h('div.column.scroller',
52- {style: {'overflow':'auto'}})
52 + var composer = api.message_compose(
53 + {type: 'post', recps: [], private: true},
54 + {
55 + prepublish: function (msg) {
56 + msg.recps = [id].concat(msg.mentions).filter(function (e) {
57 + return ref.isFeed('string' === typeof e ? e : e.link)
58 + })
59 + if(!msg.recps.length)
60 + throw new Error('cannot make private message without recipients - just mention the user in an at reply in the message you send')
61 + return msg
62 + },
63 + placeholder: 'Write a private message'
64 + }
65 + )
66 + var { container, content } = api.build_scroller({ prepend: composer })
5367
5468 // if local id is different from sbot id, sbot won't have indexes of
5569 // private threads
5670 //TODO: put all private indexes client side.
5771 var id = require('../keys').id
5872 api.sbot_whoami(function (err, feed) {
5973 if (err) return console.error(err)
6074 if(id !== feed.id)
61- return div.appendChild(h('h4',
75 + return container.appendChild(h('h4',
6276 'Private messages are not supported in the lite client.'))
6377
64- var compose = api.message_compose(
65- {type: 'post', recps: [], private: true},
66- {
67- prepublish: function (msg) {
68- msg.recps = [id].concat(msg.mentions).filter(function (e) {
69- return ref.isFeed('string' === typeof e ? e : e.link)
70- })
71- if(!msg.recps.length)
72- throw new Error('cannot make private message without recipients - just mention the user in an at reply in the message you send')
73- return msg
74- },
75- placeholder: 'Write a private message'
76- }
77- )
78-
79- var content = h('div.column.scroller__content')
80- div.appendChild(h('div.scroller__wrapper', compose, content))
81-
8278 pull(
8379 u.next(api.sbot_log, {old: false, limit: 100}),
8480 unbox(),
85- Scroller(div, content, api.message_render, true, false)
81 + Scroller(container, content, api.message_render, true, false)
8682 )
8783
8884 pull(
8985 u.next(api.sbot_log, {reverse: true, limit: 1000}),
9086 unbox(),
91- Scroller(div, content, api.message_render, false, false, function (err) {
87 + Scroller(container, content, api.message_render, false, false, function (err) {
9288 if(err) throw err
9389 })
9490 )
9591 })
9692
97- return div
93 + return container
9894 },
9995
10096 message_meta: function (msg) {
10197 if(msg.value.content.recps || msg.value.private)
modules_basic/public.jsView
@@ -1,49 +1,50 @@
1-var h = require('hyperscript')
2-var u = require('../util')
3-var pull = require('pull-stream')
4-var Scroller = require('pull-scroll')
1 +const fs = require('fs')
2 +const h = require('hyperscript')
3 +const u = require('../util')
4 +const pull = require('pull-stream')
5 +const Scroller = require('pull-scroll')
56
67 exports.needs = {
8 + build_scroller: 'first',
79 message_render: 'first',
810 message_compose: 'first',
911 sbot_log: 'first',
1012 }
1113
1214 exports.gives = {
13- builtin_tabs: true, screen_view: true
15 + builtin_tabs: true,
16 + screen_view: true,
17 + // mcss: true
1418 }
1519
1620 exports.create = function (api) {
17-
1821 return {
19- builtin_tabs: function () {
20- return ['/public']
21- },
22 + builtin_tabs,
23 + screen_view,
24 + // mcss: () => fs.readFileSync(__filename.replace(/js$/, 'mcss'), 'utf8')
25 + }
2226
23- screen_view: function (path, sbot) {
24- if(path === '/public') {
27 + function builtin_tabs () {
28 + return ['/public']
29 + }
2530
26- var content = h('div.column.scroller__content')
27- var div = h('div.column.scroller',
28- {style: {'overflow':'auto'}},
29- h('div.scroller__wrapper',
30- api.message_compose({type: 'post'}, {placeholder: 'Write a public message'}),
31- content
32- )
33- )
31 + function screen_view (path, sbot) {
32 + if(path !== '/public') return
3433
35- pull(
36- u.next(api.sbot_log, {old: false, limit: 100}),
37- Scroller(div, content, api.message_render, true, false)
38- )
34 + const composer = api.message_compose({type: 'post'}, {placeholder: 'Write a public message'})
35 + var { container, content } = api.build_scroller({ prepend: composer })
3936
40- pull(
41- u.next(api.sbot_log, {reverse: true, limit: 100, live: false}),
42- Scroller(div, content, api.message_render, false, false)
43- )
37 + pull(
38 + u.next(api.sbot_log, {old: false, limit: 100}),
39 + Scroller(container, content, api.message_render, true, false)
40 + )
4441
45- return div
46- }
47- }
42 + pull(
43 + u.next(api.sbot_log, {reverse: true, limit: 100, live: false}),
44 + Scroller(container, content, api.message_render, false, false)
45 + )
46 +
47 + return container
4848 }
4949 }
50 +
modules_basic/setup.jsView
@@ -1,5 +1,4 @@
1-
21 var h = require('hyperscript')
32 var pull = require('pull-stream')
43
54 exports.needs = {
@@ -10,8 +9,15 @@
109 sbot_progress: 'first',
1110 sbot_query: 'first'
1211 }
1312
13 +exports.gives = {
14 + setup_is_fresh_install: true,
15 + progress_bar: true,
16 + setup_joined_network: true,
17 + screen_view: true
18 +}
19 +
1420 //maybe this could show the pubs, or
1521 //if someone locally follows you,
1622 //it could show the second degree pubs?
1723
@@ -28,13 +34,17 @@
2834 }}]
2935 }
3036
3137 exports.create = function (api) {
38 + return {
39 + setup_is_fresh_install,
40 + progress_bar,
41 + setup_joined_network,
42 + screen_view
43 + }
3244
33- var exports = {}
34-
3545 //test whether we are connected to the ssb network.
36- exports.setup_is_fresh_install = function (cb) {
46 + function setup_is_fresh_install (cb) {
3747 //test by checking whether you have any friends following you?
3848 pull(
3949 api.sbot_query({query: followers_query(id), limit: 1, live: false}),
4050 pull.collect(function (err, ary) {
@@ -78,9 +88,9 @@
7888
7989 return h('div.invite-form.row', input, accept)
8090 }
8191
82- exports.progress_bar = function () {
92 + function progress_bar () {
8393 var liquid = h('div.hyperprogress__liquid', '.')
8494 var bar = h('div.hyperprogress__bar', liquid)
8595 liquid.style.width = '0%'
8696
@@ -99,9 +109,9 @@
99109
100110 //when you join the network, I want this to show as people follow you.
101111 //that could be when a pub accepts the invite, or when a local peer accepts.
102112
103- exports.setup_joined_network = function (id) {
113 + function setup_joined_network (id) {
104114 var followers = h('div.column')
105115 var label = h('label', 'not connected to a network')
106116 var joined = h('div.setup__joined', label, followers)
107117
@@ -118,31 +128,32 @@
118128
119129 return joined
120130 }
121131
122- exports.screen_view = function (path) {
132 + function screen_view (path) {
123133 if(path !== '/setup') return
124134
125- var id = require('../keys').id
135 + var { id } = require('../keys')
126136
127137 //set up an avatar
128138
129139 var status = h('span')
130- return h('div.scroller', h('div.scroller__wrapper',
131- h('h1', 'welcome to patchbay!'),
132- h('div',
133- 'please choose avatar image and name',
134- api.avatar_edit(id)
135- ),
136- h('h2', 'join network'),
137- invite_form(),
138- //show avatars of anyone on the same local network.
139- //show realtime changes in your followers, especially for local.
140 + var invite = h('input', {placeholder: 'invite code'})
141 + return h('div.scroller', [
142 + h('div.scroller__wrapper', [
143 + h('h1', 'welcome to patchbay!'),
144 + h('div',
145 + 'please choose avatar image and name',
146 + api.avatar_edit(id)
147 + ),
148 + h('h2', 'join network'),
149 + invite_form(),
150 + //show avatars of anyone on the same local network.
151 + //show realtime changes in your followers, especially for local.
140152
141- exports.progress_bar(),
142- exports.setup_joined_network(require('../keys').id)
143- ))
153 + progress_bar(),
154 + setup_joined_network(id)
155 + ])
156 + ])
144157 }
158 +}
145159
146- return exports
147-
148-}
modules_basic/thread.jsView
@@ -18,8 +18,9 @@
1818 }
1919 }
2020
2121 exports.needs = {
22 + build_scroller: 'first',
2223 message_render: 'first',
2324 message_name: 'first',
2425 message_compose: 'first',
2526 message_unbox: 'first',
@@ -60,19 +61,13 @@
6061 root: id,
6162 branch: id //mutated when thread is loaded.
6263 }
6364
64- var content = h('div.column.scroller__content')
65- var div = h('div.column.scroller',
66- {style: {'overflow-y': 'auto'}},
67- h('div.scroller__wrapper',
68- content,
69- api.message_compose(meta, {shrink: false, placeholder: 'Write a reply'})
70- )
71- )
65 + var composer = api.message_compose(meta, {shrink: false, placeholder: 'Write a reply'})
66 + var { container, content } = api.build_scroller({ append: composer })
7267
7368 api.message_name(id, function (err, name) {
74- div.title = name
69 + container.title = name
7570 })
7671
7772 pull(
7873 api.sbot_links({
@@ -118,8 +113,8 @@
118113 })
119114 }
120115
121116 loadThread()
122- return div
117 + return container
123118 }
124119 }
125120 }
modules_basic/scroller.jsView
@@ -1,0 +1,32 @@
1 +const fs = require('fs')
2 +const h = require('../h')
3 +
4 +exports.gives = {
5 + build_scroller: true,
6 + mcss: true
7 +}
8 +
9 +exports.create = function (api) {
10 + return {
11 + build_scroller,
12 + mcss: () => fs.readFileSync(__filename.replace(/js$/, 'mcss'), 'utf8')
13 + }
14 +
15 + function build_scroller ({ prepend = [], append = [] } = {}) {
16 + const content = h('section.content')
17 +
18 + const container = h('Scroller', { style: { overflow: 'auto' } }, [
19 + h('div.wrapper', [
20 + h('header', prepend),
21 + content,
22 + h('footer', append)
23 + ])
24 + ])
25 +
26 + return {
27 + content,
28 + container
29 + }
30 + }
31 +}
32 +
modules_basic/scroller.mcssView
@@ -1,0 +1,23 @@
1 +Scroller {
2 + display: flex
3 + flex-direction: column
4 +
5 + overflow: auto
6 + width: 100%
7 + min-height: 0px
8 +
9 + div.wrapper {
10 + flex: 1
11 + max-width: 600px
12 + margin-left: auto
13 + margin-right: auto
14 +
15 + section.content {
16 +
17 + div {
18 + border-top: solid 1px gainsboro
19 + }
20 + }
21 + }
22 +}
23 +
modules_core/tabs.jsView
@@ -9,8 +9,9 @@
99 return el
1010 }
1111
1212 exports.needs = {
13 + build_scroller: 'first',
1314 screen_view: 'first',
1415 search_box: 'first',
1516 menu: 'first',
1617 external_confirm:'first'
@@ -19,10 +20,9 @@
1920 exports.gives = 'screen_view'
2021
2122 exports.create = function (api) {
2223 return function (path) {
23- if(path !== 'tabs')
24- return
24 + if(path !== 'tabs') return
2525
2626 function setSelected (indexes) {
2727 var ids = indexes.map(function (index) {
2828 return tabs.get(index).id
@@ -46,9 +46,9 @@
4646 var el = api.screen_view(path)
4747
4848 if(el) {
4949 if(!el.title) el.title = path
50- el.scroll = keyscroll(el.querySelector('.scroller__content'))
50 + el.scroll = keyscroll(el.querySelector('.Scroller .\\.content'))
5151 tabs.add(el, change)
5252 // localStorage.openTabs = JSON.stringify(tabs.tabs)
5353 return change
5454 }
@@ -72,9 +72,9 @@
7272 var el = api.screen_view(path)
7373 if(!el) return
7474 el.id = el.id || path
7575 if (!el) return
76- el.scroll = keyscroll(el.querySelector('.scroller__content'))
76 + el.scroll = keyscroll(el.querySelector('.Scroller .\\.content'))
7777 if(el) tabs.add(el, false, false)
7878 })
7979
8080 tabs.select(0)
@@ -100,9 +100,9 @@
100100
101101 var el = api.screen_view(path)
102102 if(el) {
103103 el.id = el.id || path
104- el.scroll = keyscroll(el.querySelector('.scroller__content'))
104 + el.scroll = keyscroll(el.querySelector('.Scroller .\\.content'))
105105 tabs.add(el, !ev.ctrlKey, !!ev.shiftKey)
106106 // localStorage.openTabs = JSON.stringify(tabs.tabs)
107107 }
108108
@@ -164,16 +164,12 @@
164164 }
165165 })
166166
167167 // errors tab
168- var errorsContent = h('div.column.scroller__content')
169- var errors = h('div.column.scroller', {
170- id: 'errors',
171- style: {'overflow':'auto'}
172- }, h('div.scroller__wrapper',
173- errorsContent
174- )
175- )
168 + var {
169 + container: errors,
170 + content: errorsContent
171 + } = api.build_scroller()
176172
177173 // remove loader error handler
178174 if (window.onError) {
179175 window.removeEventListener('error', window.onError)
modules_extra/channel.jsView
@@ -3,8 +3,9 @@
33 var Scroller = require('pull-scroll')
44 var mfr = require('map-filter-reduce')
55
66 exports.needs = {
7 + build_scroller: 'first',
78 message_render: 'first',
89 message_compose: 'first',
910 sbot_log: 'first',
1011 sbot_query: 'first',
@@ -35,16 +36,10 @@
3536 screen_view: function (path) {
3637 if(path[0] === '#') {
3738 var channel = path.substr(1)
3839
39- var content = h('div.column.scroller__content')
40- var div = h('div.column.scroller',
41- {style: {'overflow':'auto'}},
42- h('div.scroller__wrapper',
43- api.message_compose({type: 'post', channel: channel}),
44- content
45- )
46- )
40 + var composer = api.message_compose({type: 'post', channel: channel})
41 + var { container, content } = api.build_scroller({ prepend: composer })
4742
4843 function matchesChannel(msg) {
4944 if (msg.sync) console.error('SYNC', msg)
5045 var c = msg && msg.value && msg.value.content
@@ -53,19 +48,19 @@
5348
5449 pull(
5550 api.sbot_log({old: false}),
5651 pull.filter(matchesChannel),
57- Scroller(div, content, api.message_render, true, false)
52 + Scroller(container, content, api.message_render, true, false)
5853 )
5954
6055 pull(
6156 api.sbot_query({reverse: true, query: [
6257 {$filter: {value: {content: {channel: channel}}}}
6358 ]}),
64- Scroller(div, content, api.message_render, false, false)
59 + Scroller(container, content, api.message_render, false, false)
6560 )
6661
67- return div
62 + return container
6863 }
6964 },
7065
7166 connection_status: function (err) {
modules_extra/git-ssb.jsView
@@ -3,15 +3,17 @@
33 var pull = require('pull-stream')
44 var Scroller = require('pull-scroll')
55
66 exports.needs = {
7 + build_scroller: 'first',
78 message_render: 'first',
89 message_compose: 'first',
910 sbot_log: 'first'
1011 }
1112
1213 exports.gives = {
13- menu_items: true, screen_view: true
14 + menu_items: true,
15 + screen_view: true
1416 }
1517
1618 exports.create = function (api) {
1719 return {
@@ -21,29 +23,25 @@
2123
2224 screen_view: function (path, sbot) {
2325 if(path === '/git-ssb') {
2426
25- var content = h('div.column.scroller__content')
26- var div = h('div.column.scroller',
27- {style: {'overflow':'auto'}},
28- h('div.scroller__wrapper', content)
29- )
27 + var { container, content } = api.build_scroller()
3028
3129 pull(
3230 u.next(api.sbot_log, {old: false, limit: 100}),
33- Scroller(div, content, api.message_render, true, false)
31 + Scroller(container, content, api.message_render, true, false)
3432 )
3533
3634 pull(
3735 u.next(api.sbot_log, {reverse: true, limit: 100, live: false}),
3836 pull.filter(function(msg) { return msg.value.content.type }),
3937 pull.filter(function(msg) {
4038 return msg.value.content.type.match(/^git/)
4139 }),
42- Scroller(div, content, api.message_render, false, false)
40 + Scroller(container, content, api.message_render, false, false)
4341 )
4442
45- return div
43 + return container
4644 }
4745 }
4846 }
4947 }
modules_extra/notifications.jsView
@@ -7,8 +7,9 @@
77 var cont = require('cont')
88 var ref = require('ssb-ref')
99
1010 exports.needs = {
11 + build_scroller: 'first',
1112 message_render: 'first',
1213 sbot_log: 'first',
1314 sbot_get: 'first',
1415 sbot_user_feed: 'first',
@@ -126,22 +127,16 @@
126127 oldest = msg.value.timestamp
127128 }
128129 })
129130
130- var content = h('div.column.scroller__content')
131- var div = h('div.column.scroller',
132- {style: {'overflow':'auto'}},
133- h('div.scroller__wrapper',
134- content
135- )
136- )
131 + var { container, content } = api.build_scroller()
137132
138133 pull(
139134 u.next(api.sbot_log, {old: false, limit: 100}),
140135 unbox(),
141136 notifications(ids),
142137 pull.filter(),
143- Scroller(div, content, api.message_render, true, false)
138 + Scroller(container, content, api.message_render, true, false)
144139 )
145140
146141 pull(
147142 u.next(api.sbot_log, {reverse: true, limit: 100, live: false}),
@@ -151,12 +146,12 @@
151146 pull.take(function (msg) {
152147 // abort stream after we pass the oldest messages of our feeds
153148 return !oldest ? true : msg.value.timestamp > oldest
154149 }),
155- Scroller(div, content, api.message_render, false, false)
150 + Scroller(container, content, api.message_render, false, false)
156151 )
157152
158- return div
153 + return container
159154 }
160155 }
161156 }
162157 }
modules_extra/search.jsView
@@ -4,8 +4,9 @@
44 var Scroller = require('pull-scroll')
55 var TextNodeSearcher = require('text-node-searcher')
66
77 exports.needs = {
8 + build_scroller: 'first',
89 message_render: 'first',
910 sbot_log: 'first'
1011 }
1112
@@ -59,16 +60,9 @@
5960
6061 var total = 0, matches = 0
6162
6263 var header = h('div.search_header', '')
63- var content = h('div.column.scroller__content')
64- var div = h('div.column.scroller',
65- {style: {'overflow':'auto'}},
66- h('div.scroller__wrapper',
67- header,
68- content
69- )
70- )
64 + var { container, content } = api.build_scroller({ prepend: header})
7165
7266 function matchesQuery (data) {
7367 total++
7468 var m = _matches(data)
@@ -76,10 +70,8 @@
7670 header.textContent = 'searched:'+total+', found:'+matches
7771 return m
7872 }
7973
80-
81-
8274 function renderMsg(msg) {
8375 var el = api.message_render(msg)
8476 highlight(el, createOrRegExp(query))
8577 return el
@@ -87,18 +79,18 @@
8779
8880 pull(
8981 api.sbot_log({old: false}),
9082 pull.filter(matchesQuery),
91- Scroller(div, content, renderMsg, true, false)
83 + Scroller(container, content, renderMsg, true, false)
9284 )
9385
9486 pull(
9587 u.next(api.sbot_log, {reverse: true, limit: 500, live: false}),
9688 pull.filter(matchesQuery),
97- Scroller(div, content, renderMsg, false, false)
89 + Scroller(container, content, renderMsg, false, false)
9890 )
9991
100- return div
92 + return container
10193 }
10294 }
10395
10496 }

Built with git-ssb-web