|
13 | 13 | [status-im.utils.utils :as utils]
|
14 | 14 | [taoensso.timbre :as log]
|
15 | 15 | [quo2.foundations.colors :as colors]
|
16 |
| - [quo2.core :as quo])) |
| 16 | + [quo2.core :as quo] |
| 17 | + [react-native.core :as rn])) |
17 | 18 |
|
18 | 19 | (defonce player-ref (atom nil))
|
19 | 20 | (defonce current-player-message-id (atom nil))
|
|
101 | 102 |
|
102 | 103 | (defn download-audio-http
|
103 | 104 | [base64-uri on-success]
|
| 105 | + (println base64-uri) |
104 | 106 | (-> (.config ReactNativeBlobUtil (clj->js {:trusty platform/ios?}))
|
105 | 107 | (.fetch "GET" (str base64-uri))
|
106 | 108 | (.then #(on-success (.base64 ^js %)))
|
107 |
| - (.catch #(log/error "could not fetch audio")))) |
| 109 | + (.catch #(println "could not fetch audio" %)))) |
108 | 110 |
|
109 | 111 | (defn reload-player
|
110 | 112 | [{:keys [message-id state-ref] :as params} audio-url on-success]
|
|
154 | 156 | (when @player-ref
|
155 | 157 | (audio/toggle-playpause-player
|
156 | 158 | @player-ref
|
157 |
| - #(do |
158 |
| - (update-state params)) |
159 |
| - #(do |
160 |
| - (update-state params)) |
| 159 | + #(update-state params) |
| 160 | + #(update-state params) |
161 | 161 | #(update-state (merge params {:error (:message %)}))))))
|
162 | 162 |
|
163 | 163 | (defn- play-pause-button
|
|
174 | 174 | :accessibility-label :play-pause-audio-message-button
|
175 | 175 | :color colors/white}]])
|
176 | 176 |
|
177 |
| -(defview message-content |
| 177 | +(defn message-content |
178 | 178 | [{:keys [audio audio-duration-ms message-id]}]
|
179 |
| - (letsubs [state (reagent/atom nil) |
180 |
| - progress (reagent/atom 0) |
181 |
| - seeking-audio? (reagent/atom false)] |
182 |
| - {:component-did-mount (fn [] |
183 |
| - (update-state {:state-ref state |
184 |
| - :audio-duration-ms audio-duration-ms |
185 |
| - :message-id message-id |
186 |
| - :unloaded? true |
187 |
| - :progress-ref progress})) |
188 |
| - :component-will-unmount (fn [] |
189 |
| - (destroy-player {:state-ref state :message-id message-id}) |
190 |
| - (when (= @current-player-message-id message-id) |
191 |
| - (reset! current-active-state-ref-ref nil) |
192 |
| - (reset! current-player-message-id nil)) |
193 |
| - (reset! state nil))} |
194 |
| - |
195 |
| - (let [base-params {:state-ref state |
196 |
| - :message-id message-id |
197 |
| - :progress-ref progress}] |
198 |
| - (if (= (:general @state) :error) |
199 |
| - [react/text |
200 |
| - {:style {:typography :main-medium |
201 |
| - :margin-bottom 16}} (:error-msg @state)] |
202 |
| - [react/view {:style (style/container)} |
203 |
| - [play-pause-button state #(play-pause base-params audio seeking-audio?)] |
204 |
| - [quo/soundtrack |
205 |
| - {:style style/slider-container |
206 |
| - :audio-current-time-ms progress |
207 |
| - :player-ref player-ref |
208 |
| - :seeking-audio? seeking-audio?}] |
209 |
| - [quo/text |
210 |
| - {:style style/timestamp |
211 |
| - :accessibility-label :audio-duration-label |
212 |
| - :weight :medium |
213 |
| - :size :paragraph-2} |
214 |
| - (let [duration-ms (:duration @state) |
215 |
| - duration-secs (quot duration-ms 1000)] |
216 |
| - (gstring/format "%02d:%02d" (quot duration-secs 60) (mod duration-secs 60)))]])))) |
| 179 | + [:f> |
| 180 | + (fn [] |
| 181 | + (let [state (reagent/atom nil) |
| 182 | + progress (reagent/atom 0) |
| 183 | + seeking-audio? (reagent/atom false) |
| 184 | + base-params {:state-ref state |
| 185 | + :message-id message-id |
| 186 | + :progress-ref progress} |
| 187 | + time-ms (if (#{:playing :paused :seeking} (:general @state)) |
| 188 | + @progress |
| 189 | + (:duration @state)) |
| 190 | + time-secs (quot time-ms 1000)] |
| 191 | + (rn/use-effect |
| 192 | + (fn [] |
| 193 | + (update-state {:state-ref state |
| 194 | + :audio-duration-ms audio-duration-ms |
| 195 | + :message-id message-id |
| 196 | + :unloaded? true |
| 197 | + :progress-ref progress}))) |
| 198 | + (if (= (:general @state) :error) |
| 199 | + [react/text |
| 200 | + {:style {:typography :main-medium |
| 201 | + :margin-bottom 16}} (:error-msg @state)] |
| 202 | + [react/view {:style (style/container)} |
| 203 | + [play-pause-button state #(play-pause base-params audio seeking-audio?)] |
| 204 | + [quo/soundtrack |
| 205 | + {:style style/slider-container |
| 206 | + :audio-current-time-ms progress |
| 207 | + :player-ref player-ref |
| 208 | + :seeking-audio? seeking-audio?}] |
| 209 | + [quo/text |
| 210 | + {:style style/timestamp |
| 211 | + :accessibility-label :audio-duration-label |
| 212 | + :weight :medium |
| 213 | + :size :paragraph-2} |
| 214 | + (gstring/format "%02d:%02d" (quot time-secs 60) (mod time-secs 60))]])))]) |
0 commit comments