aboutsummaryrefslogtreecommitdiff
path: root/src/frontend/tau/views/search.cljs
blob: b6bc75d04f152bdd95e5b16a5b514a3b66be22a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(ns tau.views.search
  (:require
   [re-frame.core :as rf]
   [reitit.frontend.easy :as rfe]
   [tau.components.items :as items]
   [tau.components.loading :as loading]
   [tau.events :as events]))

(defn search
  [{{:keys [q serviceId]} :query-params}]
  (let [{:keys [items next-page] :as search-results} @(rf/subscribe [:search-results])
        next-page-url (:url next-page)
        services @(rf/subscribe [:services])
        service-id @(rf/subscribe [:service-id])
        service-color @(rf/subscribe [:service-color])
        page-scroll @(rf/subscribe [:page-scroll])
        page-loading? @(rf/subscribe [:show-page-loading])
        pagination-loading? @(rf/subscribe [:show-pagination-loading])
        scrolled-to-bottom? (= page-scroll (.-scrollHeight js/document.body))]
    (when scrolled-to-bottom?
      (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.w-full.pt-4.flex-initial
      [:h2 (str "Showing search results for: \"" q "\"")]
      [:h1 (str "Number of search results: " (count items))]]
     (if page-loading?
       [loading/page-loading-icon service-color]
       (when items
         [:div.flex.flex-col
          [: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?])]]))]))