diff options
author | Miguel Ángel Moreno <mail@migalmoreno.com> | 2022-12-20 00:47:36 +0100 |
---|---|---|
committer | Miguel Ángel Moreno <mail@migalmoreno.com> | 2022-12-20 00:55:11 +0100 |
commit | 5730dd7812d979c07f8f6f52852603bf928c4bc0 (patch) | |
tree | ee1b1f73266ccea14fa3d34fe07bc1ce86a8b502 | |
parent | d85306e3fa2a25bcace91565bbc9bfabd8e3796c (diff) |
feat: Set up initial frontend routes
-rw-r--r-- | src/frontend/tau/routes.cljs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/frontend/tau/routes.cljs b/src/frontend/tau/routes.cljs new file mode 100644 index 0000000..1742aaa --- /dev/null +++ b/src/frontend/tau/routes.cljs @@ -0,0 +1,38 @@ +(ns tau.routes + (:require + [reitit.frontend :as ref] + [reitit.frontend.easy :as rfe] + [reitit.frontend.controllers :as rfc] + [re-frame.core :as rf] + [tau.views.home :as home] + [tau.views.search :as search] + [tau.views.stream :as stream])) + +(def routes + (ref/router + [["/" {:view home/home-page + :name ::home}] + ["/search" {:view search/search + :name ::search + :controllers [{:parameters {:query [:q :serviceId]} + :start (fn [parameters] + (rf/dispatch [:get-search-results + {:id (-> parameters :query :serviceId) + :query (-> parameters :query :q)}]))}]}] + ["/stream" {:view stream/stream + :name ::stream + :controllers [{:parameters {:query [:url]} + :start (fn [parameters] + (rf/dispatch [:get-stream (-> parameters :query :url)]))}]}]])) + +(defn on-navigate + [new-match] + (let [old-match (rf/subscribe [:current-match])] + (when new-match + (let [controllers (rfc/apply-controllers (:controllers @old-match) new-match) + match (assoc new-match :controllers controllers)] + (rf/dispatch [:navigated match]))))) + +(defn start-routes! + [] + (rfe/start! routes on-navigate {:use-fragment false})) |