From c29e709decfee4d7535ed3affb271472cc7ed053 Mon Sep 17 00:00:00 2001 From: Miguel Ángel Moreno Date: Mon, 22 Jan 2024 01:12:25 +0100 Subject: feat(frontend): add media queue position guard at event level --- src/frontend/tubo/events.cljs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/frontend') diff --git a/src/frontend/tubo/events.cljs b/src/frontend/tubo/events.cljs index c4086ab..2c21dae 100644 --- a/src/frontend/tubo/events.cljs +++ b/src/frontend/tubo/events.cljs @@ -238,13 +238,17 @@ (rf/reg-event-fx ::change-media-queue-pos [(rf/inject-cofx :store)] - (fn [{:keys [db store]} [_ idx]] - (let [stream (get (:media-queue db) idx)] - {:db (-> db - (assoc :media-queue-pos idx) - (assoc-in [:media-queue idx :stream] "")) - :store (assoc store :media-queue-pos idx) - :fx [[:dispatch [::fetch-audio-player-stream (:url stream) idx]]]}))) + (fn [{:keys [db store]} [_ i]] + (let [idx (if (< i (count (:media-queue db))) + i + (when (= (:loop-playback db) :playlist) 0)) + stream (get (:media-queue db) idx)] + (when stream + {:db (-> db + (assoc :media-queue-pos idx) + (assoc-in [:media-queue idx :stream] "")) + :store (assoc store :media-queue-pos idx) + :fx [[:dispatch [::fetch-audio-player-stream (:url stream) idx true]]]})))) (rf/reg-event-fx ::change-media-queue-stream -- cgit v1.2.3