Disable fetch more button while posts are loaded

This commit is contained in:
arne 2025-11-19 20:21:42 +01:00
commit fa3e3ad5cb

View file

@ -442,7 +442,7 @@
[:path.arc {:d "M50,0 A50,50 180 0,1 100,50"}]])) [:path.arc {:d "M50,0 A50,50 180 0,1 100,50"}]]))
(defn posts-section [{:keys [posts]}] (defn posts-section [{:keys [posts]}]
(let [{:keys [per-page query total displayed-posts]} posts (let [{:keys [per-page query total displayed-posts loading]} posts
n-displayed (count displayed-posts)] n-displayed (count displayed-posts)]
[:section.posts [:section.posts
[:h2 "Favorites"] [:h2 "Favorites"]
@ -456,28 +456,14 @@
" matches")))))] " matches")))))]
[:section.search-form [:section.search-form
[search] [search]
[loading-indicator (select-keys posts [:loading])] [loading-indicator {:loading loading}]
#_(cond (= api-state :loading) " …" #_(cond (= api-state :loading) " …"
(= api-state :error) " API Error!")] (= api-state :error) " API Error!")]
[:section.buttons [:section.buttons
[:button.control-button {:on-click fetch-more-posts!} "⇓ Fetch more"] [:button.control-button {:on-click fetch-more-posts! :disabled (boolean (seq loading))} "⇓ Fetch more"]
[:button.control-button {:on-click disconnect-account!} "▤ Disconnect account"]]] [:button.control-button {:on-click disconnect-account!} "▤ Disconnect account"]]]
[:ul.results (map-indexed (fn [idx p] [:ul.results (map-indexed (fn [idx p]
^{:key idx} [:li.result [post {:post p}]]) displayed-posts)] ^{:key idx} [:li.result [post {:post p}]]) displayed-posts)]]))
#_[:div.load-buttons
[:button
{:on-click (fn [_]
(let [num-posts (count posts)]
(fetch-posts! {:continue? (fn [response]
(and (seq (:body response))
(< (count (:favorites @state)) (+ num-posts 1000))))})))}
"Load more"]
" "
[:button
{:on-click (fn [_]
(fetch-posts! {:continue? (fn [response]
(seq (:body response)))}))}
"Load all"]]]))
;; help section ;; help section