[front/feat] show question page
This commit is contained in:
parent
8dec6f8900
commit
82145993dc
3 changed files with 63 additions and 1 deletions
|
@ -27,7 +27,13 @@
|
||||||
|
|
||||||
;; -- URL @ "/item" --------------------------------------------------------
|
;; -- URL @ "/item" --------------------------------------------------------
|
||||||
:item {:db set-page
|
:item {:db set-page
|
||||||
:dispatch [:get-page {:id id}]}))))
|
:dispatch [:get-page {:id id}]}
|
||||||
|
|
||||||
|
;; -- URL @ "/item" --------------------------------------------------------
|
||||||
|
:question {:db set-page
|
||||||
|
:dispatch [:get-question {:id id}]}
|
||||||
|
))))
|
||||||
|
|
||||||
|
|
||||||
(reg-event-fx
|
(reg-event-fx
|
||||||
:get-page
|
:get-page
|
||||||
|
@ -59,6 +65,36 @@
|
||||||
(assoc-in [:loading :post] false)
|
(assoc-in [:loading :post] false)
|
||||||
(assoc :post body))))
|
(assoc :post body))))
|
||||||
|
|
||||||
|
(reg-event-fx
|
||||||
|
:get-question
|
||||||
|
(fn [{:keys [db]} [_ params]]
|
||||||
|
{:fetch {:method :get
|
||||||
|
:url (endpoint "hq" (:id 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))}))
|
||||||
|
|
||||||
|
(reg-event-db
|
||||||
|
:get-question-success
|
||||||
|
(fn [db [_ {body :body}]]
|
||||||
|
(-> db
|
||||||
|
(assoc-in [:loading :question] false)
|
||||||
|
(assoc :post body))))
|
||||||
|
|
||||||
|
(reg-event-db
|
||||||
|
:get-question-failure
|
||||||
|
(fn [db [_ {body :body}]]
|
||||||
|
(-> db
|
||||||
|
(assoc-in [:loading :question] false)
|
||||||
|
(assoc :post body))))
|
||||||
|
|
||||||
(reg-event-db
|
(reg-event-db
|
||||||
:initialize-db
|
:initialize-db
|
||||||
(fn [_ _]
|
(fn [_ _]
|
||||||
|
|
|
@ -19,6 +19,12 @@
|
||||||
{:name :item
|
{:name :item
|
||||||
:view frontend.views/item-page
|
:view frontend.views/item-page
|
||||||
:link-text "Item"
|
:link-text "Item"
|
||||||
|
:parameters {:path {:id int?}
|
||||||
|
:query {(ds/opt :foo) keyword?}}}]
|
||||||
|
["hq/:id"
|
||||||
|
{:name :question
|
||||||
|
:view frontend.views/question-page
|
||||||
|
:link-text "Question"
|
||||||
:parameters {:path {:id int?}
|
:parameters {:path {:id int?}
|
||||||
:query {(ds/opt :foo) keyword?}}}]]])
|
:query {(ds/opt :foo) keyword?}}}]]])
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,26 @@
|
||||||
{:dangerouslySetInnerHTML
|
{:dangerouslySetInnerHTML
|
||||||
{:__html (:content post)}}]])))
|
{:__html (:content post)}}]])))
|
||||||
|
|
||||||
|
(defn question-page []
|
||||||
|
(let [loading @(subscribe [:loading])
|
||||||
|
post @(subscribe [:post])]
|
||||||
|
(if (:question loading)
|
||||||
|
[:p "Loading..."]
|
||||||
|
[:div
|
||||||
|
[:h1 {:class "text-2xl"}
|
||||||
|
(-> post :question :title)]
|
||||||
|
[:div {:class "space-y-5"}
|
||||||
|
(for [ans (:answers post)]
|
||||||
|
^{:key ans}
|
||||||
|
[:div {:class "p-3 bg-white shadow rounded-lg"}
|
||||||
|
[:img
|
||||||
|
{:src (-> ans :author :avatar_url)}]
|
||||||
|
[:a {:class "text-lg"}
|
||||||
|
(-> ans :author :name)]
|
||||||
|
[:div
|
||||||
|
{:dangerouslySetInnerHTML
|
||||||
|
{:__html (:content ans)}}]
|
||||||
|
])]])))
|
||||||
|
|
||||||
(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