git ssb

2+

mixmix / ticktack



Tree: 46d4867aaf1d06eb2172236393ad7fc7f2ff354e

Files: 46d4867aaf1d06eb2172236393ad7fc7f2ff354e / app / html / header.js

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

Built with git-ssb-web