git ssb

16+

Dominic / patchbay



Tree: 5f97c9299ad9c3dffb16c07de00d5b45e15a80a7

Files: 5f97c9299ad9c3dffb16c07de00d5b45e15a80a7 / app / page / blogs.js

2363 bytesRaw
1const nest = require('depnest')
2const { h } = require('mutant')
3// const pull = require('pull-stream')
4const Scroller = require('mutant-scroll')
5const next = require('pull-next-query')
6
7exports.gives = nest({
8 'app.html.menuItem': true,
9 'app.page.blogs': true
10})
11
12exports.needs = nest({
13 'message.html.render': 'first',
14 'sbot.pull.stream': 'first'
15})
16
17exports.create = function (api) {
18 return nest({
19 'app.html.menuItem': menuItem,
20 'app.page.blogs': blogsPage
21 })
22
23 function menuItem () {
24 return h('a', {
25 style: { order: 1 },
26 'ev-click': () => api.app.sync.goTo({ page: 'blogs' })
27 }, '/blogs')
28 }
29
30 function blogsPage (location) {
31 const createStream = (opts) => {
32 const query = [{
33 $filter: {
34 timestamp: { $gt: 0 },
35 value: {
36 content: { type: 'blog' }
37 }
38 }
39 }]
40 return api.sbot.pull.stream(server => {
41 return next(server.query.read, Object.assign({}, { limit: 100, query }, opts), ['timestamp'])
42 })
43 }
44 var page = Scroller({
45 classList: ['Blogs'],
46 streamToTop: createStream({ live: true, old: false }),
47 streamToBottom: createStream({ reverse: true }),
48 render: api.message.html.render
49 })
50
51 page.title = '/blogs'
52 page.id = '{"page": "blogs"}' // this is needed because our page is a computed
53 page.scroll = keyscroll(page.querySelector('section.content'))
54 return page
55 }
56}
57
58// copied from app.html.scroller
59function keyscroll (content) {
60 var curMsgEl
61
62 if (!content) return () => {}
63
64 content.addEventListener('click', onActivateChild, false)
65 content.addEventListener('focus', onActivateChild, true)
66
67 function onActivateChild (ev) {
68 for (var el = ev.target; el; el = el.parentNode) {
69 if (el.parentNode === content) {
70 curMsgEl = el
71 return
72 }
73 }
74 }
75
76 return function scroll (d) {
77 selectChild((!curMsgEl || d === 'first') ? content.firstChild
78 : d < 0 ? curMsgEl.previousElementSibling || content.firstChild
79 : d > 0 ? curMsgEl.nextElementSibling || content.lastChild
80 : curMsgEl)
81
82 return curMsgEl
83 }
84
85 function selectChild (el) {
86 if (!el) { return }
87
88 if (!el.scrollIntoViewIfNeeded && !el.scrollIntoView) return
89 ;(el.scrollIntoViewIfNeeded || el.scrollIntoView).call(el)
90 el.focus()
91 curMsgEl = el
92 }
93}
94

Built with git-ssb-web