1
0

commit.cljs 2.9 KB

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