Files: db07f3aa11263d691a9cda69238563a05b7c440e / app / html / header.js
1236 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 | |
19 | const loc = computed(location, location => { |
20 | if (typeof location != 'object') return {} |
21 | return location |
22 | }) |
23 | |
24 | if (loc().page === 'splash') return |
25 | |
26 | const isSettings = computed(loc, loc => { |
27 | return SETTINGS_PAGES.includes(loc.page) |
28 | }) |
29 | |
30 | const isFeed = computed([isSettings], isSettings => !isSettings) |
31 | |
32 | return h('Header', [ |
33 | h('nav', [ |
34 | h('img.feed', { |
35 | src: when(isFeed, assetPath('feed_on.png'), assetPath('feed.png')), |
36 | 'ev-click': () => push({page: 'blogIndex'}), |
37 | }), |
38 | h('img.feed', { |
39 | src: when(isSettings, assetPath('settings_on.png'), assetPath('settings.png')), |
40 | 'ev-click': () => push({page: 'settings'}) |
41 | }), |
42 | ]), |
43 | ]) |
44 | }) |
45 | } |
46 | |
47 | function assetPath (name) { |
48 | return path.join(__dirname, '../../assets', name) |
49 | } |
50 | |
51 |
Built with git-ssb-web