From 2fd76e17ef3fbfe970dd721f0ed0a9635da8b8df Mon Sep 17 00:00:00 2001 From: Miguel Ángel Moreno Date: Mon, 16 Oct 2023 00:33:17 +0200 Subject: feat(frontend): add initial support for media queueing --- src/frontend/tubo/events.cljs | 31 +++++++++++++++++++++++++------ src/frontend/tubo/subs.cljs | 9 +++++++-- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/frontend/tubo/events.cljs b/src/frontend/tubo/events.cljs index 87778b8..610b73e 100644 --- a/src/frontend/tubo/events.cljs +++ b/src/frontend/tubo/events.cljs @@ -15,6 +15,8 @@ :stream {} :search-results [] :services [] + :media-queue [] + :media-queue-pos 0 :current-match nil :page-scroll 0})) @@ -166,21 +168,38 @@ :nextPage (js/encodeURIComponent next-page-url)}) :db (assoc db :show-pagination-loading true))))) +(rf/reg-event-fx + ::add-to-media-queue + (fn [{:keys [db]} [_ stream]] + (let [media-queue (update db :media-queue conj stream)] + {:db media-queue + :fx [[:dispatch [::fetch-global-player-stream (:url stream)]]]}))) + +(rf/reg-event-fx + ::change-media-queue-pos + (fn [{:keys [db]} [_ idx]] + {:db (assoc db :media-queue-pos idx)})) + (rf/reg-event-db - ::change-global-stream - (fn [db [_ global-stream]] - (assoc db :global-stream global-stream))) + ::change-media-queue-stream + (fn [db [_ src]] + (let [idx (- (count (:media-queue db)) 1)] + (when-not (-> db :media-queue (nth idx) :stream) + (assoc-in db [:media-queue idx :stream] src))))) (rf/reg-event-db ::toggle-global-player (fn [db _] - (assoc db :show-global-player (not (:show-global-player db))))) + (-> db + (assoc :show-global-player (not (:show-global-player db))) + (assoc :media-queue []) + (assoc :media-queue-pos 0)))) (rf/reg-event-fx ::switch-to-global-player - (fn [{:keys [db]} [_ global-stream]] + (fn [{:keys [db]} [_ stream]] {:db (assoc db :show-global-player true) - :fx [[:dispatch [::change-global-stream global-stream]]]})) + :fx [[:dispatch [::add-to-media-queue stream]]]})) (rf/reg-event-db ::load-services diff --git a/src/frontend/tubo/subs.cljs b/src/frontend/tubo/subs.cljs index 88291ca..7c68b0b 100644 --- a/src/frontend/tubo/subs.cljs +++ b/src/frontend/tubo/subs.cljs @@ -73,9 +73,14 @@ (:page-scroll db))) (rf/reg-sub - :global-stream + :media-queue (fn [db _] - (:global-stream db))) + (:media-queue db))) + +(rf/reg-sub + :media-queue-pos + (fn [db _] + (:media-queue-pos db))) (rf/reg-sub :show-global-player -- cgit v1.2.3