git ssb

2+

mixmix / ticktack



Tree: b820672852d31940a46c7ac613f5f5c0195f65b8

Files: b820672852d31940a46c7ac613f5f5c0195f65b8 / app / page / settings.js

4566 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
25exports.create = (api) => {
26 return nest('app.page.settings', settings)
27
28 function settings (location) {
29 // RESET the app when the settings are changed
30 api.settings.obs.get('language')(() => {
31 console.log('language changed, resetting view')
32
33 // clear history back to start page
34 api.history.obs.store().set([
35 { page: 'blogIndex' }
36 ])
37 api.history.sync.push({ page: 'settings' })
38 })
39
40 const webSharingMetricsOption = api.settings.obs.get('ticktack.websharemetrics')
41 const feed = api.keys.sync.id()
42 const strings = api.translations.sync.strings()
43 const currentLanguage = api.settings.sync.get('language')
44
45 const editProfile = () => api.history.sync.push({
46 page: 'userEdit',
47 feed,
48 callback: (err, didEdit) => {
49 if (err) throw new Error('Error editing profile', err)
50 api.history.sync.push({ page: 'settings' })
51 }
52 })
53
54 return h('Page -settings', [
55 h('div.content', [
56 h('h1', strings.settingsPage.title),
57 h('section -avatar', [
58 h('div.left'),
59 h('div.right', api.about.html.image(feed))
60 ]),
61 h('section -name', [
62 h('div.left', strings.settingsPage.section.name),
63 h('div.right', [
64 api.about.obs.name(feed),
65 h('img', {
66 src: path.join(__dirname, '../../assets', 'edit.png'),
67 'ev-click': editProfile
68 })
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 h('section -sharing', [
85 h('div.left', strings.share.settings.caption),
86 h('div.right', [].concat(
87 webSharingOption('public', strings.share.settings.publicOption),
88 webSharingOption('author', strings.share.settings.authorAndYouOption),
89 webSharingOption('private', strings.share.settings.justYouOption)
90 ))
91 ]),
92 h('section -version', [
93 h('div.left', strings.settingsPage.section.version),
94 h('div.right', version)
95 ])
96 ])
97 ])
98
99 function Language (lang) {
100 const selectLang = () => api.settings.sync.set({ language: lang })
101 const className = currentLanguage === lang ? '-strong' : ''
102
103 return h('Button -language',
104 {
105 'ev-click': () => selectLang(lang),
106 className
107 },
108 strings.languages[lang]
109 )
110 }
111
112 function zoomButton (increment, symbol) {
113 const { getCurrentWebContents } = electron.remote
114 return h('Button -zoom',
115 {
116 'ev-click': () => {
117 var zoomFactor = api.settings.sync.get('ticktack.electron.zoomFactor', 1)
118 var newZoomFactor = zoomFactor + increment
119 api.settings.sync.set('ticktack.electron.zoomFactor', newZoomFactor)
120 getCurrentWebContents().setZoomFactor(newZoomFactor)
121 }
122 },
123 symbol
124 )
125 }
126
127 function webSharingOption (v, label) {
128 let myOption = computed(webSharingMetricsOption, opt => opt === v)
129
130 const selectWebSharingOption = () => {
131 webSharingMetricsOption.set(v)
132 }
133
134 return h('Button -websharingmetrics',
135 {
136 'ev-click': () => selectWebSharingOption(v),
137 className: when(myOption, '-strong', '')
138 },
139 label
140 )
141 }
142 }
143}
144

Built with git-ssb-web