Commit 506b936a9c62f45d8e99106da18ee6c393ee5b59
Merge branch 'themes'
Dominic Tarr committed on 8/20/2016, 6:28:01 AMParent: a8df69cc1a1b8b743f946e87c87e41c1423b4161
Parent: b80b05485ac96a83b8b083d66d87dd14ee6ec93e
Files changed
index.js | changed |
modules/theme.js | changed |
index.js | ||
---|---|---|
@@ -13,8 +13,10 @@ | ||
13 | 13 | var fs = require('fs') |
14 | 14 | var path = require('path') |
15 | 15 | var SbotApi = require('./sbot-api') |
16 | 16 | |
17 | +document.head.appendChild(h('style', require('./style.css.json'))) | |
18 | + | |
17 | 19 | var modules = require('./modules') |
18 | 20 | |
19 | 21 | var u = require('./util') |
20 | 22 | |
@@ -25,9 +27,7 @@ | ||
25 | 27 | console.log(require('depject/graph')(modules)) |
26 | 28 | process.exit(0) |
27 | 29 | } |
28 | 30 | |
29 | -document.head.appendChild(h('style', require('./style.css.json'))) | |
30 | - | |
31 | 31 | document.body.appendChild(modules['app.js'].app()) |
32 | 32 | |
33 | 33 |
modules/theme.js | ||
---|---|---|
@@ -6,8 +6,13 @@ | ||
6 | 6 | var sbot_links2 = plugs.first(exports.sbot_links2 = []) |
7 | 7 | var avatar_name = plugs.first(exports.avatar_name = []) |
8 | 8 | var blob_url = require('../plugs').first(exports.blob_url = []) |
9 | 9 | |
10 | +var defaultTheme = { | |
11 | + id: '&JFa42U6HtPm9k+s+AmpDIAoTJJI/PzoRC/J/WCfduDY=.sha256', | |
12 | + name: 'patchbay-minimal.css' | |
13 | +} | |
14 | + | |
10 | 15 | var link = document.head.appendChild(h('link', {rel: 'stylesheet'})) |
11 | 16 | var activeTheme |
12 | 17 | |
13 | 18 | function useTheme(id) { |
@@ -21,20 +26,23 @@ | ||
21 | 26 | radio.checked = (radio.value === activeTheme) |
22 | 27 | }) |
23 | 28 | } |
24 | 29 | |
25 | -setImmediate(function () { | |
26 | - useTheme(localStorage.themeId || '') | |
27 | -}) | |
30 | +function useSavedTheme() { | |
31 | + useTheme(localStorage.themeId || defaultTheme.id) | |
32 | +} | |
28 | 33 | |
34 | +setImmediate(useSavedTheme) | |
35 | + | |
29 | 36 | function themes() { |
30 | 37 | return cat([ |
31 | 38 | pull.values([ |
32 | 39 | { |
33 | 40 | id: '', |
34 | 41 | name: 'none', |
35 | 42 | feed: '' |
36 | - } | |
43 | + }, | |
44 | + defaultTheme, | |
37 | 45 | ]), |
38 | 46 | pull( |
39 | 47 | sbot_links2({ |
40 | 48 | query: [ |
@@ -74,34 +82,44 @@ | ||
74 | 82 | link.feed ? h('a', {href: '#'+link.feed}, avatar_name(link.feed)) : '' |
75 | 83 | ) |
76 | 84 | } |
77 | 85 | |
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 | - | |
90 | 86 | function theme_view() { |
91 | 87 | var themeInput |
88 | + var themesList = h('form.themes__list') | |
89 | + var themesByKey = {} | |
92 | 90 | |
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 | + | |
93 | 115 | return h('div.column.scroll-y', h('div', |
94 | 116 | updateForm(h('form.themes__form', {onsubmit: onsubmit, onreset: onreset}, |
95 | 117 | themeInput = h('input.themes__id', {placeholder: 'theme id', |
96 | 118 | value: link.href}), ' ', |
97 | 119 | h('input.themes__reset', {type: 'reset'}), ' ', |
98 | 120 | 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 | |
104 | 122 | )) |
105 | 123 | |
106 | 124 | function onsubmit(e) { |
107 | 125 | e.preventDefault() |
@@ -109,9 +127,9 @@ | ||
109 | 127 | } |
110 | 128 | |
111 | 129 | function onreset(e) { |
112 | 130 | e.preventDefault() |
113 | - useTheme(localStorage.themeId || '') | |
131 | + useSavedTheme() | |
114 | 132 | } |
115 | 133 | } |
116 | 134 | |
117 | 135 | exports.menu_items = function () { |
Built with git-ssb-web