From fafbe80a343c0d0bf384ee5eb7bb26ba26554612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20Schl=C3=BCter?= Date: Sun, 25 Nov 2018 13:59:49 +0100 Subject: [PATCH] Fix for safari autoplay bug (#34) --- src/cljs/airsonic_ui/components/podcast/views.cljs | 4 +++- src/cljs/airsonic_ui/helpers.cljs | 9 ++++++--- src/cljs/airsonic_ui/views/song.cljs | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/cljs/airsonic_ui/components/podcast/views.cljs b/src/cljs/airsonic_ui/components/podcast/views.cljs index 2655cbd..07ec8d2 100644 --- a/src/cljs/airsonic_ui/components/podcast/views.cljs +++ b/src/cljs/airsonic_ui/components/podcast/views.cljs @@ -52,7 +52,9 @@ " - " [:a {:title (:title episode) :href "#" - :on-click (muted-dispatch [:audio-player/play-all episodes idx])} + ;; the reason for :sync? true can be found here + ;; https://github.com/heyarne/airsonic-ui/issues/33 + :on-click (muted-dispatch [:audio-player/play-all episodes idx] :sync? true)} (:title episode)]]]] (episode-actions episode)))]) diff --git a/src/cljs/airsonic_ui/helpers.cljs b/src/cljs/airsonic_ui/helpers.cljs index b17e98d..046801c 100644 --- a/src/cljs/airsonic_ui/helpers.cljs +++ b/src/cljs/airsonic_ui/helpers.cljs @@ -12,11 +12,14 @@ (when (p song) (reduced [idx song]))) nil))) (defn muted-dispatch - "Dispatches a re-frame event while canceling default DOM behavior" - [ev] + "Dispatches a re-frame event while canceling default DOM behavior; to be + called for example in `:on-click`." + [ev & {:keys [sync?]}] (fn [e] (.preventDefault e) - (rf/dispatch ev))) + (if sync? + (rf/dispatch-sync ev) + (rf/dispatch ev)))) (defn add-classes "Adds one or more classes to a hiccup keyword" diff --git a/src/cljs/airsonic_ui/views/song.cljs b/src/cljs/airsonic_ui/views/song.cljs index 358a279..2133a54 100644 --- a/src/cljs/airsonic_ui/views/song.cljs +++ b/src/cljs/airsonic_ui/views/song.cljs @@ -13,7 +13,7 @@ (:artist song)) " - " [:a - {:href "#" :on-click (muted-dispatch [:audio-player/play-all songs idx])} + {:href "#" :on-click (muted-dispatch [:audio-player/play-all songs idx] :sync? true)} (:title song)] [:span.duration (format-duration duration)]]))