Files: 038e248915e3e8c69af62015ec1eb52f957d79f3 / app / html / page / public.js
1719 bytesRaw
1 | const nest = require('depnest') |
2 | const { h } = require('mutant') |
3 | const pull = require('pull-stream') |
4 | const Scroller = require('pull-scroll') |
5 | const next = require('../../../junk/next-stepper') |
6 | |
7 | exports.gives = nest({ |
8 | 'app.html': { |
9 | page: true, |
10 | menuItem: true |
11 | } |
12 | }) |
13 | |
14 | exports.needs = nest({ |
15 | 'app.html': { |
16 | filter: 'first', |
17 | scroller: 'first' |
18 | }, |
19 | 'feed.pull.public': 'first', |
20 | 'message.html': { |
21 | compose: 'first', |
22 | render: 'first' |
23 | } |
24 | }) |
25 | |
26 | exports.create = function (api) { |
27 | const route = '/public' |
28 | |
29 | return nest({ |
30 | 'app.html': { |
31 | page: publicPage, |
32 | menuItem: menuItem |
33 | } |
34 | }) |
35 | |
36 | function menuItem (handleClick) { |
37 | return h('a', { |
38 | style: { order: 1 }, |
39 | 'ev-click': () => handleClick(route) |
40 | }, route) |
41 | } |
42 | |
43 | function publicPage (path) { |
44 | if (path !== route) return |
45 | |
46 | const composer = api.message.html.compose({ |
47 | meta: { type: 'post' }, |
48 | placeholder: 'Write a public message' |
49 | }) |
50 | const { filterMenu, filterDownThrough, filterUpThrough, resetFeed } = api.app.html.filter(draw) |
51 | const { container, content } = api.app.html.scroller({ prepend: [composer, filterMenu] }) |
52 | |
53 | // TODO : build a pull-stream which has seperate state + rendering |
54 | function draw () { |
55 | resetFeed({ container, content }) |
56 | |
57 | pull( |
58 | next(api.feed.pull.public, {old: false, limit: 100}), |
59 | filterDownThrough(), |
60 | Scroller(container, content, api.message.html.render, true, false) |
61 | ) |
62 | |
63 | pull( |
64 | next(api.feed.pull.public, {reverse: true, limit: 100, live: false}), |
65 | filterUpThrough(), |
66 | Scroller(container, content, api.message.html.render, false, false) |
67 | ) |
68 | } |
69 | draw() |
70 | |
71 | return container |
72 | } |
73 | } |
74 | |
75 |
Built with git-ssb-web