git ssb

2+

mixmix / ticktack



Tree: 1967ee98ce129f2ab3b072bcdeac1ad9f0990092

Files: 1967ee98ce129f2ab3b072bcdeac1ad9f0990092 / app / page / settings.js

2469 bytesRaw
1const nest = require('depnest')
2const { h } = require('mutant')
3
4exports.gives = nest('app.page.settings')
5
6exports.needs = nest({
7 'about.html.image': 'first',
8 'about.obs.name': 'first',
9 'history.sync.push': 'first',
10 'history.obs.store': 'first',
11 'keys.sync.id': 'first',
12 'settings.sync.get': 'first',
13 'settings.sync.set': 'first',
14 'settings.obs.get': 'first',
15 'translations.sync.strings': 'first',
16})
17
18const LANGUAGES = ['zh', 'en']
19
20// TODO - this needs moving somewhere upstream
21// const DEFAULT_SETTINGS = {
22// onboarded: false,
23// language: 'zh'
24// }
25
26exports.create = (api) => {
27 return nest('app.page.settings', settings)
28
29 function settings (location) {
30
31 // RESET the app when the settings are changed
32 api.settings.obs.get('language')(() => {
33 console.log('language changed, resetting view')
34
35 // clear history back to start page
36 api.history.obs.store().set([
37 { page: 'blogIndex' }
38 ])
39 api.history.sync.push({page: 'settings'})
40 })
41
42 const feed = api.keys.sync.id()
43 const strings = api.translations.sync.strings()
44 const currentLanguage = api.settings.sync.get('language')
45
46 const editProfile = () => api.history.sync.push({
47 page:'userEdit',
48 feed,
49 callback: (err, didEdit) => {
50 if (err) throw new Error ('Error editing profile', err)
51 api.history.sync.push({ page: 'settings' })
52 }
53 })
54
55 return h('Page -settings', [
56 h('div.content', [
57 h('h1', strings.settingsPage.title),
58 h('section -profile', [
59 h('header', strings.settingsPage.section.profile),
60 h('div.profile', [
61 h('div.name', api.about.obs.name(feed)),
62 api.about.html.image(feed),
63 ]),
64 h('div.actions', [
65 h('Button', { 'ev-click': editProfile }, [
66 strings.settingsPage.action.edit,
67 h('i.fa.fa-pencil')
68 ])
69 ])
70 ]),
71 h('section -language', [
72 h('header', strings.settingsPage.section.language),
73 h('div.languages', LANGUAGES.map(Language))
74 ])
75 ])
76 ])
77
78 function Language (lang) {
79 const selectLang = () => api.settings.sync.set({ language: lang })
80 const className = currentLanguage === lang ? '-strong' : ''
81
82 return h('Button -language',
83 {
84 'ev-click': () => selectLang(lang),
85 className
86 },
87 lang
88 )
89 }
90
91 }
92}
93
94

Built with git-ssb-web