Commit 0dbf73654513a31bdd3cab71a2047f263c054072
basic language settings toggleable
mix irving committed on 8/21/2017, 8:39:42 AMParent: 7d97c83df2eafb6c49340cb80ba64420cf4d764e
Files changed
app/html/header.js | changed |
app/page/settings.js | changed |
main.js | changed |
package-lock.json | changed |
package.json | changed |
translations/sync.js | changed |
app/html/header.js | ||
---|---|---|
@@ -15,9 +15,10 @@ | ||
15 | 15 | // h('h1', computed(nav.location, e => e.element.title)), |
16 | 16 | |
17 | 17 | h('div.tools', [ |
18 | 18 | h('i.fa.fa-address-book', { 'ev-click': () => nav.push({page:'userFind'}) }), |
19 | - h('i.fa.fa-hashtag', { 'ev-click': () => nav.push({page:'groupFind'}) }) | |
19 | + h('i.fa.fa-hashtag', { 'ev-click': () => nav.push({page:'groupFind'}) }), | |
20 | + h('i.fa.fa-gear', { 'ev-click': () => nav.push({page:'settings'}) }) | |
20 | 21 | ]) |
21 | 22 | ]), |
22 | 23 | ]) |
23 | 24 | }) |
app/page/settings.js | ||
---|---|---|
@@ -3,20 +3,45 @@ | ||
3 | 3 | |
4 | 4 | exports.gives = nest('app.page.settings') |
5 | 5 | |
6 | 6 | exports.needs = nest({ |
7 | + 'settings.sync.get': 'first', | |
8 | + 'settings.sync.set': 'first', | |
9 | + 'settings.obs.get': 'first', | |
7 | 10 | 'translations.sync.strings': 'first', |
8 | 11 | }) |
9 | 12 | |
13 | +const LANGUAGES = ['zh', 'en'] | |
14 | +const DEFAULT_SETTINGS = { | |
15 | + language: 'zh' | |
16 | +} | |
17 | + | |
10 | 18 | exports.create = (api) => { |
11 | 19 | return nest('app.page.settings', settings) |
12 | 20 | |
13 | 21 | function settings (location) { |
22 | + // RESET the app when the settings are changed | |
23 | + api.settings.obs.get()(() => { | |
24 | + window.location.reload() | |
25 | + }) | |
14 | 26 | |
15 | - return h('Page -settings', {title: strings.settings}, [ | |
16 | - '****' | |
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('div.language', { 'ev-click': () => selectLang(lang) }, | |
35 | + h('Button', { className }, lang) | |
36 | + ) | |
37 | + } | |
38 | + | |
39 | + return h('Page -settings', [ | |
40 | + h('div.container', [ | |
41 | + h('h1', strings.settings), | |
42 | + h('div.languages', LANGUAGES.map(Language)) | |
43 | + ]) | |
17 | 44 | ]) |
18 | 45 | } |
19 | 46 | } |
20 | 47 | |
21 | - | |
22 | - |
main.js | ||
---|---|---|
@@ -9,11 +9,11 @@ | ||
9 | 9 | require('./context-menu') |
10 | 10 | |
11 | 11 | // from more specialized to more general |
12 | 12 | const sockets = combine( |
13 | + require('patch-settings'), | |
13 | 14 | //we always need to have translations first! |
14 | - {translations: require('./translations/sync')}, | |
15 | - require('./unread'), | |
15 | + { translations: require('./translations/sync') }, | |
16 | 16 | { |
17 | 17 | about: require('./about'), |
18 | 18 | app: require('./app'), |
19 | 19 | blob: require('./blob'), |
@@ -24,8 +24,9 @@ | ||
24 | 24 | message: require('./message'), |
25 | 25 | router: require('./router'), |
26 | 26 | styles: require('./styles'), |
27 | 27 | state: require('./state/obs'), |
28 | + unread: require('./unread'), | |
28 | 29 | }, |
29 | 30 | require('patchcore') |
30 | 31 | ) |
31 | 32 | |
@@ -41,11 +42,4 @@ | ||
41 | 42 | function (err, follows) { |
42 | 43 | console.log('autofollowed', err, follows); |
43 | 44 | }) |
44 | 45 | |
45 | - | |
46 | - | |
47 | - | |
48 | - | |
49 | - | |
50 | - | |
51 | - |
package-lock.json | ||
---|---|---|
The diff is too large to show. Use a local git client to view these changes. Old file size: 196213 bytes New file size: 197011 bytes |
package.json | ||
---|---|---|
@@ -32,8 +32,9 @@ | ||
32 | 32 | "morphdom": "^2.3.3", |
33 | 33 | "mutant": "^3.21.2", |
34 | 34 | "obv-debounce": "^1.0.2", |
35 | 35 | "open-external": "^0.1.1", |
36 | + "patch-settings": "^1.0.0", | |
36 | 37 | "patchcore": "^1.10.0", |
37 | 38 | "pull-next": "^1.0.1", |
38 | 39 | "pull-obv": "^1.3.0", |
39 | 40 | "pull-stream": "^3.6.0", |
translations/sync.js | ||
---|---|---|
@@ -2,16 +2,19 @@ | ||
2 | 2 | const merge = require('lodash/merge') |
3 | 3 | |
4 | 4 | exports.gives = nest('translations.sync.strings') |
5 | 5 | |
6 | -const en = require('./en.js') | |
7 | -const zh = require('./zh.js') | |
6 | +exports.needs = nest('settings.sync.get', 'first') | |
8 | 7 | |
8 | +const languages = { | |
9 | + en: require('./en.js'), | |
10 | + zh: require('./zh.js') | |
11 | +} | |
12 | + | |
9 | 13 | exports.create = (api) => { |
10 | - // return nest('translations.sync.strings', () => en) | |
11 | - | |
12 | 14 | return nest('translations.sync.strings', () => { |
13 | - return merge({}, en, zh) | |
15 | + const language = api.settings.sync.get('language', 'zh') | |
16 | + | |
17 | + return merge({}, languages.en, languages[language]) | |
14 | 18 | }) |
15 | 19 | } |
16 | 20 | |
17 | - |
Built with git-ssb-web