[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
|
(reg-event-fx
|
||||||
:get-question
|
:get-question
|
||||||
(fn [{:keys [db]} [_ params]]
|
(fn [{:keys [db]} [_ params]]
|
||||||
{:fetch {:method :get
|
(let [loading (if (empty? (:query params))
|
||||||
:url (endpoint "hq" (:id params))
|
:question
|
||||||
:params (:query params)
|
:comment)]
|
||||||
:mode :cors
|
{:fetch {:method :get
|
||||||
:referrer :no-referrer
|
:url (endpoint "hq" (:id params))
|
||||||
:credentials :omit
|
:params (:query params)
|
||||||
:timeout 10000
|
:mode :cors
|
||||||
:response-content-types {#"application/.*json" :json}
|
:referrer :no-referrer
|
||||||
:on-success [:get-question-success]
|
:credentials :omit
|
||||||
:on-failure [:get-question-failure]}
|
:timeout 10000
|
||||||
|
:response-content-types {#"application/.*json" :json}
|
||||||
|
:on-success [:get-question-success]
|
||||||
|
: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
|
||||||
|
|
|
@ -68,15 +68,17 @@
|
||||||
{:__html (:content ans)}}]])]
|
{:__html (:content ans)}}]])]
|
||||||
(if end?
|
(if end?
|
||||||
[:p "answers end here."]
|
[:p "answers end here."]
|
||||||
[:div
|
(if (:comment loading)
|
||||||
[:button {:type "button"
|
[:p "loading comment..."]
|
||||||
:href (-> post :paging :next)
|
[:div
|
||||||
:class "btn btn-blue"
|
[:button {:type "button"
|
||||||
:on-click #(rfe/push-state
|
:href (-> post :paging :next)
|
||||||
:question
|
:class "btn btn-blue"
|
||||||
{:id (-> post :paging :question_id)}
|
:on-click #(rfe/push-state
|
||||||
{:cursor (-> post :paging :cursor)
|
:question
|
||||||
:session_id (-> post :paging :session_id)})}]])])))
|
{:id (-> post :paging :question_id)}
|
||||||
|
{:cursor (-> post :paging :cursor)
|
||||||
|
: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)) "> ")]
|
||||||
|
|
Loading…
Reference in a new issue