Files: 3451510316992d414ec76ba5b29681fe359b7428 / lib / depject / page / html / render / settings.js
5080 bytesRaw
1 | const { h } = require('mutant') |
2 | const nest = require('depnest') |
3 | const packageInfo = require('../../../../../package.json') |
4 | |
5 | const themeNames = Object.keys(require('../../../../../styles')) |
6 | |
7 | exports.needs = nest({ |
8 | 'settings.obs.get': 'first', |
9 | 'intl.sync.locales': 'first', |
10 | 'intl.sync.i18n': 'first', |
11 | 'intl.sync.localeNames': 'first' |
12 | }) |
13 | |
14 | exports.gives = nest('page.html.render') |
15 | |
16 | exports.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 locales = api.intl.sync.locales() |
22 | const localeNameLookup = api.intl.sync.localeNames() |
23 | const fontSizes = ['8px', '10px', '12px', '14px', '16px', '18px', '20px'] |
24 | const fontFamilies = [ |
25 | 'serif', |
26 | 'sans-serif', |
27 | 'cursive', |
28 | 'fantasy', |
29 | 'monospace' |
30 | ] |
31 | |
32 | const theme = api.settings.obs.get('patchwork.theme', 'light') |
33 | const lang = api.settings.obs.get('patchwork.lang', '') |
34 | const fontSize = api.settings.obs.get('patchwork.fontSize', '') |
35 | const fontFamily = api.settings.obs.get('patchwork.fontFamily', '') |
36 | const includeParticipating = api.settings.obs.get('patchwork.includeParticipating', false) |
37 | const autoDeleteBlocked = api.settings.obs.get('patchwork.autoDeleteBlocked', false) |
38 | |
39 | // const filterFollowing = api.settings.obs.get('filters.following') |
40 | // const filterSubscriptions = api.settings.obs.get('filters.subscriptions') |
41 | // const onlySubscribed = api.settings.obs.get('filters.onlySubscribed') |
42 | // const filterChannelViewSubscriptions = api.settings.obs.get('filters.channelView.subscriptions') |
43 | |
44 | const prepend = [ |
45 | h('PageHeading', [ |
46 | h('h1', [ |
47 | h('strong', i18n('Settings')) |
48 | ]) |
49 | ]) |
50 | ] |
51 | |
52 | return h('Scroller', { style: { overflow: 'auto' } }, [ |
53 | h('div.wrapper', [ |
54 | h('section.prepend', prepend), |
55 | h('section.content', [ |
56 | |
57 | h('section', [ |
58 | h('h2', i18n('Theme')), |
59 | h('select', { |
60 | style: { 'font-size': '120%' }, |
61 | value: theme, |
62 | 'ev-change': (ev) => theme.set(ev.target.value) |
63 | }, [ |
64 | themeNames.map(name => h('option', { value: name }, [name])) |
65 | ]) |
66 | ]), |
67 | |
68 | h('section', [ |
69 | h('h2', i18n('Language')), |
70 | h('select', { |
71 | style: { 'font-size': '120%' }, |
72 | value: lang, |
73 | 'ev-change': (ev) => lang.set(ev.target.value) |
74 | }, [ |
75 | h('option', { value: '' }, i18n('Default')), |
76 | locales.map(code => h('option', { value: code }, [ |
77 | '[', code, '] ', getLocaleName(code) |
78 | ])) |
79 | ]) |
80 | ]), |
81 | |
82 | h('section', [ |
83 | h('h2', i18n('Font Size')), |
84 | h('select', { |
85 | style: { 'font-size': '120%' }, |
86 | value: fontSize, |
87 | 'ev-change': (ev) => fontSize.set(ev.target.value) |
88 | }, [ |
89 | h('option', { value: '' }, i18n('Default')), |
90 | fontSizes.map(size => h('option', { value: size }, size)) |
91 | ]) |
92 | ]), |
93 | |
94 | h('section', [ |
95 | h('h2', i18n('Font Family')), |
96 | h('select', { |
97 | style: { 'font-size': '120%' }, |
98 | value: fontFamily, |
99 | 'ev-change': (ev) => fontFamily.set(ev.target.value) |
100 | }, [ |
101 | h('option', { value: '' }, i18n('Default')), |
102 | fontFamilies.map(family => h('option', { value: family }, family)) |
103 | ]) |
104 | ]), |
105 | h('h2', i18n('Notification Options')), |
106 | |
107 | h('div', [ |
108 | checkbox(includeParticipating, { |
109 | label: i18n('Include "Participating" tab in navigation bar') |
110 | }) |
111 | ]), |
112 | |
113 | h('h2', i18n('Blocking')), |
114 | |
115 | h('div', [ |
116 | checkbox(autoDeleteBlocked, { |
117 | label: i18n('Automatically delete messages from blocked authors. This is irreversible and will cause problems with clients that share the database but do not support deleted messages. Enable at your own risk!') |
118 | }) |
119 | ]) |
120 | ]), |
121 | |
122 | // h('section', [ |
123 | // h('h2', i18n('Channel Feed Options')), |
124 | |
125 | // h('div', [ |
126 | // checkbox(filterChannelViewSubscriptions, { |
127 | // label: i18n('Hide channel subscription messages') |
128 | // }) |
129 | // ]) |
130 | // ]), |
131 | |
132 | h('section', [ |
133 | h('h2', i18n('Information')), |
134 | |
135 | h('p', `${packageInfo.productName} ${packageInfo.version}`) |
136 | ]) |
137 | ]) |
138 | ]) |
139 | |
140 | function getLocaleName (code) { |
141 | const translated = i18n(code) |
142 | const name = localeNameLookup[code] |
143 | |
144 | if (name !== translated && code !== translated) { |
145 | return `${name} (${translated})` |
146 | } else { |
147 | return name |
148 | } |
149 | } |
150 | }) |
151 | } |
152 | |
153 | function checkbox (param, { label }) { |
154 | return h('label', [ |
155 | h('input', { |
156 | type: 'checkbox', |
157 | checked: param, |
158 | 'ev-change': (ev) => param.set(ev.target.checked) |
159 | }), ' ', label |
160 | ]) |
161 | } |
162 |
Built with git-ssb-web