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

Update events to use updated playlist, closes #6

This commit is contained in:
Arne Schlüter 2018-08-20 17:03:57 +02:00
commit 4d49b3a3ff
4 changed files with 48 additions and 37 deletions

View file

@ -2,7 +2,8 @@
"This namespace contains some JS interop code to interact with an audio player "This namespace contains some JS interop code to interact with an audio player
and receive information about the current playback status so we can use it in and receive information about the current playback status so we can use it in
our re-frame app." our re-frame app."
(:require [re-frame.core :as re-frame])) (:require [re-frame.core :as re-frame]
[airsonic-ui.audio.playlist :as playlist]))
;; TODO: Manage buffering ;; TODO: Manage buffering
@ -64,15 +65,25 @@
(re-frame/reg-sub :audio/summary summary) (re-frame/reg-sub :audio/summary summary)
(defn playlist
"Lists the complete playlist"
[summary _]
(:playlist summary))
(re-frame/reg-sub
:audio/playlist
(fn [_ _] (re-frame/subscribe [:audio/summary]))
playlist)
(defn current-song (defn current-song
"Gives us information about the currently played song as presented by "Gives us information about the currently played song as presented by
the airsonic api" the airsonic api"
[summary _] [playlist _]
(:current-song summary)) (playlist/peek playlist))
(re-frame/reg-sub (re-frame/reg-sub
:audio/current-song :audio/current-song
(fn [_ _] (re-frame/subscribe [:audio/summary])) (fn [_ _] (re-frame/subscribe [:audio/playlist]))
current-song) current-song)
(defn playback-status (defn playback-status
@ -93,17 +104,5 @@
(re-frame/reg-sub (re-frame/reg-sub
:audio/is-playing? :audio/is-playing?
(fn [_ _] (re-frame/subscribe [:audio/current-playback-status])) (fn [_ _] (re-frame/subscribe [:audio/playback-status]))
is-playing?) is-playing?)
(comment
;; NOTE: Not in use currently
(defn current-playlist
"Lists the complete playlist"
[summary _]
(:playlist summary))
(re-frame/reg-sub
:audio/current-playlist
(fn [_ _] (re-frame/subscribe [:audio/summary]))
current-playlist))

View file

@ -3,7 +3,8 @@
[ajax.core :as ajax] [ajax.core :as ajax]
[airsonic-ui.routes :as routes] [airsonic-ui.routes :as routes]
[airsonic-ui.db :as db] [airsonic-ui.db :as db]
[airsonic-ui.utils.api :as api])) [airsonic-ui.utils.api :as api]
[airsonic-ui.audio.playlist :as playlist]))
(re-frame/reg-fx (re-frame/reg-fx
;; a simple effect to keep println statements out of our event handlers ;; a simple effect to keep println statements out of our event handlers
@ -178,30 +179,40 @@
(re-frame/reg-event-fx (re-frame/reg-event-fx
; sets up the db, starts to play a song and adds the rest to a playlist ; sets up the db, starts to play a song and adds the rest to a playlist
::play-songs ::play-songs
(fn [{:keys [db]} [_ songs song]] (fn [{:keys [db]} [_ songs start-idx]]
{:audio/play (song-url db song) (println "play-songs called with" start-idx songs)
:db (-> (assoc-in db [:audio :current-song] song) (let [playlist (-> (playlist/->playlist songs :playback-mode :linear :repeat-mode :repeat-all)
(assoc-in [:audio :playlist] songs))})) (playlist/set-current-song start-idx))]
{:audio/play (song-url db (playlist/peek playlist))
:db (assoc-in db [:audio :playlist] playlist)})))
;; FIXME: :audio/play might not get the right argument here
(re-frame/reg-event-db
::set-playback-mode
(fn [db [_ playback-mode]]
(update-in db [:audio :playlist] #(playlist/set-playback-mode % playback-mode))))
(re-frame/reg-event-db
::set-repeat-mode
(fn [db [_ repeat-mode]]
(update-in db [:audio :playlist] #(playlist/set-repeat-mode % repeat-mode))))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::next-song ::next-song
(fn [{:keys [db]} _] (fn [{:keys [db]} _]
(let [playlist (get-in db [:audio :playlist]) (let [db (update-in db [:audio :playlist] playlist/next-song)
current-song (get-in db [:audio :current-song]) next (playlist/peek (get-in db [:audio :playlist]))]
next (first (rest (drop-while #(not= % current-song) playlist)))] {:db db
(when next :audio/play (song-url db next)})))
{:audio/play (song-url db next)
:db (assoc-in db [:audio :current-song] next)}))))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::previous-song ::previous-song
(fn [{:keys [db]} _] (fn [{:keys [db]} _]
(let [playlist (get-in db [:audio :playlist]) (let [db (update-in db [:audio :playlist] playlist/previous-song)
current-song (get-in db [:audio :current-song]) prev (playlist/peek (get-in db [:audio :playlist]))]
previous (last (take-while #(not= % current-song) playlist))] {:db db
(when previous :audio/play (song-url db prev)})))
{:audio/play (song-url db previous)
:db (assoc-in db [:audio :current-song] previous)}))))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::toggle-play-pause ::toggle-play-pause

View file

@ -1,5 +1,6 @@
(ns airsonic-ui.subs (ns airsonic-ui.subs
(:require [re-frame.core :as re-frame :refer [subscribe]] (:require [re-frame.core :as re-frame :refer [subscribe]]
[airsonic-ui.audio.playlist :as playlist]
[airsonic-ui.utils.api :as api])) [airsonic-ui.utils.api :as api]))
(defn is-booting? (defn is-booting?

View file

@ -4,7 +4,7 @@
[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]]))
(defn item [songs song] (defn item [songs song idx]
(let [artist-id (:artistId song)] (let [artist-id (:artistId song)]
[:div [:div
[:a [:a
@ -14,14 +14,14 @@
[:a [:a
{:href "#" :on-click (fn [e] {:href "#" :on-click (fn [e]
(.preventDefault e) (.preventDefault e)
(dispatch [::events/play-songs songs song]))} (dispatch [::events/play-songs songs idx]))}
(:title song)]])) (:title song)]]))
(defn listing [songs] (defn listing [songs]
[:table.table.is-striped.is-hoverable.is-fullwidth>tbody [:table.table.is-striped.is-hoverable.is-fullwidth>tbody
(for [[idx song] (map-indexed vector songs)] (for [[idx song] (map-indexed vector songs)]
^{:key idx} [:tr ^{:key idx} [:tr
[:td.grow [item songs song]] [: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"} [icon :plus]]
[:td>a {:title "Play last"} [icon :arrow-thick-right]]])]) [:td>a {:title "Play last"} [icon :arrow-thick-right]]])])