git ssb

10+

Matt McKegg / patchwork



Tree: ec22930fce654eefee73dc9cc02061810988d4bd

Files: ec22930fce654eefee73dc9cc02061810988d4bd / modules / page / html / render / settings.js

2828 bytesRaw
1var { h, when } = require('mutant')
2var nest = require('depnest')
3
4var themeNames = Object.keys(require('../../../../styles'))
5
6exports.needs = nest({
7 'settings.obs.get': 'first',
8 'settings.sync.set': 'first',
9 'intl.sync.locales': 'first',
10 'intl.sync.i18n': 'first',
11 'intl.sync.localeNames': 'first'
12})
13
14exports.gives = nest('page.html.render')
15
16exports.create = function (api) {
17 return nest('page.html.render', function channel (path) {
18 if (path !== '/settings') return
19 const i18n = api.intl.sync.i18n
20
21 const currentTheme = api.settings.obs.get('patchwork.theme')
22 const currentLang = api.settings.obs.get('patchwork.lang')
23 const locales = api.intl.sync.locales()
24 const localeNameLookup = api.intl.sync.localeNames()
25 const filterFollowing = api.settings.obs.get('filters.following')
26
27 var prepend = [
28 h('PageHeading', [
29 h('h1', [
30 h('strong', i18n('Settings'))
31 ])
32 ])
33 ]
34
35 return h('Scroller', { style: { overflow: 'auto' } }, [
36 h('div.wrapper', [
37 h('section.prepend', prepend),
38 h('section.content', [
39
40 h('section', [
41 h('h2', i18n('Theme')),
42 h('select', {
43 style: {
44 'font-size': '120%'
45 },
46 value: when(currentTheme, currentTheme, 'light'),
47 'ev-change': (ev) => api.settings.sync.set({
48 patchwork: {theme: ev.target.value}
49 })
50 }, [
51 themeNames.map(name => h('option', {value: name}, [name]))
52 ])
53 ]),
54
55 h('section', [
56 h('h2', i18n('Language')),
57 h('select', {
58 style: {
59 'font-size': '120%'
60 },
61 value: when(currentLang, currentLang, 'en'),
62 'ev-change': (ev) => api.settings.sync.set({
63 patchwork: {lang: ev.target.value}
64 })
65 }, [
66 locales.map(code => h('option', {value: code}, [
67 code.toUpperCase(), ' - ', getLocaleName(code)
68 ]))
69 ])
70 ]),
71
72 h('section', [
73 h('h2', i18n('Filters')),
74 h('label', [
75 h('input', {
76 type: 'checkbox',
77 checked: filterFollowing,
78 'ev-change': (ev) => api.settings.sync.set({
79 filters: {following: ev.target.checked}
80 })
81 }), i18n(' Hide following messages')
82 ])
83 ])
84 ])
85 ])
86 ])
87
88 function getLocaleName (code) {
89 var translated = i18n(code)
90 var name = localeNameLookup[code]
91
92 if (name !== translated && code !== translated) {
93 return `${name} (${translated})`
94 } else {
95 return name
96 }
97 }
98 })
99}
100

Built with git-ssb-web