Browse Source

feat(frontend): Modularize related streams and add responsive styles

Miguel Ángel Moreno 2 years ago
parent
commit
fce327a725

+ 20 - 0
src/frontend/tau/components/items.cljs

@@ -1,6 +1,8 @@
 (ns tau.components.items
 (ns tau.components.items
   (:require
   (:require
+   [re-frame.core :as rf]
    [reitit.frontend.easy :as rfe]
    [reitit.frontend.easy :as rfe]
+   [tau.components.loading :as loading]
    [tau.util :as util]
    [tau.util :as util]
    ["timeago.js" :as timeago]))
    ["timeago.js" :as timeago]))
 
 
@@ -78,3 +80,21 @@
      [:div.flex.items-center
      [:div.flex.items-center
       [:i.fa-solid.fa-video.text-xs]
       [:i.fa-solid.fa-video.text-xs]
       [:p.mx-2 stream-count]]]]])
       [:p.mx-2 stream-count]]]]])
+
+(defn related-streams
+  [related-streams next-page-url]
+  (let [service-color @(rf/subscribe [:service-color])
+        pagination-loading? @(rf/subscribe [:show-pagination-loading])]
+    [:div.flex.flex-col.justify-center.items-center.flex-auto
+     (if (empty? related-streams)
+       [:div
+        [:p "No available streams"]]
+       [:div.flex.justify-center.flex-wrap
+        (for [[i item] (map-indexed vector related-streams)
+              :let [keyed-item (assoc item :key i)]]
+          (case (:type item)
+            "stream" [stream-item keyed-item]
+            "channel" [channel-item keyed-item]
+            "playlist" [playlist-item keyed-item]))])
+     (when-not (empty? next-page-url)
+       [loading/items-pagination-loading-icon service-color pagination-loading?])]))

+ 2 - 2
src/frontend/tau/components/navigation.cljs

@@ -4,8 +4,8 @@
    [tau.events :as events]))
    [tau.events :as events]))
 
 
 (defn back-button [service-color]
 (defn back-button [service-color]
-  [:div.flex {:class "w-4/5"}
+  [:div.flex.items-center {:class "w-4/5"}
-   [:button.p-2
+   [:button.py-4
     {:on-click #(rf/dispatch [::events/history-back])}
     {:on-click #(rf/dispatch [::events/history-back])}
     [:i.fa-solid.fa-chevron-left
     [:i.fa-solid.fa-chevron-left
      {:style {:color service-color}}]
      {:style {:color service-color}}]

+ 2 - 7
src/frontend/tau/views/channel.cljs

@@ -21,7 +21,7 @@
     [:div.flex.flex-col.items-center.px-5.py-2.flex-auto
     [:div.flex.flex-col.items-center.px-5.py-2.flex-auto
      (if page-loading?
      (if page-loading?
        [loading/page-loading-icon service-color]
        [loading/page-loading-icon service-color]
-       [:div {:class "w-4/5"}
+       [:div.flex.flex-col {:class "w-4/5"}
         [navigation/back-button service-color]
         [navigation/back-button service-color]
         (when banner
         (when banner
           [:div
           [:div
@@ -38,9 +38,4 @@
              [:span.mx-2 (.toLocaleString subscriber-count)]])]]
              [:span.mx-2 (.toLocaleString subscriber-count)]])]]
         [:div.my-2
         [:div.my-2
          [:p description]]
          [:p description]]
-        [:div.flex.justify-center.items-center.align-center
+        [items/related-streams related-streams next-page-url]])]))
-         [:div.flex.justify-start.flex-wrap
-          (for [[i result] (map-indexed vector related-streams)]
-            [items/stream-item (assoc result :key i)])]]
-        (when-not (empty? next-page-url)
-           [loading/items-pagination-loading-icon service-color pagination-loading?])])]))

+ 2 - 11
src/frontend/tau/views/kiosk.cljs

@@ -12,7 +12,6 @@
         next-page-url (:url next-page)
         next-page-url (:url next-page)
         service-color @(rf/subscribe [:service-color])
         service-color @(rf/subscribe [:service-color])
         page-loading? @(rf/subscribe [:show-page-loading])
         page-loading? @(rf/subscribe [:show-page-loading])
-        pagination-loading? @(rf/subscribe [:show-pagination-loading])
         page-scroll @(rf/subscribe [:page-scroll])
         page-scroll @(rf/subscribe [:page-scroll])
         scrolled-to-bottom? (= page-scroll (.-scrollHeight js/document.body))]
         scrolled-to-bottom? (= page-scroll (.-scrollHeight js/document.body))]
     (when scrolled-to-bottom?
     (when scrolled-to-bottom?
@@ -20,16 +19,8 @@
     [:div.flex.flex-col.items-center.px-5.py-2.flex-auto
     [:div.flex.flex-col.items-center.px-5.py-2.flex-auto
      (if page-loading?
      (if page-loading?
        [loading/page-loading-icon service-color]
        [loading/page-loading-icon service-color]
-       [:div
+       [:div.flex.flex-col.flex-auto.w-full {:class "lg:w-4/5"}
         [:div.flex.justify-center.items-center.my-4.mx-2
         [:div.flex.justify-center.items-center.my-4.mx-2
          [:div.m-4
          [:div.m-4
           [:h1.text-2xl id]]]
           [:h1.text-2xl id]]]
-        [:div.flex.justify-center.items-center.align-center
+        [items/related-streams related-streams next-page-url]])]))
-         [:div.flex.justify-start.flex-wrap
-          (for [[i item] (map-indexed vector related-streams)]
-            (case (:type item)
-              "stream" [items/stream-item (assoc item :key i)]
-              "channel" [items/channel-item (assoc item :key i)]
-              "playlist" [items/playlist-item (assoc item :key i)]))]]
-        (when-not (empty? next-page-url)
-           [loading/items-pagination-loading-icon service-color pagination-loading?])])]))

+ 2 - 10
src/frontend/tau/views/playlist.cljs

@@ -15,7 +15,6 @@
         next-page-url (:url next-page)
         next-page-url (:url next-page)
         service-color @(rf/subscribe [:service-color])
         service-color @(rf/subscribe [:service-color])
         page-loading? @(rf/subscribe [:show-page-loading])
         page-loading? @(rf/subscribe [:show-page-loading])
-        pagination-loading? @(rf/subscribe [:show-pagination-loading])
         page-scroll @(rf/subscribe [:page-scroll])
         page-scroll @(rf/subscribe [:page-scroll])
         scrolled-to-bottom? (= page-scroll (.-scrollHeight js/document.body))]
         scrolled-to-bottom? (= page-scroll (.-scrollHeight js/document.body))]
     (when scrolled-to-bottom?
     (when scrolled-to-bottom?
@@ -23,7 +22,7 @@
     [:div.flex.flex-col.items-center.px-5.pt-4.flex-auto
     [:div.flex.flex-col.items-center.px-5.pt-4.flex-auto
      (if page-loading?
      (if page-loading?
        [loading/page-loading-icon service-color]
        [loading/page-loading-icon service-color]
-       [:div.flex.flex-col.flex-auto
+       [:div.flex.flex-col.flex-auto.w-full {:class "lg:w-4/5"}
         [navigation/back-button service-color]
         [navigation/back-button service-color]
         (when banner-url
         (when banner-url
           [:div
           [:div
@@ -38,11 +37,4 @@
              [:a {:href (rfe/href :tau.routes/channel nil {:url uploader-url}) :title uploader-name}
              [:a {:href (rfe/href :tau.routes/channel nil {:url uploader-url}) :title uploader-name}
               [:img.rounded-full.object-cover.min-h-full.min-w-full {:src uploader-avatar :alt uploader-name}]]]]]
               [:img.rounded-full.object-cover.min-h-full.min-w-full {:src uploader-avatar :alt uploader-name}]]]]]
           [:p.pt-4 (str stream-count " streams")]]]
           [:p.pt-4 (str stream-count " streams")]]]
-        (if (empty? related-streams)
+        [items/related-streams related-streams next-page-url]])]))
-          [:div.flex.flex-auto.justify-center.items-center
-           [:p.text-2xl "No streams available"]]
-          [:div.flex.justify-center.align-center.flex-wrap.my-2
-           (for [[i result] (map-indexed vector related-streams)]
-             [items/stream-item (assoc result :key i)])
-           (when-not (empty? next-page-url)
-             [loading/items-pagination-loading-icon service-color pagination-loading?])])])]))

+ 3 - 12
src/frontend/tau/views/search.cljs

@@ -15,23 +15,14 @@
         service-color @(rf/subscribe [:service-color])
         service-color @(rf/subscribe [:service-color])
         page-scroll @(rf/subscribe [:page-scroll])
         page-scroll @(rf/subscribe [:page-scroll])
         page-loading? @(rf/subscribe [:show-page-loading])
         page-loading? @(rf/subscribe [:show-page-loading])
-        pagination-loading? @(rf/subscribe [:show-pagination-loading])
         scrolled-to-bottom? (= page-scroll (.-scrollHeight js/document.body))]
         scrolled-to-bottom? (= page-scroll (.-scrollHeight js/document.body))]
     (when scrolled-to-bottom?
     (when scrolled-to-bottom?
       (rf/dispatch [::events/search-pagination q serviceId next-page-url]))
       (rf/dispatch [::events/search-pagination q serviceId next-page-url]))
-    [:div.flex.flex-col.text-gray-300.h-box-border.flex-auto
+    [:div.flex.flex-col.items-center.flex-auto
      [:div.flex.flex-col.items-center.w-full.pt-4.flex-initial
      [:div.flex.flex-col.items-center.w-full.pt-4.flex-initial
       [:h2 (str "Showing search results for: \"" q "\"")]
       [:h2 (str "Showing search results for: \"" q "\"")]
       [:h1 (str "Number of search results: " (count items))]]
       [:h1 (str "Number of search results: " (count items))]]
      (if page-loading?
      (if page-loading?
        [loading/page-loading-icon service-color]
        [loading/page-loading-icon service-color]
-       (when items
+       [:div.flex.flex-col.flex-auto.w-full {:class "lg:w-4/5"}
-         [:div.flex.flex-col
+        [items/related-streams items next-page-url]])]))
-          [:div.flex.justify-center.align-center.flex-wrap.flex-auto
-           (for [[i item] (map-indexed vector items)]
-             (case (:type item)
-               "stream" [items/stream-item (assoc item :key i)]
-               "channel" [items/channel-item (assoc item :key i)]
-               "playlist" [items/playlist-item (assoc item :key i)]))
-           (when-not (empty? next-page-url)
-             [loading/items-pagination-loading-icon service-color pagination-loading?])]]))]))

+ 75 - 79
src/frontend/tau/views/stream.cljs

@@ -22,87 +22,83 @@
                         :content)
                         :content)
         page-loading? @(rf/subscribe [:show-page-loading])
         page-loading? @(rf/subscribe [:show-page-loading])
         service-color @(rf/subscribe [:service-color])]
         service-color @(rf/subscribe [:service-color])]
-    [:div.flex.flex-col.p-5.items-center.justify-center.text-white.flex-auto
+    [:div.flex.flex-col.items-center.justify-center.text-white.flex-auto
      (if page-loading?
      (if page-loading?
        [loading/page-loading-icon service-color]
        [loading/page-loading-icon service-color]
-       [:div {:class "w-4/5"}
+       [:div.w-full {:class "md:w-4/5 xl:w-3/5"}
         [navigation/back-button service-color]
         [navigation/back-button service-color]
-        [:div.flex.justify-center.relative.my-2
+        [:div.flex.justify-center.relative
-         {:style {:background (str "center / cover no-repeat url('" thumbnail-url"')")
+         {:style {:background (str "center / cover no-repeat url('" thumbnail-url"')")}
-                  :height "450px"}}
+          :class "md:h-[450px] lg:h-[600px]"}
          [:video.bottom-0.object-cover.max-h-full.min-w-full
          [:video.bottom-0.object-cover.max-h-full.min-w-full
           {:src stream-type :controls true}]]
           {:src stream-type :controls true}]]
-        [:div.flex.flex.w-full.mt-3.justify-center
+        [:div.px-4.md:p-0
-         [:button.border.rounded.border-black.px-3.py-1.bg-stone-800
+         [:div.flex.flex.w-full.mt-3.justify-center
-          {:on-click #(rf/dispatch [::events/switch-to-global-player stream])}
+          [:button.border.rounded.border-black.px-3.py-1.bg-stone-800
-          [:i.fa-solid.fa-headphones]]
+           {:on-click #(rf/dispatch [::events/switch-to-global-player stream])}
-         [:a {:href url}
+           [:i.fa-solid.fa-headphones]]
-          [:button.border.rounded.border-black.px-3.py-1.bg-stone-800.mx-2
+          [:a {:href url}
-           [:i.fa-solid.fa-external-link-alt]]]]
+           [:button.border.rounded.border-black.px-3.py-1.bg-stone-800.mx-2
-        [:div.flex.flex-col.py-1.comments
+            [:i.fa-solid.fa-external-link-alt]]]]
-         [:div.min-w-full.py-3
+         [:div.flex.flex-col.py-1.comments
-          [:h1.text-2xl.font-extrabold name]]
+          [:div.min-w-full.py-3
-         [:div.flex.justify-between.py-2
+           [:h1.text-2xl.font-extrabold name]]
-          [:div.flex.items-center.flex-auto
+          [:div.flex.justify-between.py-2
-           (when uploader-avatar
+           [:div.flex.items-center.flex-auto
-             [:div.relative.w-16.h-16
+            (when uploader-avatar
-              [:a {:href (rfe/href :tau.routes/channel nil {:url uploader-url}) :title uploader-author}
+              [:div.relative.w-16.h-16
-               [:img.rounded-full.object-cover.max-w-full.min-h-full {:src uploader-avatar :alt uploader-author}]]])
+               [:a {:href (rfe/href :tau.routes/channel nil {:url uploader-url}) :title uploader-author}
-           [:div.mx-2
+                [:img.rounded-full.object-cover.max-w-full.min-h-full {:src uploader-avatar :alt uploader-author}]]])
-            [:a {:href (rfe/href :tau.routes/channel nil {:url uploader-url})} uploader-author]
+            [:div.mx-2
-            (when subscriber-count
+             [:a {:href (rfe/href :tau.routes/channel nil {:url uploader-url})} uploader-author]
-              [:div.flex.my-2.items-center
+             (when subscriber-count
-               [:i.fa-solid.fa-users.text-xs]
+               [:div.flex.my-2.items-center
-               [:p.mx-2 (util/format-quantity subscriber-count)]])]]
+                [:i.fa-solid.fa-users.text-xs]
-          [:div.flex.flex-col.items-end
+                [:p.mx-2 (util/format-quantity subscriber-count)]])]]
-           (when view-count
+           [:div.flex.flex-col.items-end
-             [:div
+            (when view-count
-              [:i.fa-solid.fa-eye.text-xs]
+              [:div
-              [:span.ml-2 (.toLocaleString view-count)]])
+               [:i.fa-solid.fa-eye.text-xs]
-           [:div.flex
+               [:span.ml-2 (.toLocaleString view-count)]])
-            (when like-count
+            [:div.flex
-              [:div.items-center
+             (when like-count
-               [:i.fa-solid.fa-thumbs-up.text-xs]
+               [:div.items-center
-               [:span.ml-2 (.toLocaleString like-count)]])
+                [:i.fa-solid.fa-thumbs-up.text-xs]
-            (when dislike-count
+                [:span.ml-2 (.toLocaleString like-count)]])
-              [:div.ml-2.items-center
+             (when dislike-count
-               [:i.fa-solid.fa-thumbs-down.text-xs]
+               [:div.ml-2.items-center
-               [:span.ml-2 dislike-count]])]
+                [:i.fa-solid.fa-thumbs-down.text-xs]
-           (when upload-date
+                [:span.ml-2 dislike-count]])]
-             [:div
+            (when upload-date
-              [:i.fa-solid.fa-calendar.mx-2.text-xs]
+              [:div
-              [:span
+               [:i.fa-solid.fa-calendar.mx-2.text-xs]
-               (-> upload-date
+               [:span
-                   js/Date.parse
+                (-> upload-date
-                   js/Date.
+                    js/Date.parse
-                   .toDateString)]])]]
+                    js/Date.
-         [:div.min-w-full.py-3
+                    .toDateString)]])]]
-          [:h1 name]
+          [:div.min-w-full.py-3
-          [:div {:dangerouslySetInnerHTML {:__html description}}]]
+           [:h1 name]
-         [:div.py-3
+           [:div {:dangerouslySetInnerHTML {:__html description}}]]
-          [:div.flex.items-center
+          [:div.py-3
-           [:i.fa-solid.fa-comments]
+           [:div.flex.items-center
-           [:p.px-2 "Comments"]
+            [:i.fa-solid.fa-comments]
-           (if show-comments
+            [:p.px-2 "Comments"]
-             [:i.fa-solid.fa-chevron-up {:on-click #(rf/dispatch [::events/toggle-comments])
+            (if show-comments
-                                           :style {:cursor "pointer"}}]
+              [:i.fa-solid.fa-chevron-up {:on-click #(rf/dispatch [::events/toggle-comments])
-             [:i.fa-solid.fa-chevron-down {:on-click #(if show-comments
+                                          :style {:cursor "pointer"}}]
-                                                        (rf/dispatch [::events/toggle-comments])
+              [:i.fa-solid.fa-chevron-down {:on-click #(if (or show-comments comments-page)
-                                                        (rf/dispatch [::events/get-comments url]))
+                                                         (rf/dispatch [::events/toggle-comments])
-                                           :style {:cursor "pointer"}}])]
+                                                         (rf/dispatch [::events/get-comments url]))
-          [:div
+                                            :style {:cursor "pointer"}}])]
-           (if show-comments-loading
+           [:div
-             [loading/page-loading-icon service-color]
+            (if show-comments-loading
-             (when (and show-comments comments-page)
+              [loading/page-loading-icon service-color]
-               [comments/comments comments-page uploader-author uploader-avatar url]))]]
+              (when (and show-comments comments-page)
-         (when-not (empty? related-streams)
+                [comments/comments comments-page uploader-author uploader-avatar url]))]]
-           [:div.py-3
+          (when-not (empty? related-streams)
-            [:div.flex.items-center
+            [:div.py-3
-             [:i.fa-solid.fa-list]
+             [:div.flex.items-center
-             [:h1.px-2.text-lg.bold "Related Results"]]
+              [:i.fa-solid.fa-list]
-            [:div.flex.justify-center.align-center.flex-wrap
+              [:h1.px-2.text-lg.bold "Related Results"]]
-             (for [[i item] (map-indexed vector related-streams)]
+             [items/related-streams related-streams nil]])]]])]))
-               (case (:type item)
-                 "stream" [items/stream-item (assoc item :key i)]
-                 "channel" [items/channel-item (assoc item :key i)]
-                 "playlist" [items/playlist-item (assoc item :key i)]))]])]])]))