Files: 09c0a2e49ccc68a4cdc3a98da00657c1aff6158b / app / html / page / public.js
1732 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 | 'app.sync.goTo': 'first', |
20 | 'feed.pull.public': 'first', |
21 | 'message.html': { |
22 | compose: 'first', |
23 | render: 'first' |
24 | } |
25 | }) |
26 | |
27 | exports.create = function (api) { |
28 | const route = '/public' |
29 | |
30 | return nest({ |
31 | 'app.html': { |
32 | page: publicPage, |
33 | menuItem |
34 | } |
35 | }) |
36 | |
37 | function menuItem () { |
38 | return h('a', { |
39 | style: { order: 1 }, |
40 | 'ev-click': () => api.app.sync.goTo(route) |
41 | }, route) |
42 | } |
43 | |
44 | function publicPage (path) { |
45 | if (path !== route) return |
46 | |
47 | const composer = api.message.html.compose({ |
48 | meta: { type: 'post' }, |
49 | placeholder: 'Write a public message' |
50 | }) |
51 | const { filterMenu, filterDownThrough, filterUpThrough, resetFeed } = api.app.html.filter(draw) |
52 | const { container, content } = api.app.html.scroller({ prepend: [composer, filterMenu] }) |
53 | |
54 | // TODO : build a pull-stream which has seperate state + rendering |
55 | function draw () { |
56 | resetFeed({ container, content }) |
57 | |
58 | pull( |
59 | next(api.feed.pull.public, {old: false, limit: 100}), |
60 | filterDownThrough(), |
61 | Scroller(container, content, api.message.html.render, true, false) |
62 | ) |
63 | |
64 | pull( |
65 | next(api.feed.pull.public, {reverse: true, limit: 100, live: false}), |
66 | filterUpThrough(), |
67 | Scroller(container, content, api.message.html.render, false, false) |
68 | ) |
69 | } |
70 | draw() |
71 | |
72 | return container |
73 | } |
74 | } |
75 | |
76 |
Built with git-ssb-web