git ssb

10+

Matt McKegg / patchwork



Tree: f2455a01ab1393669b02aa0a03d1e57bb3b2c88a

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

3662 bytesRaw
1var { h, when } = require('mutant')
2var nest = require('depnest')
3var packageInfo = require('../../../../package.json')
4
5var themeNames = Object.keys(require('../../../../styles'))
6
7exports.needs = nest({
8 'settings.obs.get': 'first',
9 'settings.sync.set': 'first',
10 'intl.sync.locales': 'first',
11 'intl.sync.i18n': 'first',
12 'intl.sync.localeNames': 'first'
13})
14
15exports.gives = nest('page.html.render')
16
17exports.create = function (api) {
18 return nest('page.html.render', function channel (path) {
19 if (path !== '/settings') return
20 const i18n = api.intl.sync.i18n
21
22 const locales = api.intl.sync.locales()
23 const localeNameLookup = api.intl.sync.localeNames()
24 const fontSizes = ['8px', '10px', '12px', '14px', '16px', '18px', '20px']
25
26 const theme = api.settings.obs.get('patchwork.theme', 'light')
27 const lang = api.settings.obs.get('patchwork.lang', '')
28 const fontSize = api.settings.obs.get('patchwork.fontSize', '')
29 const filterFollowing = api.settings.obs.get('filters.following')
30 const onlySubscribed = api.settings.obs.get('filters.onlySubscribed')
31
32 var prepend = [
33 h('PageHeading', [
34 h('h1', [
35 h('strong', i18n('Settings'))
36 ])
37 ])
38 ]
39
40 return h('Scroller', { style: { overflow: 'auto' } }, [
41 h('div.wrapper', [
42 h('section.prepend', prepend),
43 h('section.content', [
44
45 h('section', [
46 h('h2', i18n('Theme')),
47 h('select', {
48 style: { 'font-size': '120%' },
49 value: theme,
50 'ev-change': (ev) => theme.set(ev.target.value)
51 }, [
52 themeNames.map(name => h('option', {value: name}, [name]))
53 ])
54 ]),
55
56 h('section', [
57 h('h2', i18n('Language')),
58 h('select', {
59 style: { 'font-size': '120%' },
60 value: lang,
61 'ev-change': (ev) => lang.set(ev.target.value)
62 }, [
63 h('option', {value: ''}, i18n('Default')),
64 locales.map(code => h('option', {value: code}, [
65 '[', code, '] ', getLocaleName(code)
66 ]))
67 ])
68 ]),
69
70 h('section', [
71 h('h2', i18n('Font Size')),
72 h('select', {
73 style: { 'font-size': '120%' },
74 value: fontSize,
75 'ev-change': (ev) => fontSize.set(ev.target.value)
76 }, [
77 h('option', {value: ''}, i18n('Default')),
78 fontSizes.map(size => h('option', {value: size}, size))
79 ])
80 ]),
81
82 h('section', [
83 h('h2', i18n('Public Feed Options')),
84
85 h('div', [
86 checkbox(filterFollowing, {
87 label: i18n('Hide following messages')
88 })
89 ]),
90
91 h('div', [
92 checkbox(onlySubscribed, {
93 label: i18n('Only include posts from subscribed channels')
94 })
95 ])
96 ]),
97
98 h('section', [
99 h('h2', i18n('Information')),
100
101 h('p', `${packageInfo.productName} ${packageInfo.version}`)
102 ])
103 ])
104 ])
105 ])
106
107 function getLocaleName (code) {
108 var translated = i18n(code)
109 var name = localeNameLookup[code]
110
111 if (name !== translated && code !== translated) {
112 return `${name} (${translated})`
113 } else {
114 return name
115 }
116 }
117 })
118}
119
120function checkbox (param, {label}) {
121 return h('label', [
122 h('input', {
123 type: 'checkbox',
124 checked: param,
125 'ev-change': (ev) => param.set(ev.target.checked)
126 }), ' ', label
127 ])
128}
129

Built with git-ssb-web