Files: cf39375daad7bbcd8a42807ea1459802a41ee050 / app / page / settings.js
2157 bytesRaw
1 | const nest = require('depnest') |
2 | const { h } = require('mutant') |
3 | |
4 | exports.gives = nest('app.page.settings') |
5 | |
6 | exports.needs = nest({ |
7 | 'about.html.image': 'first', |
8 | 'about.obs.name': 'first', |
9 | 'history.sync.push': 'first', |
10 | 'keys.sync.id': 'first', |
11 | 'settings.sync.get': 'first', |
12 | 'settings.sync.set': 'first', |
13 | 'settings.obs.get': 'first', |
14 | 'translations.sync.strings': 'first', |
15 | }) |
16 | |
17 | const LANGUAGES = ['zh', 'en'] |
18 | const DEFAULT_SETTINGS = { |
19 | language: 'zh' |
20 | } |
21 | |
22 | exports.create = (api) => { |
23 | return nest('app.page.settings', settings) |
24 | |
25 | function settings (location) { |
26 | // RESET the app when the settings are changed |
27 | api.settings.obs.get()(() => { |
28 | window.location.reload() |
29 | }) |
30 | |
31 | const feed = api.keys.sync.id() |
32 | const strings = api.translations.sync.strings() |
33 | const currentLanguage = api.settings.sync.get('language') |
34 | |
35 | const handleEdit = () => api.history.sync.push({ |
36 | page:'userEdit', |
37 | feed, |
38 | callback: (err, didEdit) => { |
39 | if (err) throw new Error ('Error editing profile', err) |
40 | api.history.sync.push({ page: 'settings' }) |
41 | } |
42 | }) |
43 | |
44 | return h('Page -settings', [ |
45 | h('div.container', [ |
46 | h('h1', strings.settingsPage.title), |
47 | h('section -profile', [ |
48 | h('header', strings.settingsPage.section.profile), |
49 | h('div.profile', [ |
50 | h('div.name', api.about.obs.name(feed)), |
51 | api.about.html.image(feed), |
52 | ]), |
53 | h('div.actions', [ |
54 | h('Button', { 'ev-click': handleEdit}, [ |
55 | strings.settingsPage.action.edit, |
56 | h('i.fa.fa-pencil') |
57 | ]) |
58 | ]) |
59 | ]), |
60 | h('section -language', [ |
61 | h('header', strings.settingsPage.section.language), |
62 | h('div.languages', LANGUAGES.map(Language)) |
63 | ]) |
64 | ]) |
65 | ]) |
66 | |
67 | function Language (lang) { |
68 | const selectLang = () => api.settings.sync.set({ language: lang }) |
69 | const className = currentLanguage === lang ? '-primary' : '' |
70 | |
71 | return h('Button -language', |
72 | { |
73 | 'ev-click': () => selectLang(lang), |
74 | className |
75 | }, |
76 | lang |
77 | ) |
78 | } |
79 | |
80 | } |
81 | } |
82 | |
83 |
Built with git-ssb-web