diff options
author | Miguel Ángel Moreno <mail@migalmoreno.com> | 2024-12-09 00:15:23 +0100 |
---|---|---|
committer | Miguel Ángel Moreno <mail@migalmoreno.com> | 2024-12-09 00:15:23 +0100 |
commit | 73f1f8a94ed03d9187a5915cd1b64ebe808511ea (patch) | |
tree | 28a8e0c8fe39e1f5286d904821add4cc5647c3f1 /src/frontend | |
parent | d954370ea1ba01904f521cb0c8b8b0ea3812b4ab (diff) |
feat: add error handling to bookmarks import handlers
Diffstat (limited to 'src/frontend')
-rw-r--r-- | src/frontend/tubo/bookmarks/events.cljs | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/src/frontend/tubo/bookmarks/events.cljs b/src/frontend/tubo/bookmarks/events.cljs index decb107..eb5a9b4 100644 --- a/src/frontend/tubo/bookmarks/events.cljs +++ b/src/frontend/tubo/bookmarks/events.cljs @@ -62,16 +62,17 @@ (rf/reg-event-fx :likes/add-n - (fn [_ [_ items]] + (fn [_ [_ items notify?]] {:fx (conj (map (fn [item] [:dispatch [:likes/add item]]) items) - [:dispatch - [:notifications/add - {:status-text (str "Added " - (count items) - " items to likes") - :failure :success}]])})) + (when notify? + [:dispatch + [:notifications/add + {:status-text (str "Added " + (count items) + " items to likes") + :failure :success}]]))})) (rf/reg-event-fx :likes/add @@ -186,19 +187,27 @@ bookmarks) [:dispatch [:notifications/add - {:status-text "Imported playlists successfully" + {:status-text (str "Imported " + (count bookmarks) + " playlists successfully") :failure :success}]])})) (defn fetch-imported-bookmarks-items [bookmarks] (-> #(-> (p/all (map (fn [stream] - (p/then (js/fetch - (str "/api/v1/streams/" - (js/encodeURIComponent stream))) - (fn [res] (.json res)))) + (-> (js/fetch + (str "/api/v1/streams/" + (js/encodeURIComponent stream))) + (p/then (fn [res] (.json res))) + (p/catch (fn [] + (rf/dispatch + [:notifications/add + {:status-text + (str "Error importing " stream) + :failure :error}]))))) (:items %))) (p/then (fn [results] - (assoc % :items results)))) + (assoc % :items (remove nil? results))))) (map bookmarks) p/all)) @@ -213,8 +222,8 @@ [:bookmarks/add-imported]]} :fx [[:dispatch [:notifications/add - {:status-text "Importing playlists..." - :failure :success} + {:status-text "Importing playlists" + :failure :loading} false]]]})) (rf/reg-fx |