blob: 78d76d7fea0dee5326e781c34751aeb6b68605af (
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
(ns dionysus.web.enduser.home.search
(:require [clojure.string :as cstr]
[dionysus.blacklist :as dblacklist]
[dionysus.spotify :as dspotify]
[dionysus.web.utils :as dwutils]
[ring.util.response :as ruresp]))
(defn- search-item [track]
[:div {:class ["card" "search-item"]}
[: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))))]]
[:img {:class "track-action-icon"
:src "/assets/icons/plus.svg"
:hx-post (str "/search/add/" (:uri track) "/")
:hx-trigger "click"
:hx-swap "outerHTML"
:hx-target "this"
:height "60em"
:alt "plus icon"
:title "Lied zur Warteschlange hinzufügen"}]])
(defn render-search [req]
(let [query (get-in req [:query-params "query"])
tracks (-> (dspotify/search! query)
(get-in [:tracks :items])
delay)]
(cond
(cstr/blank? query)
[:i "Nutze die Suchleiste oben, um nach einem Lied zu suchen oder füge den Link zu dem Lied ein."]
(nil? @tracks)
[:b "An error occurred."]
:else
(for [track @tracks]
(search-item track)))))
(defn handle-search [req]
(-> req
render-search
dwutils/render-html
ruresp/response))
(defn handle-search-add [req]
(let [uri (get-in req [:path-params :uri])
on-blacklist? (-> uri
(cstr/split #":")
last
dblacklist/on-blacklist?)]
(when (not on-blacklist?) (dspotify/add-item-to-queue! uri))
(-> [:img {:class "track-action-icon"
:src (if on-blacklist?
"/assets/icons/warning.svg"
"/assets/icons/check.svg")
:alt (if on-blacklist?
"warn dreieck icon"
"haken icon")
:title (if on-blacklist?
"Lied oder Künstler ist auf der Blacklist"
"Lied wurde zur Warteschlange hinzugefügt")
:height "60em"}]
dwutils/render-html
ruresp/response)))
|