mirror of
https://github.com/heyarne/airsonic-ui.git
synced 2026-05-06 18:33:38 +02:00
Login → Album List → Album Detail
This commit is contained in:
parent
eb59e97e96
commit
9ca116ee72
3 changed files with 64 additions and 13 deletions
29
src/airsonic_ui/api.cljs
Normal file
29
src/airsonic_ui/api.cljs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
(ns airsonic-ui.api
|
||||
(:require [clojure.string :as string]
|
||||
[airsonic-ui.config :as config]))
|
||||
|
||||
(defn ^:private uri-escape [s]
|
||||
(js/encodeURIComponent s))
|
||||
|
||||
(defn url
|
||||
"Returns an absolute url to an API endpoint"
|
||||
[endpoint params]
|
||||
(let [query (->> (assoc params
|
||||
:f "json"
|
||||
:c "airsonic-ui-cljs"
|
||||
:v "1.15.0")
|
||||
(map (fn [[k v]]
|
||||
(str (uri-escape (name k)) "=" (uri-escape v))))
|
||||
(string/join "&"))]
|
||||
(str config/server "/rest/" endpoint "?" query)))
|
||||
|
||||
(defn ^:private api-error?
|
||||
"We need to look at the message body because the subsonic api always responds
|
||||
with status 200"
|
||||
[response]
|
||||
(= "failed" (-> response :subsonic-response :status)))
|
||||
|
||||
(defn ^:private error-message
|
||||
[response]
|
||||
(let [{:keys [code message]} (-> response :subsonic-response :error)]
|
||||
(str "Code " code ": " message)))
|
||||
|
|
@ -18,7 +18,8 @@
|
|||
;; ---
|
||||
|
||||
;; TODO: Make this nice and clean
|
||||
|
||||
(re-frame/reg-sub
|
||||
::current-album-list
|
||||
::current-content
|
||||
(fn [db]
|
||||
(-> db :response :album)))
|
||||
(-> db :response)))
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
[:div
|
||||
[:button {:on-click #(re-frame/dispatch [::events/authenticate @user @pass])} "Submit"]]])))
|
||||
|
||||
;; album list
|
||||
;; album list (start page)
|
||||
|
||||
(defn album-item [album]
|
||||
(let [{:keys [artist artistId name coverArt year id]} album]
|
||||
|
|
@ -34,21 +34,42 @@
|
|||
;; link to album
|
||||
[:a {:href (routes/url-for ::routes/album-view {:id id})} name] (when year (str " (" year ")"))]))
|
||||
|
||||
(defn album-list []
|
||||
(let [albums @(re-frame/subscribe [::subs/current-album-list])]
|
||||
[:ul
|
||||
(map-indexed (fn [idx album]
|
||||
[:li {:key idx} [album-item album]])
|
||||
albums)]))
|
||||
;; TODO: album-list shouldn't know about the structure of content and should just get a list
|
||||
(defn album-list [content]
|
||||
[:div
|
||||
[:h2 (str "Recently played")]
|
||||
[:ul
|
||||
(map-indexed
|
||||
(fn [idx album]
|
||||
[:li {:key idx} [album-item album]])
|
||||
(:album content))]])
|
||||
|
||||
;; single album
|
||||
|
||||
(defn song-item [song]
|
||||
[:div (str (:artist song) " - " (:title song))])
|
||||
|
||||
(defn song-list [songs]
|
||||
[:ul
|
||||
(map-indexed
|
||||
(fn [idx song] [:li {:key idx} [song-item song]])
|
||||
songs)])
|
||||
|
||||
(defn album-detail [content]
|
||||
[:div
|
||||
[:h2 (str (:artist content) " - " (:name content))]
|
||||
[song-list (:song content)]])
|
||||
|
||||
;; putting everything together
|
||||
|
||||
(defn app [route params query]
|
||||
(let [login @(re-frame/subscribe [::subs/login])]
|
||||
(let [login @(re-frame/subscribe [::subs/login])
|
||||
content @(re-frame/subscribe [::subs/current-content])]
|
||||
[:div
|
||||
[:h2 (str "Currently logged in as " (:u login))]
|
||||
[:h3 (str "Recently played")]
|
||||
[album-list]
|
||||
[:span (str "Currently logged in as " (:u login))]
|
||||
(case route
|
||||
::routes/main [album-list content]
|
||||
::routes/album-view [album-detail content])
|
||||
[:a {:on-click #(re-frame/dispatch [::events/initialize-db]) :href "#"} "Logout"]]))
|
||||
|
||||
(defn main-panel []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue