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