git ssb

16+

Dominic / patchbay



Commit d9ce9323d9a5a315cef7fac9f453d316b265746a

make /settings listen to keyboard scroll shortcuts

mixmix committed on 7/18/2019, 4:39:25 PM
Parent: 2314dae55e7e5f8e1fa87ef113061d9a8da38fcf

Files changed

app/html/settings/custom-styles.mcsschanged
app/page/settings.jschanged
app/html/settings/custom-styles.mcssView
@@ -1,9 +1,9 @@
11 CustomStyles {
22 textarea {
33 font-family: monospace
44 line-height: 1.2rem
5- max-width: calc(100% - 1rem)
5 + width: 100%
66 min-height: 400px
77 border: 1px solid gainsboro
88 }
99
app/page/settings.jsView
@@ -24,30 +24,26 @@
2424 }, '/settings')
2525 }
2626
2727 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!
28 + const state = {
29 + groups: groupSettings(api.app.html.settings()),
30 + activeGroup: Value(0)
31 + }
3632
3733 var page = h('SettingsPage', { title: '/settings' }, [
38- h('div.container', computed(activeGroup, _activeGroup => {
34 + h('div.container', computed(state.activeGroup, activeGroup => {
3935 return [
40- h('section.groups', groupNames.map(group => {
36 + h('section.groups', state.groups.map((group, i) => {
4137 return h('div.group',
4238 {
43- 'className': group === _activeGroup ? '-active' : '',
44- 'ev-click': () => activeGroup.set(group)
39 + 'className': i === activeGroup ? '-active' : '',
40 + 'ev-click': () => state.activeGroup.set(i)
4541 },
46- group
42 + group.name
4743 )
4844 })),
49- h('section.group-settings', groups[_activeGroup].map(Setting))
45 + h('section.group-settings', state.groups[activeGroup].subgroups.map(Setting))
5046 ]
5147 }))
5248 ])
5349
@@ -59,14 +55,19 @@
5955 }
6056
6157 var { container } = api.app.html.scroller({ prepend: page })
6258 container.title = '/settings'
59 + container.keyboardScroll = function (n) {
60 + if (isNaN(n)) return
61 +
62 + state.activeGroup.set((state.activeGroup() + n) % state.groups.length)
63 + }
6364 return container
6465 }
6566 }
6667
6768 function groupSettings (settings) {
68- return settings
69 + const groupedByGroup = settings
6970 .reduce((acc, setting) => {
7071 if (!setting.title || !setting.body) throw new Error('setting sections require title, body')
7172
7273 const group = (setting.group || setting.title).toLowerCase()
@@ -74,5 +75,18 @@
7475 else acc[group] = [setting]
7576
7677 return acc
7778 }, {})
79 +
80 + return Object.keys(groupedByGroup)
81 + .map(name => {
82 + return {
83 + name,
84 + subgroups: groupedByGroup[name]
85 + }
86 + })
87 + .sort((a, b) => {
88 + if (a === 'general') return -1
89 + else if (b === 'general') return 1
90 + else return a < b ? -1 : +1
91 + })
7892 }

Built with git-ssb-web