Can you figure out what's wrong with my code? The home page and navbar don't show up,…
- User
Can you figure out what's wrong with my code? The home page and navbar don't show up, and I'm sure there are other errors.
(ns ^:figwheel-hooks simple-server.core (:require [clojure.string :as str] [ajax.core :refer [GET]] [goog.dom :as gdom] [goog.events :as events] [goog.history.EventType :as HistoryEventType] [reagent.core :as r :refer [atom]] [reagent.dom :as rdom] [reitit.core :as reitit]) (:import goog.History))
(defonce session (r/atom {:page :home}))
(defn nav-link [uri title page] [:a.navbar-item {:href uri :class (when (= page (:page @session)) "is-active")} title])
(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}} "Apex Charts demo"] [: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)} [:div.navbar-start [nav-link "#/" "Home" :home] [nav-link "#/about" "About" :about]]]]))
(defn about-page [] [:section.section>div.container>div.content [:img {:src "/img/warning_clojure.png"}]])
(println "This text is printed from src/simple_server/core.cljs. Go ahead and edit it and see reloading in action.")
(defn multiply [a b] (* a b))
;; define your app data so that it doesn't get over-written on reload (defonce app-state (atom {:text "Hello world!"}))
(defn get-app-element [] (gdom/getElement "app"))
(defn base-page [] [:div [:h1 (:text @app-state)] [:h3 "Edit this in src/simple_server/core.cljs and watch it change!"]])
(defn home-page [] [:section.section>div.container>div.content [:h1 {:style {:display "flex" :justify-content "center" :align-items "center"}} "ApexCharts.js"] [:h4 "ApexCharts Basics"] [:p {:style {:display "flex" :justify-content "center" :align-items "center"}} "ApexCharts is a modern charting library that works with the React framework. It provides a wide range of chart types and features such as animations, zooming, panning, and updating series dynamically. It is also responsive, making it suitable for creating interactive data visualizations for both desktop and mobile devices. It is open-source and provided under the MIT licence, so it is entirely viable for commercial projects."]
])
(def pages {:home #'home-page :about #'about-page})
(defn page [] [(pages (:page @session))])
;; ------------------------- ;; Routes
(def router (reitit/router [["/" :home] ["/about" :about]]))
(defn match-route [uri] (->> (or (not-empty (str/replace uri #"^.*#" "")) "/") (reitit/match-by-path router) :data :name))
;; ------------------------- ;; History ;; must be called after routes have been defined (defn hook-browser-navigation! [] (doto (History.) (events/listen HistoryEventType/NAVIGATE (fn [^js/Event.token event] (swap! session assoc :page (match-route (.-token event))))) (.setEnabled true)))
- Assistant
- User
Can you make more suggestions related to the code itself?
- Assistant
- User
- Assistant