Files: 1b46fe809a87f906b19ab7dad059971d13730b4f / app / html / header.js
2238 bytesRaw
1 | const nest = require('depnest') |
2 | const { h, computed, when } = require('mutant') |
3 | const path = require('path') |
4 | const { remote } = require('electron') |
5 | |
6 | exports.gives = nest('app.html.header') |
7 | |
8 | const SETTINGS_PAGES = [ |
9 | 'settings', |
10 | 'userEdit' |
11 | ] |
12 | |
13 | exports.create = (api) => { |
14 | return nest('app.html.header', (nav) => { |
15 | const { location, push } = nav |
16 | |
17 | const loc = computed(location, location => { |
18 | if (typeof location !== 'object') return {} |
19 | return location |
20 | }) |
21 | |
22 | if (loc().page === 'splash') return |
23 | |
24 | const isSettings = computed(loc, loc => SETTINGS_PAGES.includes(loc.page)) |
25 | const isAddressBook = computed(loc, loc => loc.page === 'addressBook') |
26 | const isFeed = computed([isAddressBook, isSettings], (p, s) => !p && !s) |
27 | |
28 | return h('Header', [ |
29 | windowControls(), |
30 | h('nav', [ |
31 | h('img.feed', { |
32 | src: when(isFeed, assetPath('feed_on.png'), assetPath('feed.png')), |
33 | 'ev-click': () => push({page: 'blogIndex'}) |
34 | }), |
35 | h('img.addressBook', { |
36 | src: when(isAddressBook, assetPath('address_bk_on.png'), assetPath('address_bk.png')), |
37 | 'ev-click': () => push({page: 'addressBook'}) |
38 | }), |
39 | h('img.settings', { |
40 | src: when(isSettings, assetPath('settings_on.png'), assetPath('settings.png')), |
41 | 'ev-click': () => push({page: 'settings'}) |
42 | }), |
43 | h('i.fa.fa-bell', { |
44 | 'ev-click': () => push({page: 'statsShow'}) |
45 | }) |
46 | ]) |
47 | ]) |
48 | }) |
49 | |
50 | function windowControls () { |
51 | if (process.platform === 'darwin') return |
52 | |
53 | const window = remote.getCurrentWindow() |
54 | const minimize = () => window.minimize() |
55 | const maximize = () => { |
56 | if (!window.isMaximized()) window.maximize() |
57 | else window.unmaximize() |
58 | } |
59 | const close = () => window.close() |
60 | |
61 | return h('div.window-controls', [ |
62 | h('img.min', { |
63 | src: assetPath('minimize.png'), |
64 | 'ev-click': minimize |
65 | }), |
66 | h('img.max', { |
67 | src: assetPath('maximize.png'), |
68 | 'ev-click': maximize |
69 | }), |
70 | h('img.close', { |
71 | src: assetPath('close.png'), |
72 | 'ev-click': close |
73 | }) |
74 | ]) |
75 | } |
76 | } |
77 | |
78 | function assetPath (name) { |
79 | return path.join(__dirname, '../../assets', name) |
80 | } |
81 | |
82 |
Built with git-ssb-web