[front/perf] load more answers
This commit is contained in:
parent
249234dee0
commit
8c20ed32f3
2 changed files with 40 additions and 22 deletions
|
@ -69,26 +69,42 @@
|
|||
(reg-event-fx
|
||||
:get-question
|
||||
(fn [{:keys [db]} [_ params]]
|
||||
{:fetch {:method :get
|
||||
:url (endpoint "hq" (:id params))
|
||||
:params (:query params)
|
||||
:mode :cors
|
||||
:referrer :no-referrer
|
||||
:credentials :omit
|
||||
:timeout 10000
|
||||
:response-content-types {#"application/.*json" :json}
|
||||
:on-success [:get-question-success]
|
||||
:on-failure [:get-question-failure]}
|
||||
(let [loading (if (empty? (:query params))
|
||||
:question
|
||||
:comment)]
|
||||
{:fetch {:method :get
|
||||
:url (endpoint "hq" (:id params))
|
||||
:params (:query params)
|
||||
:mode :cors
|
||||
:referrer :no-referrer
|
||||
:credentials :omit
|
||||
:timeout 10000
|
||||
:response-content-types {#"application/.*json" :json}
|
||||
:on-success [:get-question-success]
|
||||
:on-failure [:get-question-failure]}
|
||||
|
||||
:db (-> db
|
||||
(assoc-in [:loading :question] true))}))
|
||||
:db (-> db
|
||||
(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
|
||||
|
|
|
@ -68,15 +68,17 @@
|
|||
{:__html (:content ans)}}]])]
|
||||
(if end?
|
||||
[:p "answers end here."]
|
||||
[:div
|
||||
[:button {:type "button"
|
||||
:href (-> post :paging :next)
|
||||
:class "btn btn-blue"
|
||||
:on-click #(rfe/push-state
|
||||
:question
|
||||
{:id (-> post :paging :question_id)}
|
||||
{:cursor (-> post :paging :cursor)
|
||||
:session_id (-> post :paging :session_id)})}]])])))
|
||||
(if (:comment loading)
|
||||
[:p "loading comment..."]
|
||||
[:div
|
||||
[:button {:type "button"
|
||||
:href (-> post :paging :next)
|
||||
:class "btn btn-blue"
|
||||
:on-click #(rfe/push-state
|
||||
:question
|
||||
{:id (-> post :paging :question_id)}
|
||||
{:cursor (-> post :paging :cursor)
|
||||
:session_id (-> post :paging :session_id)})}]]))])))
|
||||
|
||||
(defn nav [{:keys [current-route]}]
|
||||
(let [active #(when (= % (-> current-route :data :name)) "> ")]
|
||||
|
|
Loading…
Reference in a new issue