git ssb

2+

mixmix / ticktack



Tree: 4caad32bdc583a475ce49a53d2293c67c0f52cb6

Files: 4caad32bdc583a475ce49a53d2293c67c0f52cb6 / app / page / settings.js

4666 bytesRaw
1const nest = require('depnest')
2const { h, computed, when } = require('mutant')
3const electron = require('electron')
4const path = require('path')
5const { version } = require('../../package.json')
6
7exports.gives = nest('app.page.settings')
8
9exports.needs = nest({
10 'about.html.image': 'first',
11 'about.obs.name': 'first',
12 'about.obs.description': 'first',
13 'history.sync.push': 'first',
14 'history.obs.store': 'first',
15 'keys.sync.id': 'first',
16 'message.html.markdown': 'first',
17 'settings.sync.get': 'first',
18 'settings.sync.set': 'first',
19 'settings.obs.get': 'first',
20 'translations.sync.strings': 'first'
21})
22
23const LANGUAGES = ['zh', 'en']
24
25// TODO - this needs moving somewhere upstream
26// const DEFAULT_SETTINGS = {
27// onboarded: false,
28// language: 'zh'
29// }
30
31exports.create = (api) => {
32 return nest('app.page.settings', settings)
33
34 function settings(location) {
35 // RESET the app when the settings are changed
36 api.settings.obs.get('language')(() => {
37 console.log('language changed, resetting view')
38
39 // clear history back to start page
40 api.history.obs.store().set([
41 { page: 'blogIndex' }
42 ])
43 api.history.sync.push({ page: 'settings' })
44 })
45
46 const webSharingMetricsOption = api.settings.obs.get('websharemetrics')
47 const feed = api.keys.sync.id()
48 const strings = api.translations.sync.strings()
49 const currentLanguage = api.settings.sync.get('language')
50
51
52 const editProfile = () => api.history.sync.push({
53 page: 'userEdit',
54 feed,
55 callback: (err, didEdit) => {
56 if (err) throw new Error('Error editing profile', err)
57 api.history.sync.push({ page: 'settings' })
58 }
59 })
60
61 return h('Page -settings', [
62 h('div.content', [
63 h('h1', strings.settingsPage.title),
64 h('section -avatar', [
65 h('div.left'),
66 h('div.right', api.about.html.image(feed))
67 ]),
68 h('section -name', [
69 h('div.left', strings.settingsPage.section.name),
70 h('div.right', [
71 api.about.obs.name(feed),
72 h('img', {
73 src: path.join(__dirname, '../../assets', 'edit.png'),
74 'ev-click': editProfile
75 })
76 // h('i.fa.fa-pencil', { 'ev-click': editProfile })
77 ])
78 ]),
79 h('section -introduction', [
80 h('div.left', strings.settingsPage.section.introduction),
81 h('div.right', computed(api.about.obs.description(feed), d => api.message.html.markdown(d || '')))
82 ]),
83 h('section -language', [
84 h('div.left', strings.settingsPage.section.language),
85 h('div.right', LANGUAGES.map(Language))
86 ]),
87 h('section -zoom', [
88 h('div.left', strings.settingsPage.section.zoom),
89 h('div.right', [zoomButton(-0.1, '-'), zoomButton(+0.1, '+')])
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 ]),
99 h('section -version', [
100 h('div.left', strings.settingsPage.section.version),
101 h('div.right', version)
102 ])
103 ])
104 ])
105
106 function Language(lang) {
107 const selectLang = () => api.settings.sync.set({ language: lang })
108 const className = currentLanguage === lang ? '-strong' : ''
109
110 return h('Button -language',
111 {
112 'ev-click': () => selectLang(lang),
113 className
114 },
115 strings.languages[lang]
116 )
117 }
118
119 function zoomButton(increment, symbol) {
120 const { getCurrentWebContents } = electron.remote
121 return h('Button -zoom',
122 {
123 'ev-click': () => {
124 var zoomFactor = api.settings.sync.get('ticktack.electron.zoomFactor', 1)
125 var newZoomFactor = zoomFactor + increment
126 var zoomFactor = api.settings.sync.set('ticktack.electron.zoomFactor', newZoomFactor)
127 getCurrentWebContents().setZoomFactor(newZoomFactor)
128 }
129 },
130 symbol
131 )
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
150 }
151}
152

Built with git-ssb-web