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]]
[re-frame "0.10.2"]
[cljs-ajax "0.7.2"]
[secretary "1.2.3"]
[funcool/bide "1.6.0"]
[reagent-utils "0.2.1"]
[reagent "0.7.0"]
[org.clojure/clojurescript "1.9.946"]

View File

@ -1,10 +1,10 @@
(ns commiteth.core
(:require [reagent.core :as r]
[re-frame.core :as rf]
[secretary.core :as secretary]
[goog.events :as events]
[goog.history.EventType :as HistoryEventType]
[commiteth.ajax :refer [load-interceptors!]]
[commiteth.routes]
[commiteth.handlers]
[commiteth.subscriptions]
[commiteth.activity :refer [activity-page]]
@ -89,7 +89,7 @@
(for [[page caption] tabs]
(let [props {:class (str "ui item"
(when (= @current-page page) " active"))
:on-click #(rf/dispatch [:set-active-page page])}]
:on-click #(commiteth.routes/nav! page)}]
^{:key page} [:div props caption])))))))
@ -124,15 +124,6 @@
[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 []
(let [top-hunters (rf/subscribe [:top-hunters])]
(fn []
@ -211,7 +202,13 @@
[:div {:class (str (if (show-top-hunters?) "eleven" "sixteen")
" wide computer sixteen wide tablet column")}
[: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?)
[:div.five.wide.column.computer.only
[:div.ui.container.top-hunters
@ -220,28 +217,6 @@
[top-hunters]]])]]]
[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 []
(r/render [#'page] (.getElementById js/document "app")))
@ -286,7 +261,7 @@
(when config/debug?
(enable-re-frisk!))
(load-interceptors!)
(hook-browser-navigation!)
(commiteth.routes/setup-nav!)
(load-data true)
(.addEventListener js/window "click" #(rf/dispatch [:clear-flash-message]))
(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 {}))