git ssb

2+

mixmix / ticktack



Tree: 354bcc491180e33154ea042ff61d5912ae2d95ab

Files: 354bcc491180e33154ea042ff61d5912ae2d95ab / app / page / settings.js

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

Built with git-ssb-web