footer.cljs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. (ns frontend.mobile.footer
  2. (:require [frontend.ui :as ui]
  3. [rum.core :as rum]
  4. [frontend.state :as state]
  5. [frontend.mobile.record :as record]
  6. [frontend.util :as util]
  7. [frontend.handler.editor :as editor-handler]
  8. [clojure.string :as string]
  9. [frontend.date :as date]))
  10. (rum/defc mobile-bar-command [command-handler icon]
  11. [:div
  12. [:button.bottom-action
  13. {:on-mouse-down (fn [e]
  14. (util/stop e)
  15. (command-handler))}
  16. (ui/icon icon {:style {:fontSize ui/icon-size}})]])
  17. (defn seconds->minutes:seconds
  18. [seconds]
  19. (let [minutes (quot seconds 60)
  20. seconds (mod seconds 60)]
  21. (util/format "%02d:%02d" minutes seconds)))
  22. (def *record-start (atom -1))
  23. (rum/defcs audio-record-cp < rum/reactive
  24. {:did-mount (fn [state]
  25. (let [comp (:rum/react-component state)
  26. callback #(rum/request-render comp)
  27. interval (js/setInterval callback 1000)]
  28. (assoc state ::interval interval)))
  29. :will-mount (fn [state]
  30. (js/clearInterval (::interval state))
  31. (dissoc state ::interval))}
  32. [state]
  33. (when (= (state/sub :editor/record-status) "RECORDING")
  34. (swap! *record-start inc))
  35. [:div.flex.flex-row
  36. (if (= (state/sub :editor/record-status) "NONE")
  37. (do
  38. (reset! *record-start -1)
  39. (mobile-bar-command #(record/start-recording) "microphone"))
  40. [:div.flex.flex-row
  41. (mobile-bar-command #(record/stop-recording) "player-stop")
  42. [:div.timer.pl-2 (seconds->minutes:seconds @*record-start)]])])
  43. (rum/defc footer < rum/reactive
  44. []
  45. (when-not (or (state/sub :editor/editing?)
  46. (state/sub :block/component-editing-mode?)
  47. (state/sub :editor/editing-page-title?))
  48. [:div.cp__footer.w-full.bottom-0.justify-between
  49. (audio-record-cp)
  50. (mobile-bar-command #(state/toggle-document-mode!) "notes")
  51. (mobile-bar-command
  52. #(let [page (or (state/get-current-page)
  53. (string/lower-case (date/journal-name)))
  54. block (editor-handler/api-insert-new-block!
  55. ""
  56. {:page page
  57. :replace-empty-target? true})]
  58. (js/setTimeout
  59. (fn [] (editor-handler/edit-block!
  60. block
  61. :max
  62. (:block/uuid block))) 100))
  63. "edit")]))