fix race in filters
authorRadek Czajka <rczajka@rczajka.pl>
Fri, 9 Jun 2023 15:49:36 +0000 (17:49 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Fri, 9 Jun 2023 15:49:36 +0000 (17:49 +0200)
src/catalogue/static/2022/book/filter.js

index 59e810a..43b6c4e 100644 (file)
@@ -8,10 +8,17 @@
     function get_page(page, search, ordering, callback) {
         get_page_by_url('.?page=' + page + '&order=' + ordering + '&search=' + search, callback);
     }
+
+    let lastFulfilledPage = 0;
+
     function get_page_by_url(url, callback) {
+        let requestTime = + new Date();
         $.get(
             url,
             function(data) {
+                if (lastFulfilledPage > requestTime) return;
+                lastFulfilledPage = requestTime;
+
                 html = $(data);
                 objectList = $('#object-list', html);
                 paginate = $('#paginate', html);