1
0

commit.cljs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. (ns frontend.components.commit
  2. (:require [electron.ipc :as ipc]
  3. [frontend.mixins :as mixins]
  4. [frontend.state :as state]
  5. [frontend.util :as util]
  6. [frontend.util.cursor :as cursor]
  7. [goog.dom :as gdom]
  8. [goog.object :as gobj]
  9. [rum.core :as rum]))
  10. (defn commit-and-push!
  11. []
  12. (let [value (gobj/get (gdom/getElement "commit-message") "value")]
  13. (when (and value (>= (count value) 1))
  14. (when (util/electron?)
  15. (ipc/ipc "gitCommitAll" value))
  16. (state/close-modal!))))
  17. (rum/defcs add-commit-message <
  18. {:did-update (fn [state]
  19. (when-let [input (gdom/getElement "commit-message")]
  20. (.focus input)
  21. (cursor/move-cursor-to-end input))
  22. state)}
  23. (mixins/event-mixin
  24. (fn [state]
  25. (mixins/on-enter state
  26. :node (gdom/getElement "commit-message")
  27. :on-enter (fn []
  28. (commit-and-push!)))))
  29. [state _close-fn]
  30. [:div.w-full.mx-auto.sm:max-w-lg.sm:w-96 {:style {:padding "48px 0"}}
  31. [:div.sm:flex.sm:items-start
  32. [:div.mt-3.text-center.sm:mt-0.sm:text-left.mb-2
  33. [:h3#modal-headline.text-lg.leading-6.font-medium
  34. "Your commit message:"]]]
  35. [:input#commit-message.form-input.block.w-full.sm:text-sm.sm:leading-5.my-2
  36. {:auto-focus true
  37. :default-value ""}]
  38. [:div.mt-5.sm:mt-4.flex
  39. [:span.flex.w-full.rounded-md.shadow-sm
  40. [: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
  41. {:type "button"
  42. :on-click commit-and-push!}
  43. "Commit"]]]])
  44. (defn show-commit-modal! [e]
  45. (when (and
  46. (util/electron?)
  47. (not (util/input? (gobj/get e "target")))
  48. (not (gobj/get e "shiftKey"))
  49. (not (gobj/get e "ctrlKey"))
  50. (not (gobj/get e "altKey"))
  51. (not (gobj/get e "metaKey")))
  52. #_:clj-kondo/ignore
  53. (when-let [repo-url (state/get-current-repo)]
  54. (when-not (state/get-edit-input-id)
  55. (util/stop e)
  56. (state/set-modal! add-commit-message)))))