Files: f80524e4e4d9ee8b39654228746a0afe58778971 / app / html / header.js
2168 bytesRaw
1 | const nest = require('depnest') |
2 | const { h, computed, when } = require('mutant') |
3 | const path = require('path') |
4 | const windowControls = require('../../windowControls') |
5 | |
6 | exports.gives = nest('app.html.header') |
7 | exports.needs = nest({ |
8 | 'app.obs.pluginsOk': 'first' |
9 | }) |
10 | |
11 | const SETTINGS_PAGES = [ |
12 | 'settings', |
13 | 'userEdit' |
14 | ] |
15 | |
16 | exports.create = (api) => { |
17 | return nest('app.html.header', (nav) => { |
18 | const { location, push } = nav |
19 | |
20 | const loc = computed(location, location => { |
21 | if (typeof location !== 'object') return {} |
22 | return location |
23 | }) |
24 | |
25 | if (loc().page === 'splash') return |
26 | |
27 | const isSettings = computed(loc, loc => SETTINGS_PAGES.includes(loc.page)) |
28 | const isAddressBook = computed(loc, loc => loc.page === 'addressBook') |
29 | const isNotifications = computed(loc, loc => loc.page === 'notifications' || loc.page === 'statsShow') |
30 | const isFeed = computed([isAddressBook, isSettings, isNotifications], (p, s, n) => !p && !s && !n) |
31 | |
32 | return h('Header', [ |
33 | windowControls(), |
34 | h('nav', [ |
35 | h('i.feed', [ |
36 | h('img', { |
37 | src: when(isFeed, assetPath('feed_on.png'), assetPath('feed.png')), |
38 | 'ev-click': () => push({page: 'blogIndex'}) |
39 | }) |
40 | ]), |
41 | h('i.addressBook', [ |
42 | h('img', { |
43 | src: when(isAddressBook, assetPath('address_bk_on.png'), assetPath('address_bk.png')), |
44 | 'ev-click': () => push({page: 'addressBook'}) |
45 | }) |
46 | ]), |
47 | h('i.settings', [ |
48 | h('img.settings', { |
49 | src: when(isSettings, assetPath('settings_on.png'), assetPath('settings.png')), |
50 | 'ev-click': () => push({page: 'settings'}) |
51 | }) |
52 | ]), |
53 | computed(api.app.obs.pluginsOk(), ok => { |
54 | return h('i.notifications.fa', { |
55 | classList: [ |
56 | when(isNotifications, 'fa-bell', 'fa-bell-o'), |
57 | when(!ok, '-disabled') |
58 | ], |
59 | 'ev-click': () => { |
60 | if (!ok) return |
61 | push({page: 'statsShow'}) |
62 | } |
63 | }) |
64 | }) |
65 | ]) |
66 | ]) |
67 | }) |
68 | } |
69 | |
70 | function assetPath (name) { |
71 | return path.join(__dirname, '../../assets', name) |
72 | } |
73 |
Built with git-ssb-web