git ssb

16+

Dominic / patchbay



Commit 48e2cdec810952a1c79bffd16684974c8c841222

Update theme picker calculation

Charles Lehner authored on 9/25/2016, 3:50:21 PM
Dominic Tarr committed on 10/24/2016, 8:44:52 PM
Parent: 2a3b514162af82f82e2d8b229bcf5db9c72bbc96

Files changed

modules/theme.jschanged
modules/theme.jsView
@@ -93,29 +93,42 @@
9393
9494 function theme_view() {
9595 var themeInput
9696 var themesList = h('form.themes__list')
97- var themesByKey = {}
97 + var themesPerFeed = {/* feedid: {blobid||name: theme} */}
9898
9999 pull(
100100 themes(),
101- pull.unique('id'),
102101 pull.drain(function (theme) {
103- // don't show old versions of theme
104- var key = theme.feed + theme.name
105- var newerTheme = themesByKey[key]
102 + var map = themesPerFeed[theme.feed] || (themesPerFeed[theme.feed] = {})
103 + // replace old theme
104 + var prevByName = map[theme.name]
105 + var prevById = map[theme.id]
106106 theme.el = renderTheme(theme)
107- themesByKey[key] = theme
108- if (!newerTheme) {
109- // show latest theme
107 + map[theme.name] = theme
108 + map[theme.id] = theme
109 + if (prevById) {
110 + // remove theme which is having its id reused
111 + themesList.removeChild(prevById.el)
112 + // prevById.el.appendChild(document.createTextNode(' (renamed)'))
113 + if (prevById === prevByName) {
114 + prevByName = null
115 + }
116 + }
117 + if (prevByName) {
118 + // update theme
119 + if (prevByName.id === localStorage.themeId
120 + || prevByName.id === activeTheme) {
121 + // keep old version because the user is still using it
122 + prevByName.el.appendChild(document.createTextNode(' (old)'))
123 + insertAfter(themesList, theme.el, prevByName.el)
124 + } else {
125 + // replace old version
126 + themesList.replaceChild(theme.el, prevByName.el)
127 + }
128 + } else {
129 + // show new theme
110130 themesList.appendChild(theme.el)
111- } else if (theme.id === localStorage.themeId
112- || theme.id === activeTheme) {
113- // show old version because the user is still using it
114- theme.el.appendChild(document.createTextNode(' (old)'))
115- insertAfter(themesList, theme.el, newerTheme.el)
116- } else {
117- // ignore old version of theme
118131 }
119132 }, function (err) {
120133 if (err) console.error(err)
121134 })

Built with git-ssb-web