git ssb

16+

Dominic / patchbay



Commit 506b936a9c62f45d8e99106da18ee6c393ee5b59

Merge branch 'themes'

Dominic Tarr committed on 8/20/2016, 6:28:01 AM
Parent: a8df69cc1a1b8b743f946e87c87e41c1423b4161
Parent: b80b05485ac96a83b8b083d66d87dd14ee6ec93e

Files changed

index.jschanged
modules/theme.jschanged
index.jsView
@@ -13,8 +13,10 @@
1313 var fs = require('fs')
1414 var path = require('path')
1515 var SbotApi = require('./sbot-api')
1616
17+document.head.appendChild(h('style', require('./style.css.json')))
18+
1719 var modules = require('./modules')
1820
1921 var u = require('./util')
2022
@@ -25,9 +27,7 @@
2527 console.log(require('depject/graph')(modules))
2628 process.exit(0)
2729 }
2830
29-document.head.appendChild(h('style', require('./style.css.json')))
30-
3131 document.body.appendChild(modules['app.js'].app())
3232
3333
modules/theme.jsView
@@ -6,8 +6,13 @@
66 var sbot_links2 = plugs.first(exports.sbot_links2 = [])
77 var avatar_name = plugs.first(exports.avatar_name = [])
88 var blob_url = require('../plugs').first(exports.blob_url = [])
99
10+var defaultTheme = {
11+ id: '&JFa42U6HtPm9k+s+AmpDIAoTJJI/PzoRC/J/WCfduDY=.sha256',
12+ name: 'patchbay-minimal.css'
13+}
14+
1015 var link = document.head.appendChild(h('link', {rel: 'stylesheet'}))
1116 var activeTheme
1217
1318 function useTheme(id) {
@@ -21,20 +26,23 @@
2126 radio.checked = (radio.value === activeTheme)
2227 })
2328 }
2429
25-setImmediate(function () {
26- useTheme(localStorage.themeId || '')
27-})
30+function useSavedTheme() {
31+ useTheme(localStorage.themeId || defaultTheme.id)
32+}
2833
34+setImmediate(useSavedTheme)
35+
2936 function themes() {
3037 return cat([
3138 pull.values([
3239 {
3340 id: '',
3441 name: 'none',
3542 feed: ''
36- }
43+ },
44+ defaultTheme,
3745 ]),
3846 pull(
3947 sbot_links2({
4048 query: [
@@ -74,34 +82,44 @@
7482 link.feed ? h('a', {href: '#'+link.feed}, avatar_name(link.feed)) : ''
7583 )
7684 }
7785
78-function hPull() {
79- var args = [].slice.call(arguments)
80- var stream = args.pop()
81- var parent = h.apply(this, args)
82- pull(stream, pull.drain(function (el) {
83- parent.appendChild(el)
84- }, function (err) {
85- if (err) console.error(err)
86- }))
87- return parent
88-}
89-
9086 function theme_view() {
9187 var themeInput
88+ var themesList = h('form.themes__list')
89+ var themesByKey = {}
9290
91+ pull(
92+ themes(),
93+ pull.unique('id'),
94+ pull.drain(function (theme) {
95+ // replace old versions of themes in the list
96+ var key = theme.feed + theme.name
97+ var oldTheme = themesByKey[key]
98+ theme.el = renderTheme(theme)
99+ themesByKey[key] = theme
100+ if (!oldTheme) {
101+ themesList.appendChild(theme.el)
102+ } else if (oldTheme.id === localStorage.themeId
103+ || oldTheme.id === activeTheme) {
104+ // show old version because the user is still using it
105+ oldTheme.el.appendChild(document.createTextNode(' (old)'))
106+ themesList.appendChild(theme.el)
107+ } else {
108+ themesList.replaceChild(theme.el, oldTheme.el)
109+ }
110+ }, function (err) {
111+ if (err) console.error(err)
112+ })
113+ )
114+
93115 return h('div.column.scroll-y', h('div',
94116 updateForm(h('form.themes__form', {onsubmit: onsubmit, onreset: onreset},
95117 themeInput = h('input.themes__id', {placeholder: 'theme id',
96118 value: link.href}), ' ',
97119 h('input.themes__reset', {type: 'reset'}), ' ',
98120 h('input.themes__submit', {type: 'submit', value: 'Save'}))),
99- hPull('form.themes__list', pull(
100- themes(),
101- pull.unique('id'), // TODO: update existing items with new data
102- pull.map(renderTheme)
103- ))
121+ themesList
104122 ))
105123
106124 function onsubmit(e) {
107125 e.preventDefault()
@@ -109,9 +127,9 @@
109127 }
110128
111129 function onreset(e) {
112130 e.preventDefault()
113- useTheme(localStorage.themeId || '')
131+ useSavedTheme()
114132 }
115133 }
116134
117135 exports.menu_items = function () {

Built with git-ssb-web