Commit 48e2cdec810952a1c79bffd16684974c8c841222
Update theme picker calculation
Charles Lehner authored on 9/25/2016, 3:50:21 PMDominic Tarr committed on 10/24/2016, 8:44:52 PM
Parent: 2a3b514162af82f82e2d8b229bcf5db9c72bbc96
Files changed
modules/theme.js | changed |
modules/theme.js | |||
---|---|---|---|
@@ -93,29 +93,42 @@ | |||
93 | 93 … | ||
94 | 94 … | function theme_view() { | |
95 | 95 … | var themeInput | |
96 | 96 … | var themesList = h('form.themes__list') | |
97 | - var themesByKey = {} | ||
97 … | + var themesPerFeed = {/* feedid: {blobid||name: theme} */} | ||
98 | 98 … | ||
99 | 99 … | pull( | |
100 | 100 … | themes(), | |
101 | - pull.unique('id'), | ||
102 | 101 … | 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] | ||
106 | 106 … | 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 | ||
110 | 130 … | 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 | ||
118 | 131 … | } | |
119 | 132 … | }, function (err) { | |
120 | 133 … | if (err) console.error(err) | |
121 | 134 … | }) |
Built with git-ssb-web