git ssb

16+

Dominic / patchbay



Tree: 46842ef2f464bf904590456aee41d122413cabb4

Files: 46842ef2f464bf904590456aee41d122413cabb4 / app / page / blogs.js

2314 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 'app.sync.goTo': 'first',
14 'message.html.render': 'first',
15 'sbot.pull.stream': 'first'
16})
17
18exports.create = function (api) {
19 return nest({
20 'app.html.menuItem': menuItem,
21 'app.page.blogs': blogsPage
22 })
23
24 function menuItem () {
25 return h('a', {
26 style: { order: 1 },
27 'ev-click': () => api.app.sync.goTo({ page: 'blogs' })
28 }, '/blogs')
29 }
30
31 function blogsPage (location) {
32 const createStream = (opts) => {
33 const query = [{
34 $filter: {
35 timestamp: { $gt: 0 },
36 value: {
37 content: { type: 'blog' }
38 }
39 }
40 }]
41 return api.sbot.pull.stream(server => {
42 return next(server.query.read, Object.assign({}, { limit: 100, query }, opts), ['timestamp'])
43 })
44 }
45 var page = Scroller({
46 classList: ['Blogs'],
47 streamToTop: createStream({ live: true, old: false }),
48 streamToBottom: createStream({ reverse: true }),
49 render: api.message.html.render
50 })
51
52 page.title = '/blogs'
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