Skip to content

Commit

Permalink
feat: move pages containing related streams to new scroll approach
Browse files Browse the repository at this point in the history
  • Loading branch information
migalmoreno committed Dec 8, 2024
1 parent b3a7566 commit cbd3e67
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 40 deletions.
9 changes: 4 additions & 5 deletions src/frontend/tubo/kiosks/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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])]]))))
8 changes: 3 additions & 5 deletions src/frontend/tubo/playlist/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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])]]))))
9 changes: 4 additions & 5 deletions src/frontend/tubo/search/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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])]]))))
25 changes: 0 additions & 25 deletions src/frontend/tubo/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 [_]
Expand Down

0 comments on commit cbd3e67

Please sign in to comment.