git ssb

2+

mixmix / ticktack



Tree: 7647ceaff9ecb9fbc0386af2a317afc08778b794

Files: 7647ceaff9ecb9fbc0386af2a317afc08778b794 / app / html / header.js

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

Built with git-ssb-web