git ssb

2+

mixmix / ticktack



Tree: 992639a1213cadc35e523df588f878128718bc5b

Files: 992639a1213cadc35e523df588f878128718bc5b / app / page / settings.js

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

Built with git-ssb-web