From 73bf88b666478b6bba23b7849858cfb500edcae7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20Schl=C3=BCter?= Date: Wed, 25 Apr 2018 17:09:26 +0200 Subject: [PATCH] Implement breadcrumbs --- src/airsonic_ui/routes.cljs | 5 +++-- src/airsonic_ui/views.cljs | 36 +++++++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/airsonic_ui/routes.cljs b/src/airsonic_ui/routes.cljs index c766785..654705f 100644 --- a/src/airsonic_ui/routes.cljs +++ b/src/airsonic_ui/routes.cljs @@ -11,8 +11,9 @@ ["/album/:id" ::album-view]])) ; use this in views to construct a url -(defn url-for [k params] - (str "#" (r/resolve router k params))) +(defn url-for + ([k] (url-for k {})) + ([k params] (str "#" (r/resolve router k params)))) ; which routes need valid login credentials? (def protected-routes #{::main ::artist-view ::album-view}) diff --git a/src/airsonic_ui/views.cljs b/src/airsonic_ui/views.cljs index 49ae0e8..7c9acf2 100644 --- a/src/airsonic_ui/views.cljs +++ b/src/airsonic_ui/views.cljs @@ -2,7 +2,7 @@ (:require [re-frame.core :refer [dispatch subscribe]] [reagent.core :as r] [airsonic-ui.config :as config] - [airsonic-ui.routes :as routes] + [airsonic-ui.routes :as routes :refer [url-for]] [airsonic-ui.events :as events] [airsonic-ui.subs :as subs])) @@ -44,7 +44,7 @@ (let [artist-id (:artistId song)] [:div [:a - (when artist-id {:href (routes/url-for ::routes/artist-view {:id artist-id})}) + (when artist-id {:href (url-for ::routes/artist-view {:id artist-id})}) (:artist song)] " - " [:a @@ -66,15 +66,14 @@ (let [{:keys [artist artistId name coverArt year id]} album] [:div ;; link to artist page - [:a {:href (routes/url-for ::routes/artist-view {:id artistId})} artist] + [:a {:href (url-for ::routes/artist-view {:id artistId})} artist] " - " ;; link to album - [:a {:href (routes/url-for ::routes/album-view {:id id})} name] (when year (str " (" year ")"))])) + [:a {:href (url-for ::routes/album-view {:id id})} name] (when year (str " (" year ")"))])) (defn artist-detail [content] [:div [:h2 (:name content)] - [:p (:albumCount content) " items"] [:ul (for [[idx album] (map-indexed vector (:album content))] [:li {:key idx} [album-item album]])]]) @@ -86,6 +85,32 @@ [:ul (for [[idx album] (map-indexed vector (:album content))] [:li {:key idx} [album-item album]])]]) +;; top navigation + +(defn content-type + "Helper to see what kind of server response" + [content] + (cond + (and (vector? (:album content)) (:id content)) :artist + (vector? (:song content)) :album + :else :unknown-content)) + +(defmulti breadcrumbs content-type) + +(defmethod breadcrumbs :default [content] + [:div [:span "Start"]]) + +(defmethod breadcrumbs :artist [content] + [:div + [:span [:a {:href (url-for ::routes/main)} "Start"]] + [:span " · " (:name content)]]) + +(defmethod breadcrumbs :album [content] + [:div + [:span [:a {:href (url-for ::routes/main)} "Start"]] + [:span " · " [:a {:href (url-for ::routes/artist-view {:id (:artistId content)})} (:artist content)]] + [:span " · " (:name content)]]) + ;; currently playing / coming next / audio controls... (defn current-song-info [{:keys [item status]}] @@ -116,6 +141,7 @@ content @(subscribe [::subs/current-content])] [:div [:span (str "Currently logged in as " (:u login))] + [breadcrumbs content] (case route ::routes/main [most-recent content] ::routes/artist-view [artist-detail content]