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

Remove current song

This commit is contained in:
heyarne 2019-03-10 12:09:17 +01:00
commit 065b3a6647
7 changed files with 72 additions and 7 deletions

View file

@ -53,7 +53,8 @@
(fn [_]
(when-let [audio @audio]
(.pause audio)
(set! (.-currentTime audio) 0))))
(set! (.-currentTime audio) 0)
(set! (.-src audio) ""))))
(rf/reg-fx
:audio/toggle-play-pause

View file

@ -22,7 +22,9 @@
(enqueue-next [this song])
(move-song [this from-idx to-idx]
"Allows you to move a song in a playlist"))
"Allows you to move a song in a playlist")
(remove-song [this song-idx]
"Removes a song from the playlist"))
;; helpers to manage creating playlists
@ -142,7 +144,15 @@
(= from-idx current-idx) (assoc result :current-idx to-idx)
(<= to-idx current-idx from-idx) (update result :current-idx inc)
(>= to-idx current-idx from-idx) (update result :current-idx dec)
:else result))))
:else result)))
(remove-song [this song-idx]
(cond-> (update this :items #(let [n-items (count %)]
(-> (reduce (fn [items idx]
(assoc items idx (get items (inc idx))))
% (range song-idx n-items))
(dissoc (dec n-items)))))
(= song-idx current-idx) (assoc :current-idx -1))))
;; constructor wrapper

View file

@ -66,6 +66,14 @@
(fn [_ _]
{:audio/toggle-play-pause nil}))
(defn remove-song [{:keys [db]} [_ song-idx]]
(let [song-removed (update-in db [:audio :current-playlist] #(playlist/remove-song % song-idx))]
(cond-> {:db song-removed}
(nil? (playlist/current-song (get-in song-removed [:audio :current-playlist])))
(assoc :audio/stop nil))))
(rf/reg-event-fx :audio-player/remove-song remove-song)
(defn audio-update
"Reacts to audio events fired by the HTML5 audio player and plays the next
track if necessary."

View file

@ -21,10 +21,10 @@
(r/as-element [:span.is-size-7.has-text-grey-lighter
[icon :elevator]]))))
(defn song-actions []
(defn song-actions [{:keys [song idx]}]
;; TODO: Implement both of these
[dropdown {:items [{:label "Remove from queue"
:event []}
:event [:audio-player/remove-song idx]}
{:label "Go to source"
:event []}]}])
@ -62,7 +62,8 @@
[:td.song-artist [artist-link song]]
[:td.song-title [song-link song idx]]
[:td.song-duration (helpers/format-duration (:duration song) :brief? true)]
[:td.song-actions.is-narrow [song-actions]]])
[:td.song-actions.is-narrow [song-actions {:song song
:idx idx}]]])
:on-sort-end
(fn [{:keys [old-idx new-idx]}]