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

Update views to utilize new playlist, implement play next / play last

This commit is contained in:
Arne Schlüter 2018-08-20 17:12:31 +02:00
commit bac22c03a1
3 changed files with 29 additions and 7 deletions

View file

@ -214,6 +214,16 @@
{:db db {:db db
:audio/play (song-url db prev)}))) :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 (re-frame/reg-event-fx
::toggle-play-pause ::toggle-play-pause
(fn [_ _] (fn [_ _]

View file

@ -1,5 +1,6 @@
(ns airsonic-ui.utils.helpers (ns airsonic-ui.utils.helpers
"Assorted helper functions") "Assorted helper functions"
(:require [re-frame.core :as rf]))
(defn find-where (defn find-where
"Returns the the first item in `coll` with its index for which `(p song)` "Returns the the first item in `coll` with its index for which `(p song)`
@ -8,3 +9,10 @@
(->> (map-indexed vector coll) (->> (map-indexed vector coll)
(reduce (fn [_ [idx song]] (reduce (fn [_ [idx song]]
(when (p song) (reduced [idx song]))) nil))) (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)))

View file

@ -1,5 +1,5 @@
(ns airsonic-ui.views.song (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.events :as events]
[airsonic-ui.routes :as routes :refer [url-for]] [airsonic-ui.routes :as routes :refer [url-for]]
[airsonic-ui.views.icon :refer [icon]])) [airsonic-ui.views.icon :refer [icon]]))
@ -12,9 +12,7 @@
(:artist song)] (:artist song)]
" - " " - "
[:a [:a
{:href "#" :on-click (fn [e] {:href "#" :on-click (dispatch [::events/play-songs songs idx])}
(.preventDefault e)
(dispatch [::events/play-songs songs idx]))}
(:title song)]])) (:title song)]]))
(defn listing [songs] (defn listing [songs]
@ -23,5 +21,11 @@
^{:key idx} [:tr ^{:key idx} [:tr
[:td.grow [item songs song idx]] [:td.grow [item songs song idx]]
;; FIXME: Not implemented yet ;; FIXME: Not implemented yet
[:td>a {:title "Play next"} [icon :plus]] [:td>a {:title "Play next"
[:td>a {:title "Play last"} [icon :arrow-thick-right]]])]) :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]]])])