diff options
author | Miguel Ángel Moreno <mail@migalmoreno.com> | 2024-06-04 13:33:16 +0200 |
---|---|---|
committer | Miguel Ángel Moreno <mail@migalmoreno.com> | 2024-06-04 13:33:16 +0200 |
commit | f8e45218cecb16ebbf81a637025319f72c89329e (patch) | |
tree | 1f23ada08d20345a7a7d7291fdc84f4e04bf731c /src/frontend | |
parent | a2003b0b0329b3bb50035b23bfbfcf256b41f200 (diff) |
feat: add bad page response handlers
Diffstat (limited to 'src/frontend')
-rw-r--r-- | src/frontend/tubo/channel/events.cljs | 22 | ||||
-rw-r--r-- | src/frontend/tubo/components/layout.cljs | 12 | ||||
-rw-r--r-- | src/frontend/tubo/kiosks/events.cljs | 21 | ||||
-rw-r--r-- | src/frontend/tubo/playlist/events.cljs | 4 | ||||
-rw-r--r-- | src/frontend/tubo/search/events.cljs | 14 | ||||
-rw-r--r-- | src/frontend/tubo/stream/events.cljs | 16 |
6 files changed, 75 insertions, 14 deletions
diff --git a/src/frontend/tubo/channel/events.cljs b/src/frontend/tubo/channel/events.cljs index 99903d5..5036e73 100644 --- a/src/frontend/tubo/channel/events.cljs +++ b/src/frontend/tubo/channel/events.cljs @@ -1,7 +1,9 @@ (ns tubo.channel.events (:require [re-frame.core :as rf] - [tubo.api :as api])) + [tubo.api :as api] + [tubo.channel.views :as channel] + [tubo.components.layout :as layout])) (rf/reg-event-fx :channel/fetch @@ -20,9 +22,17 @@ [:document-title (:name channel-res)]]}))) (rf/reg-event-fx + :channel/bad-page-response + (fn [{:keys [db]} [_ uri res]] + {:fx [[:dispatch [:change-view #(layout/error res [:channel/fetch-page uri])]]] + :db (assoc db :show-page-loading false)})) + +(rf/reg-event-fx :channel/fetch-page (fn [{:keys [db]} [_ uri]] - {:fx [[:dispatch [:channel/fetch uri [:channel/load-page] [:bad-response]]]] + {:fx [[:dispatch [:change-view channel/channel]] + [:dispatch [:channel/fetch uri [:channel/load-page] + [:channel/bad-page-response uri]]]] :db (assoc db :show-page-loading true)})) (rf/reg-event-db @@ -40,6 +50,12 @@ (assoc :show-pagination-loading false)))))) (rf/reg-event-fx + :channel/bad-paginated-response + (fn [{:keys [db]} [_ res]] + {:fx [[:dispatch [:bad-response res]]] + :db (assoc db :show-pagination-loading false)})) + +(rf/reg-event-fx :channel/fetch-paginated (fn [{:keys [db]} [_ uri next-page-url]] (if (empty? next-page-url) @@ -47,6 +63,6 @@ (assoc (api/get-request (str "/channels/" (js/encodeURIComponent uri) ) - [:channel/load-paginated] [:bad-response] + [:channel/load-paginated] [:channel/bad-paginated-response] {:nextPage (js/encodeURIComponent next-page-url)}) :db (assoc db :show-pagination-loading true))))) diff --git a/src/frontend/tubo/components/layout.cljs b/src/frontend/tubo/components/layout.cljs index 436ff83..b36f38c 100644 --- a/src/frontend/tubo/components/layout.cljs +++ b/src/frontend/tubo/components/layout.cljs @@ -206,3 +206,15 @@ [secondary-button (if (not open?) "Show More" "Show Less") on-open]])])}))) + +(defn error [{:keys [failure parse-error status status-text]} cb] + [:div.flex.flex-auto.h-full.items-center.justify-center + [:div.flex.flex-col.gap-y-6.border-border-neutral-300.rounded.dark:border-stone-700.bg-neutral-800.p-5 + [:div.flex.items-center.gap-2.text-xl + [:i.fa-solid.fa-circle-exclamation] + [:h3.font-bold (str (when status (str status ": ")) status-text)]] + (when parse-error + [:span (:status-text parse-error)]) + [:div.flex.justify-center.gap-x-3 + [primary-button "Go Back" #(rf/dispatch [:history-go -1])] + [secondary-button "Retry" #(rf/dispatch cb)]]]]) diff --git a/src/frontend/tubo/kiosks/events.cljs b/src/frontend/tubo/kiosks/events.cljs index c85fc51..5b0518b 100644 --- a/src/frontend/tubo/kiosks/events.cljs +++ b/src/frontend/tubo/kiosks/events.cljs @@ -1,7 +1,8 @@ (ns tubo.kiosks.events (:require [re-frame.core :as rf] - [tubo.api :as api])) + [tubo.api :as api] + [tubo.components.layout :as layout])) (rf/reg-event-db :kiosks/load @@ -37,12 +38,24 @@ [:document-title (:id kiosk-res)]]}))) (rf/reg-event-fx + :kiosks/bad-page-response + (fn [{:keys [db]} [_ service-id kiosk-id res]] + {:fx [[:dispatch [:change-view + #(layout/error + res (if kiosk-id + [:kiosks/fetch-page service-id kiosk-id] + [:kiosks/fetch-default-page service-id]))]]] + :db (assoc db :show-page-loading false)})) + +(rf/reg-event-fx :kiosks/fetch-page (fn [{:keys [db]} [_ service-id kiosk-id]] - {:db (assoc db :show-page-loading true) + {:db (assoc db + :show-page-loading true + :kiosk nil) :fx [[:dispatch (if kiosk-id [:kiosks/fetch service-id kiosk-id - [:kiosks/load-page] [:bad-response]] + [:kiosks/load-page] [:kiosks/bad-page-response service-id kiosk-id]] [:kiosks/fetch-default-page service-id])]]})) (rf/reg-event-fx @@ -55,7 +68,7 @@ {:fx [[:dispatch (if default-kiosk-id [:kiosks/fetch-page service-id default-kiosk-id] [:kiosks/fetch-default service-id - [:kiosks/load-page] [:bad-response]])]]}))) + [:kiosks/load-page] [:kiosks/bad-page-response service-id nil]])]]}))) (rf/reg-event-fx :kiosks/change-page diff --git a/src/frontend/tubo/playlist/events.cljs b/src/frontend/tubo/playlist/events.cljs index 730950e..5a96209 100644 --- a/src/frontend/tubo/playlist/events.cljs +++ b/src/frontend/tubo/playlist/events.cljs @@ -43,4 +43,6 @@ (fn [{:keys [db]} [_ url]] {:fx [[:dispatch [:playlist/fetch url [:playlist/load-page] [:bad-response]]]] - :db (assoc db :show-page-loading true)})) + :db (assoc db + :show-page-loading true + :playlist nil)})) diff --git a/src/frontend/tubo/search/events.cljs b/src/frontend/tubo/search/events.cljs index e09e5b3..cfa3fe5 100644 --- a/src/frontend/tubo/search/events.cljs +++ b/src/frontend/tubo/search/events.cljs @@ -1,7 +1,8 @@ (ns tubo.search.events (:require [re-frame.core :as rf] - [tubo.api :as api])) + [tubo.api :as api] + [tubo.components.layout :as layout])) (rf/reg-event-fx :search/fetch @@ -18,13 +19,20 @@ :fx [[:dispatch [:services/fetch search-res]]]}))) (rf/reg-event-fx + :search/bad-page-response + (fn [{:keys [db]} [_ service-id query res]] + {:fx [[:dispatch [:change-view #(layout/error res [:search/fetch-page service-id query])]]] + :db (assoc db :show-page-loading false)})) + +(rf/reg-event-fx :search/fetch-page (fn [{:keys [db]} [_ service-id query]] {:db (assoc db :show-page-loading true - :show-search-form true) + :show-search-form true + :search-results nil) :fx [[:dispatch [:search/fetch service-id - [:search/load-page] [:bad-response] {:q query}]] + [:search/load-page] [:search/bad-page-response service-id query] {:q query}]] [:document-title (str "Search for \"" query "\"")]]})) (rf/reg-event-db diff --git a/src/frontend/tubo/stream/events.cljs b/src/frontend/tubo/stream/events.cljs index 77737d2..6b4795a 100644 --- a/src/frontend/tubo/stream/events.cljs +++ b/src/frontend/tubo/stream/events.cljs @@ -1,7 +1,8 @@ (ns tubo.stream.events (:require [re-frame.core :as rf] - [tubo.api :as api])) + [tubo.api :as api] + [tubo.components.layout :as layout])) (rf/reg-event-fx :stream/fetch @@ -21,10 +22,19 @@ [:document-title (:name stream-res)]]}))) (rf/reg-event-fx + :stream/bad-page-response + (fn [{:keys [db]} [_ url res]] + {:fx [[:dispatch [:change-view #(layout/error res [:stream/fetch-page url])]]] + :db (assoc db :show-page-loading false)})) + +(rf/reg-event-fx :stream/fetch-page (fn [{:keys [db]} [_ url]] - {:fx [[:dispatch [:stream/fetch url [:stream/load-page] [:bad-response]]]] - :db (assoc db :show-page-loading true)})) + {:fx [[:dispatch [:stream/fetch url + [:stream/load-page] [:stream/bad-page-response url]]]] + :db (assoc db + :show-page-loading true + :stream nil)})) (rf/reg-event-db :stream/toggle-layout |