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

Fix sorting when converting a shuffled into a linear playlist

This commit is contained in:
heyarne 2019-03-05 09:44:13 +01:00
commit b529b2fabe
3 changed files with 16 additions and 5 deletions

View file

@ -27,7 +27,7 @@
"This function is used if we switch from linear to shuffled; it allows us to
restore the order of the queue when it was created."
[items]
(->> (sort-by (comp meta :playlist/linear-order) items)
(->> (sort-by (comp :playlist/linear-order meta) items)
(map-indexed (fn [idx item]
(vary-meta item assoc :playlist/linear-order idx)))))
@ -85,7 +85,8 @@
queue-fn (case playback-mode
:shuffled shuffled-queue
:linear linear-queue)
next-playlist (update playlist :items (comp queue-fn vals))
next-playlist (-> (assoc playlist :playback-mode playback-mode)
(update :items (comp queue-fn vals)))
next-idx (first (keep (fn [[idx song]]
(when (= song current-song)
idx))

View file

@ -51,6 +51,7 @@
[:td.sort-handle.is-narrow [:> SortHandle]]
[:td.song-artist [artist-link song]]
[:td.song-title (:title song)]
[:td.meta>code (str (meta song))]
[:td.song-duration (helpers/format-duration (:duration song) :brief? true)]
[:td.song-actions.is-narrow [song-actions]]])

View file

@ -62,6 +62,9 @@
(let [queue (song-queue 10)
linear (playlist/->playlist queue :playback-mode :linear :repeat-mode :repeat-none)
shuffled (playlist/set-playback-mode linear :shuffled)]
(testing "should indicate the new playback mode"
(is (= :linear (:playback-mode linear)))
(is (= :shuffled (:playback-mode shuffled))))
(testing "should re-order the tracks"
(is (not= (:items shuffled) (:items linear))))
(testing "should not change the currently playing track"
@ -72,10 +75,16 @@
(let [queue (song-queue 10)
shuffled (playlist/->playlist queue :playback-mode :shuffled :repeat-mode :repeat-none)
linear (playlist/set-playback-mode shuffled :linear)]
(testing "should indicate the new playback mode"
(is (= :linear (:playback-mode linear)))
(is (= :shuffled (:playback-mode shuffled))))
(testing "should set the correct order for tracks"
(let [linear-order (comp :playlist/linear-order meta)]
(is (every? #(apply same-song? %) (interleave queue (vals (:items linear)))))
(is (< (:playlist/linear-order (meta (first (vals (:items linear)))))
(:playlist/linear-order (meta (last (vals (:items linear))))))))
;; every song should have a smaller order than its successor
(is (->> (map linear-order (vals (:items linear)))
(partition 2 1)
(every? (fn [[a b]] (< a b)))))))
(testing "should not change the currently playing track"
(is (same-song? (playlist/current-song linear) (playlist/current-song shuffled))))
(testing "should not change the repeat mode"