app/page/settings.jsView |
---|
1 | 1 | const nest = require('depnest') |
2 | | -const { h, computed } = require('mutant') |
| 2 | +const { h, computed, when } = require('mutant') |
3 | 3 | const electron = require('electron') |
4 | 4 | const path = require('path') |
5 | 5 | const { version } = require('../../package.json') |
6 | 6 | |
30 | 30 | |
31 | 31 | exports.create = (api) => { |
32 | 32 | return nest('app.page.settings', settings) |
33 | 33 | |
34 | | - function settings (location) { |
| 34 | + function settings(location) { |
35 | 35 | |
36 | 36 | api.settings.obs.get('language')(() => { |
37 | 37 | console.log('language changed, resetting view') |
38 | 38 | |
39 | 39 | |
40 | 40 | api.history.obs.store().set([ |
41 | 41 | { page: 'blogIndex' } |
42 | 42 | ]) |
43 | | - api.history.sync.push({page: 'settings'}) |
| 43 | + api.history.sync.push({ page: 'settings' }) |
44 | 44 | }) |
45 | 45 | |
| 46 | + const webSharingMetricsOption = api.settings.obs.get('websharemetrics') |
46 | 47 | const feed = api.keys.sync.id() |
47 | 48 | const strings = api.translations.sync.strings() |
48 | 49 | const currentLanguage = api.settings.sync.get('language') |
49 | 50 | |
| 51 | + |
50 | 52 | const editProfile = () => api.history.sync.push({ |
51 | 53 | page: 'userEdit', |
52 | 54 | feed, |
53 | 55 | callback: (err, didEdit) => { |
83 | 85 | h('div.right', LANGUAGES.map(Language)) |
84 | 86 | ]), |
85 | 87 | h('section -zoom', [ |
86 | 88 | h('div.left', strings.settingsPage.section.zoom), |
87 | | - h('div.right', [ zoomButton(-0.1, '-'), zoomButton(+0.1, '+') ]) |
| 89 | + h('div.right', [zoomButton(-0.1, '-'), zoomButton(+0.1, '+')]) |
88 | 90 | ]), |
| 91 | + h('section -sharing', [ |
| 92 | + h('div.left', 'Web Sharing Metrics'), |
| 93 | + h('div.right', [].concat( |
| 94 | + webSharingOption('public', 'publish metrics openly'), |
| 95 | + webSharingOption('author', 'publish for you and author'), |
| 96 | + webSharingOption('private', 'publish just for you') |
| 97 | + )) |
| 98 | + ]), |
89 | 99 | h('section -version', [ |
90 | 100 | h('div.left', strings.settingsPage.section.version), |
91 | 101 | h('div.right', version) |
92 | 102 | ]) |
93 | 103 | ]) |
94 | 104 | ]) |
95 | 105 | |
96 | | - function Language (lang) { |
| 106 | + function Language(lang) { |
97 | 107 | const selectLang = () => api.settings.sync.set({ language: lang }) |
98 | 108 | const className = currentLanguage === lang ? '-strong' : '' |
99 | 109 | |
100 | 110 | return h('Button -language', |
105 | 115 | strings.languages[lang] |
106 | 116 | ) |
107 | 117 | } |
108 | 118 | |
109 | | - function zoomButton (increment, symbol) { |
| 119 | + function zoomButton(increment, symbol) { |
110 | 120 | const { getCurrentWebContents } = electron.remote |
111 | 121 | return h('Button -zoom', |
112 | 122 | { |
113 | 123 | 'ev-click': () => { |
119 | 129 | }, |
120 | 130 | symbol |
121 | 131 | ) |
122 | 132 | } |
| 133 | + |
| 134 | + function webSharingOption(v, label) { |
| 135 | + let myOption = computed(webSharingMetricsOption, opt => opt === v) |
| 136 | + |
| 137 | + const selectWebSharingOption = () => { |
| 138 | + api.settings.sync.set({ websharemetrics: v }) |
| 139 | + } |
| 140 | + |
| 141 | + return h('Button -websharingmetrics', |
| 142 | + { |
| 143 | + 'ev-click': () => selectWebSharingOption(v), |
| 144 | + className: when(myOption, '-strong', '') |
| 145 | + }, |
| 146 | + label |
| 147 | + ) |
| 148 | + } |
| 149 | + |
123 | 150 | } |
124 | 151 | } |