From 3233d3685bacf1e4e816fbc823e42b476a9b4d6d Mon Sep 17 00:00:00 2001 From: Miguel Ángel Moreno Date: Tue, 10 Dec 2024 11:11:41 +0100 Subject: feat: simplify stream enqueuing effect handler --- src/frontend/tubo/bg_player/events.cljs | 15 ++++----------- src/frontend/tubo/queue/events.cljs | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/frontend/tubo/bg_player/events.cljs b/src/frontend/tubo/bg_player/events.cljs index 297f0f0..c82b50e 100644 --- a/src/frontend/tubo/bg_player/events.cljs +++ b/src/frontend/tubo/bg_player/events.cljs @@ -86,19 +86,12 @@ (rf/reg-event-fx :bg-player/show [(rf/inject-cofx :store)] - (fn [{:keys [db store]} [_ stream notify?]] + (fn [{:keys [db]} [_ stream notify?]] (let [updated-db (update db :queue conj stream) idx (.indexOf (:queue updated-db) stream)] - {:db updated-db - :store (assoc store :queue (:queue updated-db)) - :fx [[:dispatch - [:bg-player/fetch-stream - (:url stream) idx (= (count (:queue db)) 0)]] - (when (and notify? (not (= (count (:queue db)) 0))) - [:dispatch - [:notifications/add - {:status-text "Added stream to queue" - :failure :info}]])]}))) + {:fx [(if (= (count (:queue db)) 0) + [:dispatch [:bg-player/fetch-stream (:url stream) idx true]] + [:dispatch [:queue/add stream notify?]])]}))) (rf/reg-event-fx :bg-player/start-radio diff --git a/src/frontend/tubo/queue/events.cljs b/src/frontend/tubo/queue/events.cljs index 2765af2..08bd9c0 100644 --- a/src/frontend/tubo/queue/events.cljs +++ b/src/frontend/tubo/queue/events.cljs @@ -3,6 +3,13 @@ [re-frame.core :as rf] [vimsical.re-frame.cofx.inject :as inject])) +(defn get-stream-metadata + [stream] + (select-keys stream + [:type :service-id :url :name :thumbnails :audio-streams + :video-streams :uploader-name :uploader-url :duration + :bookmark-id])) + (rf/reg-event-fx :queue/show (fn [{:keys [db]} [_ show?]] @@ -36,7 +43,7 @@ :queue/add [(rf/inject-cofx :store)] (fn [{:keys [db store]} [_ stream notify?]] - (let [updated-db (update db :queue conj stream)] + (let [updated-db (update db :queue conj (get-stream-metadata stream))] {:db updated-db :store (assoc store :queue (:queue updated-db)) :fx (if notify? @@ -108,7 +115,11 @@ [(rf/inject-cofx :store) (rf/inject-cofx ::inject/sub [:bg-player])] (fn [{:keys [db store bg-player]} [_ stream idx]] - (let [update-entry (fn [x] (update-in x [:queue idx] #(merge % stream)))] + (let [update-entry (fn [x] + (update-in + x + [:queue idx] + #(merge % (get-stream-metadata stream))))] {:db (assoc (update-entry db) :queue/position idx) :store (assoc (update-entry store) :queue/position idx) :player/src {:player bg-player -- cgit v1.2.3