git ssb

2+

mixmix / ticktack



Tree: c24946ad74bf65f4ff10b27c737cc02628f88c75

Files: c24946ad74bf65f4ff10b27c737cc02628f88c75 / app / page / settings.js

4242 bytesRaw
1const nest = require('depnest')
2const { h, computed } = 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
29// TODO - this needs moving somewhere upstream
30// const DEFAULT_SETTINGS = {
31// onboarded: false,
32// language: 'zh'
33// }
34
35exports.create = (api) => {
36 return nest('app.page.settings', settings)
37
38 function settings(location) {
39 // RESET the app when the settings are changed
40 api.settings.obs.get('language')(() => {
41 console.log('language changed, resetting view')
42
43 // clear history back to start page
44 api.history.obs.store().set([
45 { page: 'blogIndex' }
46 ])
47 api.history.sync.push({ page: 'settings' })
48 })
49
50 const feed = api.keys.sync.id()
51 const strings = api.translations.sync.strings()
52 const currentLanguage = api.settings.sync.get('language')
53 const exportIdentityButton = api.backup.html.exportIdentityButton()
54 const importIdentityButton = api.backup.html.importIdentityButton()
55
56 const editProfile = () => api.history.sync.push({
57 page: 'userEdit',
58 feed,
59 callback: (err, didEdit) => {
60 if (err) throw new Error('Error editing profile', err)
61 api.history.sync.push({ page: 'settings' })
62 }
63 })
64
65 return h('Page -settings', [
66 h('div.content', [
67 h('h1', strings.settingsPage.title),
68 h('section -avatar', [
69 h('div.left'),
70 h('div.right', api.about.html.image(feed))
71 ]),
72 h('section -name', [
73 h('div.left', strings.settingsPage.section.name),
74 h('div.right', [
75 api.about.obs.name(feed),
76 h('img', {
77 src: path.join(__dirname, '../../assets', 'edit.png'),
78 'ev-click': editProfile
79 })
80 // h('i.fa.fa-pencil', { 'ev-click': editProfile })
81 ])
82 ]),
83 h('section -introduction', [
84 h('div.left', strings.settingsPage.section.introduction),
85 h('div.right', computed(api.about.obs.description(feed), d => api.message.html.markdown(d || '')))
86 ]),
87 h('section -language', [
88 h('div.left', strings.settingsPage.section.language),
89 h('div.right', LANGUAGES.map(Language))
90 ]),
91 h('section -zoom', [
92 h('div.left', strings.settingsPage.section.zoom),
93 h('div.right', [zoomButton(-0.1, '-'), zoomButton(+0.1, '+')])
94 ]),
95 h('section -version', [
96 h('div.left', strings.settingsPage.section.version),
97 h('div.right', version)
98 ]),
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