state.cljs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. (ns mobile.state
  2. "Mobile state"
  3. (:require [clojure.string :as string]
  4. [frontend.rum :as r]))
  5. (defonce *tab (atom "home"))
  6. (defn set-tab! [tab] (reset! *tab tab))
  7. (defn use-tab [] (r/use-atom *tab))
  8. (defonce *modal-blocks (atom []))
  9. (defonce *blocks-navigation-history (atom []))
  10. (defn open-block-modal!
  11. [block]
  12. (when (:db/id block)
  13. (reset! *modal-blocks [block])
  14. (when-not (= (:db/id block) (:db/id (last @*blocks-navigation-history)))
  15. (swap! *blocks-navigation-history conj block))))
  16. (defn close-block-modal!
  17. "Close top block sheet"
  18. []
  19. (reset! *modal-blocks [])
  20. (reset! *blocks-navigation-history []))
  21. (defn pop-navigation-history!
  22. []
  23. (when (seq @*blocks-navigation-history)
  24. (let [stack (swap! *blocks-navigation-history pop)]
  25. (when (seq stack)
  26. (reset! *modal-blocks [(last stack)])))))
  27. (defonce *popup-data (atom nil))
  28. (defn set-popup!
  29. [data]
  30. (reset! *popup-data data))
  31. (defonce *left-sidebar-open? (atom false))
  32. (defn open-left-sidebar!
  33. []
  34. (reset! *left-sidebar-open? true))
  35. (defn close-left-sidebar!
  36. []
  37. (reset! *left-sidebar-open? false))
  38. (defn left-sidebar-open?
  39. []
  40. @*left-sidebar-open?)
  41. (defn redirect-to-tab! [name]
  42. (set-tab! (str name)))
  43. (defonce *log (atom []))
  44. (defn log-append!
  45. [record]
  46. (swap! *log conj record))
  47. (defn log->str
  48. []
  49. (->> @*log
  50. (string/join "\n\n")))