aboutsummaryrefslogtreecommitdiff
path: root/src/dionysus/web/enduser/home.clj
blob: 69d8ece6c29d17df22ed439673aa7ba435fe4ce7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
(ns dionysus.web.enduser.home
  (:require [dionysus.web.utils :as dwutils]
            [ring.util.response :as ruresp]
            [dionysus.spotify :as dspotify]
            [clojure.string :as cstr]
            [dionysus.web.enduser.home.search :as dwehsearch]))

(defn- render-current-track [_req]
  (let [track (:item (dspotify/get-current-track!))]
    [:div {:id         "current-track"
           :class      "card"
           :hx-swap    "outerHTML"
           :hx-get     "/current-track/"
           :hx-trigger "every 10s"}
     [:img {:class "album-image"
            :src   (get-in track [:album :images 0 :url])
            :width "130em"}]
     [:div
      [:b (:name track)]
      [:p (str "Von " (cstr/join ", " (map :name (:artists track))))]
      [:a {:href   (get-in track [:external_urls :spotify])
           :target "_blank"} "Auf Spotify anschauen"]]]))

(defn handle-current-track [req]
  (-> req
      render-current-track
      dwutils/render-html
      ruresp/response))

(defn- render [_req]
  (dwutils/render-page (str @dwutils/title " - Home")
                       [:div {:class "text"}
                        [:h1 @dwutils/title]
                        [:p "Füge hier Lieder zur Warteschlange hinzu!"]]
                       [:input {:id          "search-bar"
                                :type        "text"
                                :placeholder "Suche nach einem Lied:"
                                :name        "query"
                                :hx-get      "/search/"
                                :hx-swap     "innerHTML"
                                :hx-target   "#search-results"
                                :hx-trigger  "change"}]
                       [:div {:id "search-results"}
                        (dwehsearch/render-search nil)]
                       [:h2 {:class "text"}
                        "Aktuelles Lied"]
                       (render-current-track nil)
                       [:script {:src "/assets/htmx.js"}]))

(defn handle [req]
  (-> req
      render
      ruresp/response))