Files: 9b7b6df024c1c91b5fa96dbbe3c3cbf1e5000f18 / app / html / header.js
1535 bytesRaw
1 | const nest = require('depnest') |
2 | const { h, computed, when } = require('mutant') |
3 | const get = require('lodash/get') |
4 | const path = require('path') |
5 | |
6 | exports.gives = nest('app.html.header') |
7 | |
8 | exports.needs = nest('keys.sync.id', 'first') |
9 | |
10 | const SETTINGS_PAGES = [ |
11 | 'settings', |
12 | 'userEdit', |
13 | ] |
14 | |
15 | exports.create = (api) => { |
16 | return nest('app.html.header', (nav) => { |
17 | const { location, push } = nav |
18 | const myKey = api.keys.sync.id() |
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 isFeed = computed([isAddressBook, isSettings], (p, s) => !p && !s) |
30 | |
31 | return h('Header', [ |
32 | h('nav', [ |
33 | h('img.feed', { |
34 | src: when(isFeed, assetPath('feed_on.png'), assetPath('feed.png')), |
35 | 'ev-click': () => push({page: 'blogIndex'}), |
36 | }), |
37 | h('img.addressBook', { |
38 | src: when(isAddressBook, assetPath('address_bk_on.png'), assetPath('address_bk.png')), |
39 | 'ev-click': () => push({page: 'addressBook'}) |
40 | }), |
41 | h('img.settings', { |
42 | src: when(isSettings, assetPath('settings_on.png'), assetPath('settings.png')), |
43 | 'ev-click': () => push({page: 'settings'}) |
44 | }), |
45 | ]), |
46 | ]) |
47 | }) |
48 | } |
49 | |
50 | function assetPath (name) { |
51 | return path.join(__dirname, '../../assets', name) |
52 | } |
53 | |
54 |
Built with git-ssb-web