Files: d6b91ba09ab42e5e8e2f376d3ddbc9cf8a9c0d76 / app / page / settings.js
2237 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 | |
19 | // TODO - this needs moving somewhere upstream |
20 | // const DEFAULT_SETTINGS = { |
21 | // onboarded: false, |
22 | // language: 'zh' |
23 | // } |
24 | |
25 | exports.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()(() => { |
31 | window.location.reload() |
32 | }) |
33 | |
34 | const feed = api.keys.sync.id() |
35 | const strings = api.translations.sync.strings() |
36 | const currentLanguage = api.settings.sync.get('language') |
37 | |
38 | const handleEdit = () => api.history.sync.push({ |
39 | page:'userEdit', |
40 | feed, |
41 | callback: (err, didEdit) => { |
42 | if (err) throw new Error ('Error editing profile', err) |
43 | api.history.sync.push({ page: 'settings' }) |
44 | } |
45 | }) |
46 | |
47 | return h('Page -settings', [ |
48 | h('div.container', [ |
49 | h('h1', strings.settingsPage.title), |
50 | h('section -profile', [ |
51 | h('header', strings.settingsPage.section.profile), |
52 | h('div.profile', [ |
53 | h('div.name', api.about.obs.name(feed)), |
54 | api.about.html.image(feed), |
55 | ]), |
56 | h('div.actions', [ |
57 | h('Button', { 'ev-click': handleEdit}, [ |
58 | strings.settingsPage.action.edit, |
59 | h('i.fa.fa-pencil') |
60 | ]) |
61 | ]) |
62 | ]), |
63 | h('section -language', [ |
64 | h('header', strings.settingsPage.section.language), |
65 | h('div.languages', LANGUAGES.map(Language)) |
66 | ]) |
67 | ]) |
68 | ]) |
69 | |
70 | function Language (lang) { |
71 | const selectLang = () => api.settings.sync.set({ language: lang }) |
72 | const className = currentLanguage === lang ? '-primary' : '' |
73 | |
74 | return h('Button -language', |
75 | { |
76 | 'ev-click': () => selectLang(lang), |
77 | className |
78 | }, |
79 | lang |
80 | ) |
81 | } |
82 | |
83 | } |
84 | } |
85 | |
86 |
Built with git-ssb-web