Files: fd8bb1c95ab59a206713bc1211f1c9c3f72e8564 / app / html / menu.js
1083 bytesRaw
1 | const nest = require('depnest') |
2 | const { h, Value, when } = require('mutant') |
3 | |
4 | exports.gives = nest('app.html.menu') |
5 | |
6 | exports.needs = nest({ |
7 | 'app.html.menuItem': 'map', |
8 | 'app.sync.goTo': 'first', |
9 | 'sbot.obs.connection': 'first' |
10 | }) |
11 | |
12 | exports.create = function (api) { |
13 | var _menu |
14 | |
15 | return nest('app.html.menu', function menu () { |
16 | if (_menu) return _menu |
17 | |
18 | const hoverClass = Value('') |
19 | const connectionClass = when(api.sbot.obs.connection, '', '-disconnected') |
20 | |
21 | const menuItems = api.app.html.menuItem(api.app.sync.goTo).map(item => { |
22 | // Remove custom order from dependencies that give app.html.menuItem |
23 | item.style.order = null |
24 | return item |
25 | }) |
26 | const sortedMenuItems = Object.values(menuItems).sort((a, b) => |
27 | a.text.localeCompare(b.text) |
28 | ) |
29 | |
30 | // TODO: move goTo out into each menuItem |
31 | _menu = h('Menu', { |
32 | classList: [ hoverClass, connectionClass ], |
33 | 'ev-mouseover': () => hoverClass.set('-open'), |
34 | 'ev-mouseout': () => hoverClass.set('') |
35 | }, [ |
36 | h('div', sortedMenuItems) |
37 | ]) |
38 | |
39 | return _menu |
40 | }) |
41 | } |
42 |
Built with git-ssb-web