[front/feat] show post
This commit is contained in:
parent
97561beed8
commit
16b4a83c45
3 changed files with 39 additions and 25 deletions
|
@ -4,7 +4,10 @@
|
||||||
[clojure.string :as str]))
|
[clojure.string :as str]))
|
||||||
|
|
||||||
|
|
||||||
(def api-url "http://localhost:3000/hp")
|
|
||||||
|
(if js/goog.DEBUG
|
||||||
|
(def api-url "http://localhost:3000/api")
|
||||||
|
(def api-url "./api"))
|
||||||
|
|
||||||
(defn endpoint
|
(defn endpoint
|
||||||
"Concat params to api-uri by /"
|
"Concat params to api-uri by /"
|
||||||
|
@ -20,36 +23,36 @@
|
||||||
(js/console.log page)
|
(js/console.log page)
|
||||||
(case page
|
(case page
|
||||||
;; -- URL @ "/" --------------------------------------------------------
|
;; -- URL @ "/" --------------------------------------------------------
|
||||||
:frontpage {:db set-page
|
:frontpage {:db set-page}
|
||||||
:dispatch [:get-page]}
|
|
||||||
;; -- URL @ "/about" --------------------------------------------------------
|
;; -- URL @ "/about" --------------------------------------------------------
|
||||||
:about {:db set-page}
|
:about {:db set-page}
|
||||||
|
|
||||||
;; -- URL @ "/item" --------------------------------------------------------
|
;; -- URL @ "/item" --------------------------------------------------------
|
||||||
:item {:db set-page}
|
:item {:db set-page
|
||||||
))))
|
:dispatch [:get-page {:id id}]}))))
|
||||||
|
|
||||||
|
|
||||||
(reg-event-fx
|
(reg-event-fx
|
||||||
:get-page
|
:get-page
|
||||||
(fn [{:keys [db]} _]
|
(fn [{:keys [db]} [_ params]]
|
||||||
{:db (assoc-in db [:loading :tags] true)
|
{:fetch {:method :get
|
||||||
:fetch {:method :get
|
:url (endpoint "hp" (:id params))
|
||||||
:url "https://api.github.com/orgs/day8"
|
:mode :cors
|
||||||
:mode :cors
|
:referrer :no-referrer
|
||||||
:referrer :no-referrer
|
:credentials :omit
|
||||||
:credentials :omit
|
:timeout 10000
|
||||||
:timeout 5000
|
:response-content-types {#"application/.*json" :json}
|
||||||
:response-content-types {#"application/.*json" :json}
|
:on-success [:get-page-success]
|
||||||
:on-success [:get-page-success]
|
:on-failure [:initialize-db]}
|
||||||
:on-failure [:initialize-db]
|
|
||||||
}}))
|
:db (-> db
|
||||||
|
(assoc-in [:loading :post] true))}))
|
||||||
|
|
||||||
(reg-event-db
|
(reg-event-db
|
||||||
:get-page-success
|
:get-page-success
|
||||||
(fn [db [_ {repos_url :body}]]
|
(fn [db [_ {body :body}]]
|
||||||
(-> db
|
(-> db
|
||||||
(assoc :repos_url (:id repos_url)) )))
|
(assoc-in [:loading :post] false)
|
||||||
|
(assoc :post (:content body)))))
|
||||||
|
|
||||||
(reg-event-db
|
(reg-event-db
|
||||||
:initialize-db
|
:initialize-db
|
||||||
|
|
|
@ -6,3 +6,13 @@
|
||||||
:current-route
|
:current-route
|
||||||
(fn [db]
|
(fn [db]
|
||||||
(:current-route db)))
|
(:current-route db)))
|
||||||
|
|
||||||
|
(reg-sub
|
||||||
|
:loading
|
||||||
|
(fn [db _]
|
||||||
|
(:loading db)))
|
||||||
|
|
||||||
|
(reg-sub
|
||||||
|
:post
|
||||||
|
(fn [db _]
|
||||||
|
(:post db)))
|
||||||
|
|
|
@ -18,10 +18,11 @@
|
||||||
[:li [:a {:href "stub"} "Source code"]]]])
|
[:li [:a {:href "stub"} "Source code"]]]])
|
||||||
|
|
||||||
(defn item-page []
|
(defn item-page []
|
||||||
(let [current-route @(subscribe [:current-route])
|
(let [loading @(subscribe [:loading])
|
||||||
id (get-in current-route [:path-params :id])]
|
post @(subscribe [:post])]
|
||||||
[:div
|
[:div
|
||||||
[:h2 "Selected item " id]]))
|
{:dangerouslySetInnerHTML
|
||||||
|
{:__html post}}]))
|
||||||
|
|
||||||
(defn nav [{:keys [current-route]}]
|
(defn nav [{:keys [current-route]}]
|
||||||
(let [active #(when (= % (-> current-route :data :name)) "> ")]
|
(let [active #(when (= % (-> current-route :data :name)) "> ")]
|
||||||
|
@ -31,7 +32,7 @@
|
||||||
[:li
|
[:li
|
||||||
[:a {:href (rfe/href :about)} (active :about) "About"]]
|
[:a {:href (rfe/href :about)} (active :about) "About"]]
|
||||||
[:li
|
[:li
|
||||||
[:a {:href (rfe/href :item {:id 233})} (active :item) "Item 233"]]]))
|
[:a {:href (rfe/href :item {:id 96817849})} (active :item) "Item 96817849"]]]))
|
||||||
|
|
||||||
|
|
||||||
(defn current-page []
|
(defn current-page []
|
||||||
|
|
Loading…
Reference in a new issue