swap secretary with bide, move routing into extra ns

This commit is contained in:
Martin Klepsch 2018-02-22 15:23:51 +01:00 committed by Tetiana Churikova
parent 13fb8dc4ec
commit ad581fd576
3 changed files with 36 additions and 36 deletions

View File

@ -5,7 +5,7 @@
:exclusions [joda-time]] :exclusions [joda-time]]
[re-frame "0.10.2"] [re-frame "0.10.2"]
[cljs-ajax "0.7.2"] [cljs-ajax "0.7.2"]
[secretary "1.2.3"] [funcool/bide "1.6.0"]
[reagent-utils "0.2.1"] [reagent-utils "0.2.1"]
[reagent "0.7.0"] [reagent "0.7.0"]
[org.clojure/clojurescript "1.9.946"] [org.clojure/clojurescript "1.9.946"]

View File

@ -1,10 +1,10 @@
(ns commiteth.core (ns commiteth.core
(:require [reagent.core :as r] (:require [reagent.core :as r]
[re-frame.core :as rf] [re-frame.core :as rf]
[secretary.core :as secretary]
[goog.events :as events] [goog.events :as events]
[goog.history.EventType :as HistoryEventType] [goog.history.EventType :as HistoryEventType]
[commiteth.ajax :refer [load-interceptors!]] [commiteth.ajax :refer [load-interceptors!]]
[commiteth.routes]
[commiteth.handlers] [commiteth.handlers]
[commiteth.subscriptions] [commiteth.subscriptions]
[commiteth.activity :refer [activity-page]] [commiteth.activity :refer [activity-page]]
@ -89,7 +89,7 @@
(for [[page caption] tabs] (for [[page caption] tabs]
(let [props {:class (str "ui item" (let [props {:class (str "ui item"
(when (= @current-page page) " active")) (when (= @current-page page) " active"))
:on-click #(rf/dispatch [:set-active-page page])}] :on-click #(commiteth.routes/nav! page)}]
^{:key page} [:div props caption]))))))) ^{:key page} [:div props caption])))))))
@ -124,15 +124,6 @@
[flash-message-pane])]))) [flash-message-pane])])))
(def pages
{:activity #'activity-page
:bounties #'bounties-page
:repos #'repos-page
:manage-payouts #'manage-payouts-page
:update-address #'update-address-page
:usage-metrics #'usage-metrics-page})
(defn top-hunters [] (defn top-hunters []
(let [top-hunters (rf/subscribe [:top-hunters])] (let [top-hunters (rf/subscribe [:top-hunters])]
(fn [] (fn []
@ -211,7 +202,13 @@
[:div {:class (str (if (show-top-hunters?) "eleven" "sixteen") [:div {:class (str (if (show-top-hunters?) "eleven" "sixteen")
" wide computer sixteen wide tablet column")} " wide computer sixteen wide tablet column")}
[:div.ui.container [:div.ui.container
[(pages @current-page)]]] (case @current-page
:activity [activity-page]
:bounties [bounties-page]
:repos [repos-page]
:manage-payouts [manage-payouts-page]
:update-address [update-address-page]
:usage-metrics [usage-metrics-page])]]
(when (show-top-hunters?) (when (show-top-hunters?)
[:div.five.wide.column.computer.only [:div.five.wide.column.computer.only
[:div.ui.container.top-hunters [:div.ui.container.top-hunters
@ -220,28 +217,6 @@
[top-hunters]]])]]] [top-hunters]]])]]]
[footer]]))) [footer]])))
(secretary/set-config! :prefix "#")
(secretary/defroute "/" []
(rf/dispatch [:set-active-page :bounties]))
(secretary/defroute "/activity" []
(rf/dispatch [:set-active-page :activity]))
(secretary/defroute "/repos" []
(if js/user
(rf/dispatch [:set-active-page :repos])
(secretary/dispatch! "/")))
(defn hook-browser-navigation! []
(doto (History.)
(events/listen
HistoryEventType/NAVIGATE
(fn [event]
(secretary/dispatch! (.-token event))))
(.setEnabled true)))
(defn mount-components [] (defn mount-components []
(r/render [#'page] (.getElementById js/document "app"))) (r/render [#'page] (.getElementById js/document "app")))
@ -286,7 +261,7 @@
(when config/debug? (when config/debug?
(enable-re-frisk!)) (enable-re-frisk!))
(load-interceptors!) (load-interceptors!)
(hook-browser-navigation!) (commiteth.routes/setup-nav!)
(load-data true) (load-data true)
(.addEventListener js/window "click" #(rf/dispatch [:clear-flash-message])) (.addEventListener js/window "click" #(rf/dispatch [:clear-flash-message]))
(on-js-load)) (on-js-load))

View File

@ -0,0 +1,25 @@
(ns commiteth.routes
(:require [bide.core :as bide]
[re-frame.core :as rf]))
(defonce router
(bide/router [["/" :bounties]
["/activity" :activity]
["/repos" :repos]
["/manage-payouts" :manage-payouts]
["/update-address" :update-address]
["/usage-metrics" :usage-metrics]]))
(defn on-navigate
"A function which will be called on each route change."
[name params query]
(println "Route change to: " name params query)
(rf/dispatch [:set-active-page name]))
(defn setup-nav! []
(bide/start! router {:default :bounties
:on-navigate on-navigate}))
(defn nav! [route-id]
(bide/navigate! router route-id {}))