Files: bd5b32f526bb880e8d7e04b41d76e69845d3506e / app / html / header.js
2430 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 isNotifications = computed(loc, loc => loc.page === 'notifications' || loc.page === 'statsShow') |
27 | const isFeed = computed([isAddressBook, isSettings, isNotifications], (p, s, n) => !p && !s && !n) |
28 | |
29 | return h('Header', [ |
30 | windowControls(), |
31 | h('nav', [ |
32 | h('img.feed', { |
33 | src: when(isFeed, assetPath('feed_on.png'), assetPath('feed.png')), |
34 | 'ev-click': () => push({page: 'blogIndex'}) |
35 | }), |
36 | h('img.addressBook', { |
37 | src: when(isAddressBook, assetPath('address_bk_on.png'), assetPath('address_bk.png')), |
38 | 'ev-click': () => push({page: 'addressBook'}) |
39 | }), |
40 | h('img.settings', { |
41 | src: when(isSettings, assetPath('settings_on.png'), assetPath('settings.png')), |
42 | 'ev-click': () => push({page: 'settings'}) |
43 | }), |
44 | h('i.fa', { |
45 | className: when(isNotifications, 'fa-bell', 'fa-bell-o'), |
46 | 'ev-click': () => push({page: 'statsShow'}) |
47 | }) |
48 | ]) |
49 | ]) |
50 | }) |
51 | |
52 | function windowControls () { |
53 | if (process.platform === 'darwin') return |
54 | |
55 | const window = remote.getCurrentWindow() |
56 | const minimize = () => window.minimize() |
57 | const maximize = () => { |
58 | if (!window.isMaximized()) window.maximize() |
59 | else window.unmaximize() |
60 | } |
61 | const close = () => window.close() |
62 | |
63 | return h('div.window-controls', [ |
64 | h('img.min', { |
65 | src: assetPath('minimize.png'), |
66 | 'ev-click': minimize |
67 | }), |
68 | h('img.max', { |
69 | src: assetPath('maximize.png'), |
70 | 'ev-click': maximize |
71 | }), |
72 | h('img.close', { |
73 | src: assetPath('close.png'), |
74 | 'ev-click': close |
75 | }) |
76 | ]) |
77 | } |
78 | } |
79 | |
80 | function assetPath (name) { |
81 | return path.join(__dirname, '../../assets', name) |
82 | } |
83 |
Built with git-ssb-web