blob: dec087b724ce6410f2486acecc37372ca00323b1 (
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
(ns tau.events
(:require
[re-frame.core :as rf]
[tau.api :as api]))
(rf/reg-event-db
:initialize-db
(fn [_ _]
{:global-search ""
:service-id 0
:stream {}
:search-results []
:services []
:current-match nil}))
(rf/reg-event-db
:navigated
(fn [db [_ new-match]]
(assoc db :current-match new-match)))
(rf/reg-event-db
:bad-response
(fn [db [_ res]]
(assoc db :http-response (get-in res [:response :error]))))
(rf/reg-event-db
:change-global-search
(fn [db [_ res]]
(assoc db :global-search res)))
(rf/reg-event-db
:change-service-id
(fn [db [_ res]]
(assoc db :service-id res)))
(rf/reg-event-fx
:switch-to-global-player
(fn [{:keys [db]} [_ res]]
{:db (assoc db :show-global-player true)
:dispatch [:change-global-search res]}))
(rf/reg-event-db
:load-services
(fn [db [_ res]]
(assoc db :services (js->clj res :keywordize-keys true)
:show-loading false)))
(rf/reg-event-fx
:get-services
(fn [{:keys [db]} _]
(assoc
(api/get-request "/api/services" [:load-services] [:bad-response])
:db (assoc db :show-loading true))))
(rf/reg-event-db
:load-stream
(fn [db [_ res]]
(assoc db :stream (js->clj res :keywordize-keys true)
:show-loading false)))
(rf/reg-event-fx
:get-stream
(fn [{:keys [db]} [_ uri]]
(assoc
(api/get-request "/api/stream" [:load-stream] [:bad-response] {:url uri})
:db (assoc db :show-loading true))))
(rf/reg-event-db
:load-search-results
(fn [db [_ res]]
(assoc db :search-results (js->clj res :keywordize-keys true)
:show-loading false)))
(rf/reg-event-fx
:get-search-results
(fn [{:keys [db]} [_ {:keys [id query]}]]
(assoc
(api/get-request "/api/search"
[:load-search-results] [:bad-response]
{:serviceId id :q query})
:db (assoc db :show-loading true))))
|