diff options
author | Miguel Ángel Moreno <mail@migalmoreno.com> | 2024-12-10 11:11:41 +0100 |
---|---|---|
committer | Miguel Ángel Moreno <mail@migalmoreno.com> | 2024-12-10 11:11:41 +0100 |
commit | 3233d3685bacf1e4e816fbc823e42b476a9b4d6d (patch) | |
tree | 07f20756c006a64e60fd0405f0b48ad53750300d | |
parent | 78ce36593a88278bf8be66a545e4a30c65eaa11c (diff) |
feat: simplify stream enqueuing effect handler
-rw-r--r-- | src/frontend/tubo/bg_player/events.cljs | 15 | ||||
-rw-r--r-- | 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 |