1
0
Fork 0
mirror of https://github.com/heyarne/airsonic-ui.git synced 2026-05-07 02:33:39 +02:00

Login → Album List → Album Detail

This commit is contained in:
Arne Schlüter 2018-04-20 15:44:59 +02:00
commit 9ca116ee72
3 changed files with 64 additions and 13 deletions

29
src/airsonic_ui/api.cljs Normal file
View 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)))

View file

@ -18,7 +18,8 @@
;; --- ;; ---
;; TODO: Make this nice and clean ;; TODO: Make this nice and clean
(re-frame/reg-sub (re-frame/reg-sub
::current-album-list ::current-content
(fn [db] (fn [db]
(-> db :response :album))) (-> db :response)))

View file

@ -23,7 +23,7 @@
[:div [:div
[:button {:on-click #(re-frame/dispatch [::events/authenticate @user @pass])} "Submit"]]]))) [:button {:on-click #(re-frame/dispatch [::events/authenticate @user @pass])} "Submit"]]])))
;; album list ;; album list (start page)
(defn album-item [album] (defn album-item [album]
(let [{:keys [artist artistId name coverArt year id]} album] (let [{:keys [artist artistId name coverArt year id]} album]
@ -34,21 +34,42 @@
;; link to album ;; link to album
[:a {:href (routes/url-for ::routes/album-view {:id id})} name] (when year (str " (" year ")"))])) [:a {:href (routes/url-for ::routes/album-view {:id id})} name] (when year (str " (" year ")"))]))
(defn album-list [] ;; TODO: album-list shouldn't know about the structure of content and should just get a list
(let [albums @(re-frame/subscribe [::subs/current-album-list])] (defn album-list [content]
[:div
[:h2 (str "Recently played")]
[:ul [:ul
(map-indexed (fn [idx album] (map-indexed
(fn [idx album]
[:li {:key idx} [album-item album]]) [:li {:key idx} [album-item album]])
albums)])) (: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 ;; putting everything together
(defn app [route params query] (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 [:div
[:h2 (str "Currently logged in as " (:u login))] [:span (str "Currently logged in as " (:u login))]
[:h3 (str "Recently played")] (case route
[album-list] ::routes/main [album-list content]
::routes/album-view [album-detail content])
[:a {:on-click #(re-frame/dispatch [::events/initialize-db]) :href "#"} "Logout"]])) [:a {:on-click #(re-frame/dispatch [::events/initialize-db]) :href "#"} "Logout"]]))
(defn main-panel [] (defn main-panel []