git ssb

2+

mixmix / ticktack



Tree: 65cd9cb5b2fda2efbf0c714425830c59b81a884e

Files: 65cd9cb5b2fda2efbf0c714425830c59b81a884e / app / page / settings.js

5496 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
7
8exports.gives = nest('app.page.settings')
9
10exports.needs = nest({
11 'about.html.image': 'first',
12 'about.obs.name': 'first',
13 'about.obs.description': 'first',
14 'history.sync.push': 'first',
15 'history.obs.store': 'first',
16 'keys.sync.id': 'first',
17 'message.html.markdown': 'first',
18 'settings.sync.get': 'first',
19 'settings.sync.set': 'first',
20 'settings.obs.get': 'first',
21 'translations.sync.strings': 'first',
22 'backup.html.exportIdentityButton': 'first',
23 'backup.html.importIdentityButton': 'first'
24
25})
26
27const LANGUAGES = ['zh', 'en']
28
29exports.create = (api) => {
30 return nest('app.page.settings', settings)
31
32 function settings(location) {
33 // RESET the app when the settings are changed
34 api.settings.obs.get('language')(() => {
35 console.log('language changed, resetting view')
36
37 // clear history back to start page
38 api.history.obs.store().set([
39 { page: 'blogIndex' }
40 ])
41 api.history.sync.push({ page: 'settings' })
42 })
43
44 const webSharingMetricsOption = api.settings.obs.get('ticktack.websharemetrics')
45 const feed = api.keys.sync.id()
46 const strings = api.translations.sync.strings()
47 const currentLanguage = api.settings.sync.get('language')
48 const exportIdentityButton = api.backup.html.exportIdentityButton()
49 const importIdentityButton = api.backup.html.importIdentityButton()
50
51 const editProfile = () => api.history.sync.push({
52 page: 'userEdit',
53 feed,
54 callback: (err, didEdit) => {
55 if (err) throw new Error('Error editing profile', err)
56 api.history.sync.push({ page: 'settings' })
57 }
58 })
59
60 return h('Page -settings', [
61 h('div.content', [
62 h('h1', strings.settingsPage.title),
63 h('section -avatar', [
64 h('div.left'),
65 h('div.right', api.about.html.image(feed))
66 ]),
67 h('section -name', [
68 h('div.left', strings.settingsPage.section.name),
69 h('div.right', [
70 api.about.obs.name(feed),
71 h('img', {
72 src: path.join(__dirname, '../../assets', 'edit.png'),
73 'ev-click': editProfile
74 })
75 // h('i.fa.fa-pencil', { 'ev-click': editProfile })
76 ])
77 ]),
78 h('section -introduction', [
79 h('div.left', strings.settingsPage.section.introduction),
80 h('div.right', computed(api.about.obs.description(feed), d => api.message.html.markdown(d || '')))
81 ]),
82 h('section -language', [
83 h('div.left', strings.settingsPage.section.language),
84 h('div.right', LANGUAGES.map(Language))
85 ]),
86 h('section -zoom', [
87 h('div.left', strings.settingsPage.section.zoom),
88 h('div.right', [zoomButton(-0.1, '-'), zoomButton(+0.1, '+')])
89 ]),
90 h('section -theme', [
91 h('div.left', strings.settingsPage.section.theme),
92 h('div.right', ['light', 'dark'].map(Theme))
93 ]),
94 h('section -sharing', [
95 h('div.left', strings.share.settings.caption),
96 h('div.right', [].concat(
97 webSharingOption('public', strings.share.settings.publicOption),
98 webSharingOption('author', strings.share.settings.authorAndYouOption),
99 webSharingOption('private', strings.share.settings.justYouOption)
100 ))
101 ]),
102 h('section -version', [
103 h('div.left', strings.settingsPage.section.version),
104 h('div.right', version)
105 ]),
106 h('section -backup', [
107 h('div.left', 'Backup'),
108 h('div.right', [
109 exportIdentityButton,
110 importIdentityButton
111 ])
112 ])
113 ])
114 ])
115
116 function Language(lang) {
117 const selectLang = () => api.settings.sync.set({ language: lang })
118 const className = currentLanguage === lang ? '-strong' : ''
119
120 return h('Button -language',
121 {
122 'ev-click': () => selectLang(lang),
123 className
124 },
125 strings.languages[lang]
126 )
127 }
128
129 function Theme(theme) {
130 const currentTheme = api.settings.obs.get('ticktack.theme')
131 const className = computed(currentTheme, t => t === theme ? '-strong' : '')
132
133 return h('Button -language',
134 {
135 'ev-click': () => currentTheme.set(theme),
136 className
137 },
138 strings.themes[theme]
139 )
140 }
141
142 function zoomButton(increment, symbol) {
143 const { getCurrentWebContents } = electron.remote
144 return h('Button -zoom',
145 {
146 'ev-click': () => {
147 var zoomFactor = api.settings.sync.get('ticktack.electron.zoomFactor', 1)
148 var newZoomFactor = zoomFactor + increment
149 api.settings.sync.set('ticktack.electron.zoomFactor', newZoomFactor)
150 getCurrentWebContents().setZoomFactor(newZoomFactor)
151 }
152 },
153 symbol
154 )
155 }
156
157 function webSharingOption(v, label) {
158 let myOption = computed(webSharingMetricsOption, opt => opt === v)
159
160 const selectWebSharingOption = () => {
161 webSharingMetricsOption.set(v)
162 }
163
164 return h('Button -websharingmetrics',
165 {
166 'ev-click': () => selectWebSharingOption(v),
167 className: when(myOption, '-strong', '')
168 },
169 label
170 )
171 }
172 }
173}
174

Built with git-ssb-web