[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 (reg-event-fx
:get-question :get-question
(fn [{:keys [db]} [_ params]] (fn [{:keys [db]} [_ params]]
(let [loading (if (empty? (:query params))
:question
:comment)]
{:fetch {:method :get {:fetch {:method :get
:url (endpoint "hq" (:id params)) :url (endpoint "hq" (:id params))
:params (:query params) :params (:query params)
@ -81,14 +84,27 @@
:on-failure [:get-question-failure]} :on-failure [:get-question-failure]}
:db (-> db :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 (reg-event-db
:get-question-success :get-question-success
(fn [db [_ {body :body}]] (fn [db [_ {body :body}]]
(-> db (-> db
(assoc-in [:loading :question] false) (assoc-in [:loading :question] false)
(assoc :post body)))) (assoc-in [:loading :comment] false)
(merge-question body))))
(reg-event-db (reg-event-db
:get-question-failure :get-question-failure

View file

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