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