Files: ee289a19dca6fefc3c9308225b6c429fdeb79ad6 / app / html / menu.js
1826 bytesRaw
1 | const nest = require('depnest') |
2 | const { h, Value, when } = require('mutant') |
3 | const pull = require('pull-stream') |
4 | |
5 | exports.gives = nest('app.html.menu') |
6 | |
7 | exports.needs = nest({ |
8 | 'app.html.menuItem': 'map', |
9 | 'app.sync.goTo': 'first', |
10 | 'sbot.obs.connection': 'first', |
11 | 'sbot.pull.stream': 'first' |
12 | }) |
13 | |
14 | exports.create = function (api) { |
15 | var _menu |
16 | |
17 | return nest('app.html.menu', function menu () { |
18 | if (_menu) return _menu |
19 | |
20 | const hoverClass = Value('') |
21 | const connectionClass = when(api.sbot.obs.connection, '', '-disconnected') |
22 | const newMessageClass = Value('') |
23 | |
24 | var timeOut |
25 | pull( |
26 | api.sbot.pull.stream(sbot => { |
27 | const query = [{ |
28 | $filter: { |
29 | timestamp: { $gt: 0 } |
30 | } |
31 | }, { |
32 | $map: { |
33 | author: ['value', 'author'] |
34 | } |
35 | }] |
36 | return sbot.query.read({ live: true, old: false, query }) |
37 | }), |
38 | // pull.filter(a => a !== myKey), // could filter out my own messages |
39 | pull.drain(m => { |
40 | if (timeOut) return |
41 | |
42 | newMessageClass.set('-newMsg') |
43 | timeOut = setTimeout(() => { |
44 | newMessageClass.set('') |
45 | timeOut = null |
46 | }, 200) |
47 | }) |
48 | ) |
49 | |
50 | const menuItems = api.app.html.menuItem(api.app.sync.goTo).map(item => { |
51 | // Remove custom order from dependencies that give app.html.menuItem |
52 | item.style.order = null |
53 | return item |
54 | }) |
55 | const sortedMenuItems = Object.values(menuItems).sort((a, b) => |
56 | a.text.localeCompare(b.text) |
57 | ) |
58 | |
59 | // TODO: move goTo out into each menuItem |
60 | _menu = h('Menu', { |
61 | classList: [ hoverClass, connectionClass, newMessageClass ], |
62 | 'ev-mouseover': () => hoverClass.set('-open'), |
63 | 'ev-mouseout': () => hoverClass.set('') |
64 | }, [ |
65 | h('div', sortedMenuItems) |
66 | ]) |
67 | |
68 | return _menu |
69 | }) |
70 | } |
71 |
Built with git-ssb-web