[front/perf] load more answers

This commit is contained in:
SouthFox 2023-09-17 18:00:16 +08:00
parent 249234dee0
commit 8c20ed32f3
2 changed files with 40 additions and 22 deletions

View file

@ -69,6 +69,9 @@
(reg-event-fx
:get-question
(fn [{:keys [db]} [_ params]]
(let [loading (if (empty? (:query params))
:question
:comment)]
{:fetch {:method :get
:url (endpoint "hq" (:id params))
:params (:query params)
@ -81,14 +84,27 @@
:on-failure [:get-question-failure]}
:db (-> db
(assoc-in [:loading :question] true))}))
(assoc-in [:loading loading] true))})))
(defn merge-question
[db body]
(if (empty? (:post db))
(-> db
(assoc-in [:post :question] (:question body))
(assoc-in [:post :answers] (:answers body))
(assoc-in [:post :paging] (:paging body)))
(-> db
(assoc-in [:post :question] (:question body))
(update-in [:post :answers] into (:answers body))
(assoc-in [:post :paging] (:paging body)))))
(reg-event-db
:get-question-success
(fn [db [_ {body :body}]]
(-> db
(assoc-in [:loading :question] false)
(assoc :post body))))
(assoc-in [:loading :comment] false)
(merge-question body))))
(reg-event-db
:get-question-failure

View file

@ -68,6 +68,8 @@
{:__html (:content ans)}}]])]
(if end?
[:p "answers end here."]
(if (:comment loading)
[:p "loading comment..."]
[:div
[:button {:type "button"
:href (-> post :paging :next)
@ -76,7 +78,7 @@
:question
{:id (-> post :paging :question_id)}
{:cursor (-> post :paging :cursor)
:session_id (-> post :paging :session_id)})}]])])))
:session_id (-> post :paging :session_id)})}]]))])))
(defn nav [{:keys [current-route]}]
(let [active #(when (= % (-> current-route :data :name)) "> ")]