From bac22c03a1650aceceb4d5ced7cdb603e860fbc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20Schl=C3=BCter?= Date: Mon, 20 Aug 2018 17:12:31 +0200 Subject: [PATCH] Update views to utilize new playlist, implement play next / play last --- src/cljs/airsonic_ui/events.cljs | 10 ++++++++++ src/cljs/airsonic_ui/utils/helpers.cljs | 10 +++++++++- src/cljs/airsonic_ui/views/song.cljs | 16 ++++++++++------ 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/cljs/airsonic_ui/events.cljs b/src/cljs/airsonic_ui/events.cljs index fac3463..f58d053 100644 --- a/src/cljs/airsonic_ui/events.cljs +++ b/src/cljs/airsonic_ui/events.cljs @@ -214,6 +214,16 @@ {:db db :audio/play (song-url db prev)}))) +(re-frame/reg-event-db + ::enqueue-next + (fn [db [_ song]] + (update-in db [:audio :playlist] #(playlist/enqueue-next % song)))) + +(re-frame/reg-event-db + ::enqueue-last + (fn [db [_ song]] + (update-in db [:audio :playlist] #(playlist/enqueue-last % song)))) + (re-frame/reg-event-fx ::toggle-play-pause (fn [_ _] diff --git a/src/cljs/airsonic_ui/utils/helpers.cljs b/src/cljs/airsonic_ui/utils/helpers.cljs index b9e86b7..663414b 100644 --- a/src/cljs/airsonic_ui/utils/helpers.cljs +++ b/src/cljs/airsonic_ui/utils/helpers.cljs @@ -1,5 +1,6 @@ (ns airsonic-ui.utils.helpers - "Assorted helper functions") + "Assorted helper functions" + (:require [re-frame.core :as rf])) (defn find-where "Returns the the first item in `coll` with its index for which `(p song)` @@ -8,3 +9,10 @@ (->> (map-indexed vector coll) (reduce (fn [_ [idx song]] (when (p song) (reduced [idx song]))) nil))) + +(defn dispatch + "Dispatches a re-frame event while canceling default DOM behavior" + [ev] + (fn [e] + (.preventDefault e) + (rf/dispatch ev))) diff --git a/src/cljs/airsonic_ui/views/song.cljs b/src/cljs/airsonic_ui/views/song.cljs index 408b0d7..b8de619 100644 --- a/src/cljs/airsonic_ui/views/song.cljs +++ b/src/cljs/airsonic_ui/views/song.cljs @@ -1,5 +1,5 @@ (ns airsonic-ui.views.song - (:require [re-frame.core :refer [dispatch]] + (:require [airsonic-ui.utils.helpers :refer [dispatch]] [airsonic-ui.events :as events] [airsonic-ui.routes :as routes :refer [url-for]] [airsonic-ui.views.icon :refer [icon]])) @@ -12,9 +12,7 @@ (:artist song)] " - " [:a - {:href "#" :on-click (fn [e] - (.preventDefault e) - (dispatch [::events/play-songs songs idx]))} + {:href "#" :on-click (dispatch [::events/play-songs songs idx])} (:title song)]])) (defn listing [songs] @@ -23,5 +21,11 @@ ^{:key idx} [:tr [:td.grow [item songs song idx]] ;; FIXME: Not implemented yet - [:td>a {:title "Play next"} [icon :plus]] - [:td>a {:title "Play last"} [icon :arrow-thick-right]]])]) + [:td>a {:title "Play next" + :href "#" + :on-click (dispatch [::events/enqueue-next song])} + [icon :plus]] + [:td>a {:title "Play last" + :href "#" + :on-click (dispatch [::events/enqueue-last song])} + [icon :arrow-thick-right]]])])