Files: 1b9e4fefcc2bb238e43c37df39cb776444d8978e / app / page / settings.js
1193 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 | 'settings.sync.get': 'first', |
8 | 'settings.sync.set': 'first', |
9 | 'settings.obs.get': 'first', |
10 | 'translations.sync.strings': 'first', |
11 | }) |
12 | |
13 | const LANGUAGES = ['zh', 'en'] |
14 | const DEFAULT_SETTINGS = { |
15 | language: 'zh' |
16 | } |
17 | |
18 | exports.create = (api) => { |
19 | return nest('app.page.settings', settings) |
20 | |
21 | function settings (location) { |
22 | // RESET the app when the settings are changed |
23 | api.settings.obs.get()(() => { |
24 | window.location.reload() |
25 | }) |
26 | |
27 | const strings = api.translations.sync.strings() |
28 | const currentLanguage = api.settings.sync.get('language') |
29 | |
30 | function Language (lang) { |
31 | const selectLang = () => api.settings.sync.set({ language: lang }) |
32 | const className = currentLanguage === lang ? '-primary' : '' |
33 | |
34 | return h('Button -language', |
35 | { |
36 | 'ev-click': () => selectLang(lang), |
37 | className |
38 | }, |
39 | lang |
40 | ) |
41 | } |
42 | |
43 | return h('Page -settings', [ |
44 | h('div.container', [ |
45 | h('h1', strings.settings), |
46 | h('div.languages', LANGUAGES.map(Language)) |
47 | ]) |
48 | ]) |
49 | } |
50 | } |
51 | |
52 |
Built with git-ssb-web