104 lines
2.6 KiB
Clojure
104 lines
2.6 KiB
Clojure
(ns datamapper.core
|
|
(:require
|
|
[clojure.string :refer [capitalize]]
|
|
[day8.re-frame.http-fx]
|
|
[reagent.core :as r]
|
|
[re-frame.core :as rf]
|
|
[goog.events :as events]
|
|
[goog.history.EventType :as HistoryEventType]
|
|
[markdown.core :refer [md->html]]
|
|
[datamapper.ajax :as ajax]
|
|
[datamapper.events]
|
|
[datamapper.views.map :as maps]
|
|
[reitit.core :as reitit]
|
|
[reitit.frontend.easy :as rfe]
|
|
[clojure.string :as string])
|
|
(:import goog.History))
|
|
|
|
(defn nav-link [uri title page]
|
|
[:a.navbar-item
|
|
{:href uri
|
|
:class (when (= page @(rf/subscribe [:page])) :is-active)}
|
|
title])
|
|
|
|
(defn about-page []
|
|
[:section.section>div.container>div.content
|
|
[:img {:src "/img/warning_clojure.png"}]])
|
|
|
|
(defn map-page
|
|
"Return the content for the main map page. Map showing current location."
|
|
[]
|
|
(maps/panel))
|
|
|
|
(defn home-page []
|
|
[:section.section>div.container>div.content
|
|
(when-let [docs @(rf/subscribe [:docs])]
|
|
[:div {:dangerouslySetInnerHTML {:__html (md->html docs)}}])])
|
|
|
|
(def pages
|
|
{:home #'home-page
|
|
:map #'map-page
|
|
:about #'about-page})
|
|
|
|
(defn auto-nav
|
|
"Automatically create a navbar for all the pages we know about."
|
|
[]
|
|
(apply vector
|
|
(cons
|
|
:div.navbar-start
|
|
(map
|
|
#(apply vector
|
|
(list
|
|
(str "#/" (if (= % :home) "" (name %)))
|
|
(capitalize (name %))
|
|
%))
|
|
(keys pages)))))
|
|
|
|
(defn navbar []
|
|
(r/with-let [expanded? (r/atom false)]
|
|
[:nav.navbar.is-info>div.container
|
|
[:div.navbar-brand
|
|
[:a.navbar-item {:href "/" :style {:font-weight :bold}} "datamapper"]
|
|
[:span.navbar-burger.burger
|
|
{:data-target :nav-menu
|
|
:on-click #(swap! expanded? not)
|
|
:class (when @expanded? :is-active)}
|
|
[:span][:span][:span]]]
|
|
[:div#nav-menu.navbar-menu
|
|
{:class (when @expanded? :is-active)}
|
|
(auto-nav)]]))
|
|
|
|
(defn page []
|
|
(if-let [page @(rf/subscribe [:page])]
|
|
[:div
|
|
[navbar]
|
|
[page]]))
|
|
|
|
(defn navigate! [match _]
|
|
(rf/dispatch [:navigate match]))
|
|
|
|
(def router
|
|
(reitit/router
|
|
[["/" {:name :home
|
|
:view #'home-page
|
|
:controllers [{:start (fn [_] (rf/dispatch [:page/init-home]))}]}]
|
|
["/about" {:name :about
|
|
:view #'about-page}]]))
|
|
|
|
(defn start-router! []
|
|
(rfe/start!
|
|
router
|
|
navigate!
|
|
{}))
|
|
|
|
;; -------------------------
|
|
;; Initialize app
|
|
(defn mount-components []
|
|
(rf/clear-subscription-cache!)
|
|
(r/render [#'page] (.getElementById js/document "app")))
|
|
|
|
(defn init! []
|
|
(start-router!)
|
|
(ajax/load-interceptors!)
|
|
(mount-components))
|