commit.cljs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. (ns frontend.components.commit
  2. (:require [rum.core :as rum]
  3. [frontend.util :as util :refer-macros [profile]]
  4. [frontend.handler.repo :as repo-handler]
  5. [frontend.state :as state]
  6. [frontend.mixins :as mixins]
  7. [frontend.handler.notification :as notification]
  8. [promesa.core :as p]
  9. [goog.dom :as gdom]
  10. [goog.object :as gobj]))
  11. (defn commit-and-push!
  12. []
  13. (let [value (gobj/get (gdom/getElement "commit-message") "value")]
  14. (when (and value (>= (count value) 1))
  15. (-> (repo-handler/git-commit-and-push! value)
  16. (p/catch (fn [error]
  17. (notification/show! error :error false))))
  18. (state/close-modal!))))
  19. (rum/defcs add-commit-message <
  20. {:did-update (fn [state]
  21. (when-let [input (gdom/getElement "commit-message")]
  22. (.focus input)
  23. (util/move-cursor-to-end input))
  24. state)}
  25. (mixins/event-mixin
  26. (fn [state]
  27. (mixins/on-enter state
  28. :node (gdom/getElement "commit-message")
  29. :on-enter (fn []
  30. (commit-and-push!)))))
  31. [state close-fn]
  32. (when-let [repo (state/sub :git/current-repo)]
  33. [:div
  34. [:div.sm:flex.sm:items-start
  35. [:div.mt-3.text-center.sm:mt-0.sm:text-left.mb-2
  36. [:h3#modal-headline.text-lg.leading-6.font-medium.text-gray-900
  37. "Your commit message:"]]]
  38. [:input#commit-message.form-input.block.w-full.sm:text-sm.sm:leading-5.my-2
  39. {:style {:color "#000"}
  40. :auto-focus true
  41. :default-value ""}]
  42. [:div.mt-5.sm:mt-4.sm:flex.sm:flex-row-reverse
  43. [:span.flex.w-full.rounded-md.shadow-sm.sm:ml-3.sm:w-auto
  44. [:button.inline-flex.justify-center.w-full.rounded-md.border.border-transparent.px-4.py-2.bg-indigo-600.text-base.leading-6.font-medium.text-white.shadow-sm.hover:bg-indigo-500.focus:outline-none.focus:border-indigo-700.focus:shadow-outline-indigo.transition.ease-in-out.duration-150.sm:text-sm.sm:leading-5
  45. {:type "button"
  46. :on-click commit-and-push!}
  47. "Commit and push!"]]
  48. [:span.mt-3.flex.w-full.rounded-md.shadow-sm.sm:mt-0.sm:w-auto
  49. [:button.inline-flex.justify-center.w-full.rounded-md.border.border-gray-300.px-4.py-2.bg-white.text-base.leading-6.font-medium.text-gray-700.shadow-sm.hover:text-gray-500.focus:outline-none.focus:border-blue-300.focus:shadow-outline-blue.transition.ease-in-out.duration-150.sm:text-sm.sm:leading-5
  50. {:type "button"
  51. :on-click close-fn}
  52. "Cancel"]]]]))