From cbd3e6733d5a023bcfc297421e1dee74ff03e5ef Mon Sep 17 00:00:00 2001 From: Miguel Ángel Moreno Date: Sun, 8 Dec 2024 22:01:13 +0100 Subject: feat: move pages containing related streams to new scroll approach --- src/frontend/tubo/kiosks/views.cljs | 9 ++++----- src/frontend/tubo/playlist/views.cljs | 8 +++----- src/frontend/tubo/search/views.cljs | 9 ++++----- src/frontend/tubo/subs.cljs | 25 ------------------------- 4 files changed, 11 insertions(+), 40 deletions(-) diff --git a/src/frontend/tubo/kiosks/views.cljs b/src/frontend/tubo/kiosks/views.cljs index 842f591..49497c3 100644 --- a/src/frontend/tubo/kiosks/views.cljs +++ b/src/frontend/tubo/kiosks/views.cljs @@ -39,10 +39,9 @@ (let [{:keys [id related-streams next-page]} @(rf/subscribe [:kiosk]) next-page-url (:url next-page) - service-id (or @(rf/subscribe [:service-id]) serviceId) - scrolled-to-bottom? @(rf/subscribe [:scrolled-to-bottom])] - (when scrolled-to-bottom? - (rf/dispatch [:kiosks/fetch-paginated service-id id next-page-url])) + service-id (or @(rf/subscribe [:service-id]) serviceId)] [layout/content-container [layout/content-header id [items/layout-switcher !layout]] - [items/related-streams related-streams next-page-url !layout]])))) + [items/related-streams related-streams next-page-url !layout + #(rf/dispatch [:kiosks/fetch-paginated service-id id + next-page-url])]])))) diff --git a/src/frontend/tubo/playlist/views.cljs b/src/frontend/tubo/playlist/views.cljs index 09fe2a0..8a4f1fd 100644 --- a/src/frontend/tubo/playlist/views.cljs +++ b/src/frontend/tubo/playlist/views.cljs @@ -31,10 +31,7 @@ stream-count] :as playlist} @(rf/subscribe [:playlist]) - next-page-url (:url next-page) - scrolled-to-bottom? @(rf/subscribe [:scrolled-to-bottom])] - (when scrolled-to-bottom? - (rf/dispatch [:playlist/fetch-paginated url next-page-url])) + next-page-url (:url next-page)] [layout/content-container [:div.flex.flex-col.justify-center [layout/content-header @@ -51,4 +48,5 @@ :title uploader-name} uploader-name]] [items/layout-switcher !layout]]] - [items/related-streams related-streams next-page-url !layout]])))) + [items/related-streams related-streams next-page-url !layout + #(rf/dispatch [:playlist/fetch-paginated url next-page-url])]])))) diff --git a/src/frontend/tubo/search/views.cljs b/src/frontend/tubo/search/views.cljs index 4cfe90e..6abe362 100644 --- a/src/frontend/tubo/search/views.cljs +++ b/src/frontend/tubo/search/views.cljs @@ -12,10 +12,9 @@ (let [{:keys [items next-page]} @(rf/subscribe [:search/results]) next-page-url (:url next-page) service-id (or @(rf/subscribe [:service-id]) - serviceId) - scrolled-to-bottom? @(rf/subscribe [:scrolled-to-bottom])] - (when scrolled-to-bottom? - (rf/dispatch [:search/fetch-paginated q service-id next-page-url])) + serviceId)] [layout/content-container [items/layout-switcher !layout] - [items/related-streams items next-page-url !layout]])))) + [items/related-streams items next-page-url !layout + #(rf/dispatch [:search/fetch-paginated q service-id + next-page-url])]])))) diff --git a/src/frontend/tubo/subs.cljs b/src/frontend/tubo/subs.cljs index 9b952e1..8c0575f 100644 --- a/src/frontend/tubo/subs.cljs +++ b/src/frontend/tubo/subs.cljs @@ -18,21 +18,6 @@ [tubo.settings.subs] [tubo.stream.subs])) -(defonce !is-window-visible - (let [a (r/atom true)] - (.addEventListener js/window "focus" #(reset! a true)) - (.addEventListener js/window "blur" #(reset! a false)) - a)) - -(defonce !scroll-distance - (let [a (r/atom 0) - compute-scroll-distance - #(when (> (.-scrollY js/window) 0) - (reset! a (+ (.-scrollY js/window) (.-innerHeight js/window))))] - (.addEventListener js/window "scroll" compute-scroll-distance) - (.addEventListener js/window "touchmove" compute-scroll-distance) - a)) - (defonce !auto-theme (let [theme (r/atom (when (and (.-matchMedia js/window) (.-matches @@ -44,16 +29,6 @@ #(reset! theme (if (.-matches %) "dark" "light"))) theme)) -(rf/reg-sub - :is-window-visible - (fn [_ _] - @!is-window-visible)) - -(rf/reg-sub - :scrolled-to-bottom - (fn [_ _] - (> (+ @!scroll-distance 35) (.-scrollHeight js/document.body)))) - (rf/reg-sub :dark-theme (fn [_] -- cgit v1.2.3