Skip to content

Commit 749b4ca

Browse files
committed
fix(filter): do not keep loading themes if new filter is set
1 parent eb73efb commit 749b4ca

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

dev/js/main.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,17 @@ function createLightbox (id) {
8181
* ======================
8282
*/
8383

84+
let running_sort = 0;
85+
8486
const search = /** @type {HTMLInputElement} */ (document.getElementById('searchInput'))
8587

8688
search.addEventListener('keydown', e => {
8789

88-
if (e.key === "Enter")
89-
sort(localStorage.sort, search.value)
90+
if (e.key === "Enter")
91+
sort(localStorage.sort, search.value)
92+
93+
})
9094

91-
})
92-
9395
const search_button = /** @type {HTMLInputElement} */ (document.getElementById('searchButton'))
9496
search_button.addEventListener('click', () => sort(localStorage.sort, search.value))
9597

@@ -125,6 +127,8 @@ function createLightbox (id) {
125127
* @param {string=} filter Term to filter the themes.
126128
**/
127129
function sort (kind, filter) {
130+
131+
const my_run = ++running_sort
128132

129133
localStorage.sort = kind
130134

@@ -198,13 +202,17 @@ function createLightbox (id) {
198202

199203
for (const [index, entry] of data)
200204
{
205+
if (running_sort !== my_run)
206+
return
207+
201208
const card = new Card(entry, index)
202209
card.render(outputContainer)
203-
await new Promise(r => setTimeout(r, 666));
210+
await new Promise(r => setTimeout(r, 444))
204211
}
205212

206-
})
207-
}
213+
}
214+
)
215+
}
208216

209217
// add themes
210218
const outputContainer = document.getElementById('themes_container')

0 commit comments

Comments
 (0)