Can you figure out what's wrong with my code? (ns ^:figwheel-hooks simple-server.core…
- User
Can you figure out what's wrong with my code?
(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
Without further context about the actual problem you're experiencing or errors you might be encountering, it's tough to give a precise answer. However, there are a few observations we can make from the code you've shared:
-
Unused functions and state:
- The
multiplyfunction andsessionatom don't appear to be used anywhere in your code. If they are required for some unshown parts of the application, you should keep them; otherwise, they could be removed to clean up the codebase.
- The
-