Skip to content

Commit 51debe5

Browse files
committed
Allow composing messages while offline
1 parent 8a081df commit 51debe5

3 files changed

Lines changed: 33 additions & 18 deletions

File tree

apps/twig/src/renderer/features/message-editor/components/MessageEditor.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const MessageEditor = forwardRef<EditorHandle, MessageEditorProps>(
6161
const disabled = context?.disabled ?? false;
6262
const isLoading = context?.isLoading ?? false;
6363
const repoPath = context?.repoPath;
64-
const isDisabled = disabled || !isOnline;
64+
const isSubmitDisabled = disabled || !isOnline;
6565

6666
const {
6767
editor,
@@ -80,7 +80,8 @@ export const MessageEditor = forwardRef<EditorHandle, MessageEditorProps>(
8080
sessionId,
8181
taskId,
8282
placeholder,
83-
disabled: isDisabled,
83+
disabled,
84+
submitDisabled: !isOnline,
8485
isLoading,
8586
autoFocus,
8687
context: { taskId, repoPath },
@@ -157,7 +158,7 @@ export const MessageEditor = forwardRef<EditorHandle, MessageEditorProps>(
157158
<Flex justify="between" align="center">
158159
<Flex gap="2" align="center">
159160
<EditorToolbar
160-
disabled={isDisabled}
161+
disabled={disabled}
161162
taskId={taskId}
162163
onInsertChip={insertChip}
163164
onAttachFiles={onAttachFiles}
@@ -185,8 +186,8 @@ export const MessageEditor = forwardRef<EditorHandle, MessageEditorProps>(
185186
<Tooltip
186187
content={
187188
!isOnline
188-
? "You're offline"
189-
: isDisabled || isEmpty
189+
? "You're offline — send when reconnected"
190+
: isSubmitDisabled || isEmpty
190191
? "Enter a message"
191192
: "Send message"
192193
}
@@ -198,13 +199,17 @@ export const MessageEditor = forwardRef<EditorHandle, MessageEditorProps>(
198199
e.stopPropagation();
199200
submit();
200201
}}
201-
disabled={isDisabled || isEmpty}
202+
disabled={isSubmitDisabled || isEmpty}
202203
loading={isLoading}
203204
style={{
204205
backgroundColor:
205-
isDisabled || isEmpty ? "var(--accent-a4)" : undefined,
206+
isSubmitDisabled || isEmpty
207+
? "var(--accent-a4)"
208+
: undefined,
206209
color:
207-
isDisabled || isEmpty ? "var(--accent-8)" : undefined,
210+
isSubmitDisabled || isEmpty
211+
? "var(--accent-8)"
212+
: undefined,
208213
}}
209214
>
210215
<ArrowUp size={14} weight="bold" />

apps/twig/src/renderer/features/message-editor/tiptap/useTiptapEditor.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface UseTiptapEditorOptions {
1515
taskId?: string;
1616
placeholder?: string;
1717
disabled?: boolean;
18+
submitDisabled?: boolean;
1819
isLoading?: boolean;
1920
autoFocus?: boolean;
2021
context?: DraftContext;
@@ -41,6 +42,7 @@ export function useTiptapEditor(options: UseTiptapEditorOptions) {
4142
taskId,
4243
placeholder = "",
4344
disabled = false,
45+
submitDisabled = false,
4446
isLoading = false,
4547
autoFocus = false,
4648
context,
@@ -77,6 +79,9 @@ export function useTiptapEditor(options: UseTiptapEditorOptions) {
7779
onBlur,
7880
};
7981

82+
const submitDisabledRef = useRef(submitDisabled);
83+
submitDisabledRef.current = submitDisabled;
84+
8085
const prevBashModeRef = useRef(false);
8186
const prevIsEmptyRef = useRef(true);
8287
const submitRef = useRef<() => void>(() => {});
@@ -128,7 +133,7 @@ export function useTiptapEditor(options: UseTiptapEditorOptions) {
128133
: !event.shiftKey;
129134

130135
if (isSubmitKey) {
131-
if (!view.editable) return false;
136+
if (!view.editable || submitDisabledRef.current) return false;
132137
const suggestionPopup =
133138
document.querySelector("[data-tippy-root]");
134139
if (suggestionPopup) return false;
@@ -341,7 +346,7 @@ export function useTiptapEditor(options: UseTiptapEditorOptions) {
341346

342347
const submit = useCallback(() => {
343348
if (!editor) return;
344-
if (disabled) return;
349+
if (disabled || submitDisabled) return;
345350

346351
const content = draft.getContent();
347352
if (isContentEmpty(content)) return;
@@ -366,7 +371,7 @@ export function useTiptapEditor(options: UseTiptapEditorOptions) {
366371
prevBashModeRef.current = false;
367372
draft.clearDraft();
368373
}
369-
}, [editor, disabled, isLoading, draft, clearOnSubmit]);
374+
}, [editor, disabled, submitDisabled, isLoading, draft, clearOnSubmit]);
370375

371376
submitRef.current = submit;
372377

apps/twig/src/renderer/features/task-detail/components/TaskInputEditor.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const TaskInputEditor = forwardRef<
4040
ref,
4141
) => {
4242
const { isOnline } = useConnectivity();
43-
const isDisabled = isCreatingTask || !isOnline;
43+
const isSubmitDisabled = isCreatingTask || !isOnline;
4444

4545
const {
4646
editor,
@@ -55,7 +55,8 @@ export const TaskInputEditor = forwardRef<
5555
} = useTiptapEditor({
5656
sessionId,
5757
placeholder: "What do you want to work on? - @ to add context",
58-
disabled: isDisabled,
58+
disabled: isCreatingTask,
59+
submitDisabled: !isOnline,
5960
isLoading: isCreatingTask,
6061
autoFocus: true,
6162
context: { repoPath },
@@ -95,7 +96,7 @@ export const TaskInputEditor = forwardRef<
9596

9697
const getSubmitTooltip = () => {
9798
if (isCreatingTask) return "Creating task...";
98-
if (!isOnline) return "You're offline";
99+
if (!isOnline) return "You're offline — send when reconnected";
99100
if (isEmpty) return "Enter a task description";
100101
if (!hasDirectory) return "Select a folder first";
101102
if (!canSubmit) return "Missing required fields";
@@ -181,7 +182,7 @@ export const TaskInputEditor = forwardRef<
181182

182183
<Flex justify="between" align="center" px="3" pb="3">
183184
<EditorToolbar
184-
disabled={isDisabled}
185+
disabled={isCreatingTask}
185186
adapter={adapter}
186187
onInsertChip={insertChip}
187188
attachTooltip="Attach files from anywhere"
@@ -197,13 +198,17 @@ export const TaskInputEditor = forwardRef<
197198
e.stopPropagation();
198199
onSubmit();
199200
}}
200-
disabled={!canSubmit || isDisabled}
201+
disabled={!canSubmit || isSubmitDisabled}
201202
loading={isCreatingTask}
202203
style={{
203204
backgroundColor:
204-
!canSubmit || isDisabled ? "var(--accent-a4)" : undefined,
205+
!canSubmit || isSubmitDisabled
206+
? "var(--accent-a4)"
207+
: undefined,
205208
color:
206-
!canSubmit || isDisabled ? "var(--accent-8)" : undefined,
209+
!canSubmit || isSubmitDisabled
210+
? "var(--accent-8)"
211+
: undefined,
207212
}}
208213
>
209214
<ArrowUp size={16} weight="bold" />

0 commit comments

Comments
 (0)