[front/feat] show more answers

This commit is contained in:
SouthFox 2023-09-12 19:08:35 +08:00
parent 36112c3195
commit 64aa07a572
3 changed files with 28 additions and 17 deletions

View file

@ -4,7 +4,6 @@
[clojure.string :as str]))
(if js/goog.DEBUG
(def api-url "http://localhost:3000/api")
(def api-url "./api"))
@ -16,7 +15,7 @@
(reg-event-fx
:set-active-page
(fn [{:keys [db]} [_ {:keys [new-match id]}]]
(fn [{:keys [db]} [_ {:keys [new-match id query]}]]
(let [page (get-in new-match [:data :name])
set-page (assoc db :current-route new-match)]
(case page
@ -27,11 +26,13 @@
;; -- URL @ "/item" --------------------------------------------------------
:item {:db set-page
:dispatch [:get-page {:id id}]}
:dispatch [:get-page {:id id
:query query}]}
;; -- URL @ "/item" --------------------------------------------------------
:question {:db set-page
:dispatch [:get-question {:id id}]}
:dispatch [:get-question {:id id
:query query}]}
))))
@ -70,6 +71,7 @@
(fn [{:keys [db]} [_ params]]
{:fetch {:method :get
:url (endpoint "hq" (:id params))
:params (:query params)
:mode :cors
:referrer :no-referrer
:credentials :omit

View file

@ -25,13 +25,14 @@
{:name :question
:view frontend.views/question-page
:link-text "Question"
:parameters {:path {:id int?}
:query {(ds/opt :foo) keyword?}}}]]])
:parameters {:path {:id int?}}}]]])
(def router
(rf/router
routes))
(def on-navigate
#(dispatch [:set-active-page {:new-match %
:id (get-in % [:path-params :id])}]))
(defn on-navigate
[match _]
(dispatch [:set-active-page {:new-match match
:id (get-in match [:path-params :id])
:query (get match :query-params)}]))

View file

@ -1,6 +1,6 @@
(ns frontend.views
(:require [reitit.frontend.easy :as rfe]
[re-frame.core :refer [subscribe]]))
[re-frame.core :refer [subscribe dispatch]]))
(defn button
@ -13,7 +13,6 @@
"Post " id]
[:br]])
(defn home-page []
[:div
[:h2 "Try this!"]
@ -21,14 +20,12 @@
(button 96817849)
(button 24425284)])
(defn about-page []
[:div
[:h2 "About"]
[:ul
[:li [:a {:href "https://git.southfox.me/southfox/liberty-hu"} "Source code"]]]])
(defn item-page []
(let [loading @(subscribe [:loading])
post @(subscribe [:post])]
@ -44,7 +41,8 @@
(defn question-page []
(let [loading @(subscribe [:loading])
post @(subscribe [:post])]
post @(subscribe [:post])
end? (-> post :paging :is_end)]
(if (:question loading)
[:p "Loading..."]
[:div
@ -61,8 +59,18 @@
(-> ans :author :name)]]
[:div
{:dangerouslySetInnerHTML
{:__html (:content ans)}}]
])]])))
{:__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)})}]])])))
(defn nav [{:keys [current-route]}]
(let [active #(when (= % (-> current-route :data :name)) "> ")]