Skip to content

Commit 1e5eeb6

Browse files
authored
fix: task creation (#152)
creating a task fails the second time when hitting enter, this fixes it, very odd
1 parent c9df526 commit 1e5eeb6

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/renderer/features/task-detail/hooks/useEditorSetup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function useEditorSetup({
5757
name: "submitOnEnter",
5858
addKeyboardShortcuts() {
5959
return {
60-
Enter: () => {
60+
"Mod-Enter": () => {
6161
if (!this.editor.state.selection.$from.parent.textContent) {
6262
return false;
6363
}

src/renderer/features/task-detail/hooks/useTaskCreation.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,23 @@ export function useTaskCreation({
4848

4949
const canSubmit =
5050
!!editor &&
51-
!!isAuthenticated &&
51+
isAuthenticated &&
5252
!!client &&
5353
!!selectedDirectory &&
5454
!isCreatingTask &&
5555
!editor.isEmpty;
5656

5757
const handleSubmit = useCallback(() => {
58-
if (!canSubmit || !editor) {
58+
// TRICKY: This needs to be redefined in the callback due to a weird issue where the callback uses a stale version of canSubmit, even if its a dependency
59+
const canSubmit =
60+
!!editor &&
61+
isAuthenticated &&
62+
!!client &&
63+
!!selectedDirectory &&
64+
!isCreatingTask &&
65+
!editor.isEmpty;
66+
67+
if (!canSubmit) {
5968
return;
6069
}
6170

@@ -102,7 +111,6 @@ export function useTaskCreation({
102111
},
103112
);
104113
}, [
105-
canSubmit,
106114
editor,
107115
selectedDirectory,
108116
detectedRepo,
@@ -115,6 +123,9 @@ export function useTaskCreation({
115123
setRunMode,
116124
runTask,
117125
clearDraft,
126+
isCreatingTask,
127+
client,
128+
isAuthenticated,
118129
]);
119130

120131
return {

0 commit comments

Comments
 (0)