git ssb

16+

Dominic / patchbay



Tree: bea9630a530f26bfccd3c236c760ec44e13813b7

Files: bea9630a530f26bfccd3c236c760ec44e13813b7 / app / page / settings.js

2082 bytesRaw
1const nest = require('depnest')
2const { h, Value, computed } = require('mutant')
3
4exports.gives = nest({
5 'app.html.menuItem': true,
6 'app.page.settings': true
7})
8
9exports.needs = nest({
10 'app.html.settings': 'map',
11 'app.html.scroller': 'first',
12 'app.sync.goTo': 'first'
13})
14
15exports.create = function (api) {
16 return nest({
17 'app.html.menuItem': menuItem,
18 'app.page.settings': settingsPage
19 })
20
21 function menuItem () {
22 return h('a', {
23 'ev-click': () => api.app.sync.goTo({ page: 'settings' })
24 }, '/settings')
25 }
26
27 function settingsPage (location) {
28 const groups = groupSettings(api.app.html.settings())
29 const groupNames = Object.keys(groups)
30 .sort((a, b) => {
31 if (a === 'general') return -1
32 else if (b === 'general') return 1
33 else return a < b ? -1 : +1
34 })
35 const activeGroup = Value('general') // NOTE this assume this group exists!
36
37 var page = h('SettingsPage', { title: '/settings' }, [
38 h('div.container', computed(activeGroup, _activeGroup => {
39 return [
40 h('section.groups', groupNames.map(group => {
41 return h('div.group',
42 {
43 'className': group === _activeGroup ? '-active' : '',
44 'ev-click': () => activeGroup.set(group)
45 },
46 group
47 )
48 })),
49 h('section.group-settings', groups[_activeGroup].map(Setting))
50 ]
51 }))
52 ])
53
54 function Setting (setting) {
55 return h('div.setting', [
56 h('h2', setting.title),
57 setting.body
58 ])
59 }
60
61 var { container } = api.app.html.scroller({ prepend: page })
62 container.title = '/settings'
63 return container
64 }
65}
66
67function groupSettings (settings) {
68 return settings
69 .reduce((acc, setting) => {
70 if (!setting.title || !setting.body) throw new Error('setting sections require title, body')
71
72 const group = (setting.group || setting.title).toLowerCase()
73 if (acc[group]) acc[group].push(setting)
74 else acc[group] = [setting]
75
76 return acc
77 }, {})
78}
79

Built with git-ssb-web