mirror of
https://github.com/heyarne/airsonic-ui.git
synced 2026-05-06 18:33:38 +02:00
Be more consistent when naming events
This commit is contained in:
parent
4639f4ef27
commit
a9c95bc4a8
3 changed files with 25 additions and 20 deletions
|
|
@ -18,7 +18,7 @@
|
||||||
; explanation of these events: https://developer.mozilla.org/en-US/Apps/Fundamentals/Audio_and_video_delivery/Cross-browser_audio_basics
|
; explanation of these events: https://developer.mozilla.org/en-US/Apps/Fundamentals/Audio_and_video_delivery/Cross-browser_audio_basics
|
||||||
(defn attach-listeners! [el]
|
(defn attach-listeners! [el]
|
||||||
(doseq [event ["loadstart" "progress" "play" "timeupdate" "pause"]]
|
(doseq [event ["loadstart" "progress" "play" "timeupdate" "pause"]]
|
||||||
(.addEventListener el event #(re-frame/dispatch [:audio-update (->status el)]))))
|
(.addEventListener el event #(re-frame/dispatch [:audio/update (->status el)]))))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
:play-song
|
:play-song
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,18 @@
|
||||||
[airsonic-ui.db :as db]
|
[airsonic-ui.db :as db]
|
||||||
[airsonic-ui.api :as api]))
|
[airsonic-ui.api :as api]))
|
||||||
|
|
||||||
|
;; this is where all of the event handling takes place; the names put the events into
|
||||||
|
;; the following categories:
|
||||||
|
;; ::events/something-happening -> relevant to only this app
|
||||||
|
;; :single-colon/something -> coming from external sources (e.g. :audio/... or :routes/...) that are potentially reusable
|
||||||
|
|
||||||
|
;; database reset / init
|
||||||
|
|
||||||
|
(re-frame/reg-event-db
|
||||||
|
::initialize-db
|
||||||
|
(fn [_]
|
||||||
|
db/default-db))
|
||||||
|
|
||||||
;; this is called with user and password to try and see if the credentials are
|
;; this is called with user and password to try and see if the credentials are
|
||||||
;; correct; if yes, ::auth-success will be fired
|
;; correct; if yes, ::auth-success will be fired
|
||||||
|
|
||||||
|
|
@ -25,7 +37,7 @@
|
||||||
(fn [{:keys [db]} [_ user pass response]]
|
(fn [{:keys [db]} [_ user pass response]]
|
||||||
;; TODO: Handle failures differently
|
;; TODO: Handle failures differently
|
||||||
(let [login {:u user :p pass}]
|
(let [login {:u user :p pass}]
|
||||||
{::routes/set-credentials login
|
{:routes/set-credentials login
|
||||||
:db (-> (update db :active-requests #(max (dec %) 0))
|
:db (-> (update db :active-requests #(max (dec %) 0))
|
||||||
(assoc :login login))
|
(assoc :login login))
|
||||||
:dispatch [::logged-in]})))
|
:dispatch [::logged-in]})))
|
||||||
|
|
@ -34,7 +46,7 @@
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::logged-in
|
::logged-in
|
||||||
(fn [_ _]
|
(fn [_ _]
|
||||||
{::routes/navigate [::routes/main]}))
|
{:routes/navigate [::routes/main]}))
|
||||||
|
|
||||||
;; TODO: Test that credentials are actually taken
|
;; TODO: Test that credentials are actually taken
|
||||||
;; TODO: Move these in the future? events.cljs should just do wiring. We could
|
;; TODO: Move these in the future? events.cljs should just do wiring. We could
|
||||||
|
|
@ -79,7 +91,7 @@
|
||||||
{:toggle-play-pause nil}))
|
{:toggle-play-pause nil}))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
:audio-update
|
:audio/update
|
||||||
(fn [db [_ status]]
|
(fn [db [_ status]]
|
||||||
; we receive this from the player once it's playing
|
; we receive this from the player once it's playing
|
||||||
(assoc-in db [:currently-playing :status] status)))
|
(assoc-in db [:currently-playing :status] status)))
|
||||||
|
|
@ -87,7 +99,7 @@
|
||||||
;; routing
|
;; routing
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::routes/navigation
|
:routes/navigation
|
||||||
(fn [{:keys [db]} [_ route params query]]
|
(fn [{:keys [db]} [_ route params query]]
|
||||||
;; all the naviagation logic is in routes.cljs; all we need to do here
|
;; all the naviagation logic is in routes.cljs; all we need to do here
|
||||||
;; is say what actually happens once we've navigated succesfully
|
;; is say what actually happens once we've navigated succesfully
|
||||||
|
|
@ -95,16 +107,9 @@
|
||||||
:dispatch (routes/route-data route params query)}))
|
:dispatch (routes/route-data route params query)}))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::routes/unauthorized
|
:routes/unauthorized
|
||||||
(fn [fx _]
|
(fn [fx _]
|
||||||
;; log out on 403
|
;; log out on 403
|
||||||
{::routes/navigate [routes/default-route]
|
{:routes/navigate [routes/default-route]
|
||||||
::routes/unset-credentials nil
|
:routes/unset-credentials nil
|
||||||
:db db/default-db}))
|
:db db/default-db}))
|
||||||
|
|
||||||
;; database reset / init
|
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
|
||||||
::initialize-db
|
|
||||||
(fn [_]
|
|
||||||
db/default-db))
|
|
||||||
|
|
|
||||||
|
|
@ -42,17 +42,17 @@
|
||||||
(def credentials (atom nil))
|
(def credentials (atom nil))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
::set-credentials
|
:routes/set-credentials
|
||||||
(fn [credentials']
|
(fn [credentials']
|
||||||
(reset! credentials credentials')))
|
(reset! credentials credentials')))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
::unset-credentials
|
:routes/unset-credentials
|
||||||
(fn []
|
(fn []
|
||||||
(reset! credentials nil)))
|
(reset! credentials nil)))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
::navigate
|
:routes/navigate
|
||||||
(fn [[route-id params query]]
|
(fn [[route-id params query]]
|
||||||
(println "calling ::navigate with" route-id params query)
|
(println "calling ::navigate with" route-id params query)
|
||||||
(r/navigate! router route-id params query)))
|
(r/navigate! router route-id params query)))
|
||||||
|
|
@ -63,8 +63,8 @@
|
||||||
(defn on-navigate
|
(defn on-navigate
|
||||||
[route-id params query]
|
[route-id params query]
|
||||||
(if (can-access? route-id)
|
(if (can-access? route-id)
|
||||||
(re-frame/dispatch [::navigation route-id params query])
|
(re-frame/dispatch [:routes/navigation route-id params query])
|
||||||
(re-frame/dispatch [::unauthorized route-id params query])))
|
(re-frame/dispatch [:routes/unauthorized route-id params query])))
|
||||||
|
|
||||||
(defn start-routing!
|
(defn start-routing!
|
||||||
"Initializes the router and makes sure the correct events get dispatched."
|
"Initializes the router and makes sure the correct events get dispatched."
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue