Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(comments): pending send signal to disallow dupe comment send (#3679)

Seamusb7f283dc89eb
diff --git a/js/app/packages/block-md/component/DiscussionInput.tsx b/js/app/packages/block-md/component/DiscussionInput.tsx
index 4262a3be39..2a4ed98ee6 100644
--- a/js/app/packages/block-md/component/DiscussionInput.tsx
+++ b/js/app/packages/block-md/component/DiscussionInput.tsx
@@ -76,7 +76,7 @@ function AttachImagesAction() {
);
}
-function DefaultActions(props: { input: InputData }) {
+function DefaultActions(props: { input: InputData; isSending: boolean }) {
return (
<Input.Actions>
<Input.Actions.Left>
@@ -87,7 +87,7 @@ function DefaultActions(props: { input: InputData }) {
</Show>
</Input.Actions.Left>
<Input.Actions.Right>
- <Input.SendAction tooltip="Send comment" />
+ <Input.SendAction tooltip="Send comment" disabled={props.isSending} />
</Input.Actions.Right>
</Input.Actions>
);
@@ -98,6 +98,7 @@ export function DiscussionInput(props: DiscussionInputProps) {
const [value, setValue] = createSignal(props.input.value ?? '');
const [mentions, setMentions] = createSignal<ItemMention[]>([]);
const [showFormatRibbon, setShowFormatRibbon] = createSignal(false);
+ const [isSending, setIsSending] = createSignal(false);
const inputView = () => ({
...props.input,
@@ -146,10 +147,16 @@ export function DiscussionInput(props: DiscussionInputProps) {
const commands = {
send: async () => {
+ if (isSending()) return false;
const snapshot = createSnapshot();
if (!snapshot.value.trim()) return false;
- await props.onSend?.(snapshot);
- return true;
+ setIsSending(true);
+ try {
+ await props.onSend?.(snapshot);
+ return true;
+ } finally {
+ setIsSending(false);
+ }
},
close: () => {
props.onClose?.(createSnapshot());
@@ -235,7 +242,7 @@ export function DiscussionInput(props: DiscussionInputProps) {
<Switch>
<Match when={props.children}>{props.children}</Match>
<Match when>
- <DefaultActions input={inputView()} />
+ <DefaultActions input={inputView()} isSending={isSending()} />
</Match>
</Switch>
</Input.Footer>
diff --git a/js/app/packages/channel/Input/SendAction.tsx b/js/app/packages/channel/Input/SendAction.tsx
index fe8caae298..7c5d948588 100644
--- a/js/app/packages/channel/Input/SendAction.tsx
+++ b/js/app/packages/channel/Input/SendAction.tsx
@@ -12,9 +12,16 @@ export type SendActionProps = JSX.ButtonHTMLAttributes<HTMLButtonElement> & {
export function SendAction(props: SendActionProps) {
const input = useInput();
const commands = useInputCommands();
- const [local, rest] = splitProps(props, ['class', 'tooltip', 'hidden']);
+ const [local, rest] = splitProps(props, [
+ 'class',
+ 'disabled',
+ 'tooltip',
+ 'hidden',
+ ]);
const isBlockedByPending = () => !!input().hasPendingAttachments;
const isBlockedByEmptyInput = () => !hasSendableInputContent(input());
+ const isDisabled = () =>
+ !!local.disabled || isBlockedByPending() || isBlockedByEmptyInput();
const tooltipText = () => local.tooltip ?? 'Send message';
@@ -25,7 +32,7 @@ export function SendAction(props: SendActionProps) {
aria-label={tooltipText()}
data-input-action="send"
pending={isBlockedByPending()}
- disabled={isBlockedByPending() || isBlockedByEmptyInput()}
+ disabled={isDisabled()}
hidden={isMobile() && isBlockedByEmptyInput()}
class={local.class}
onPointerDown={(event) => {
diff --git a/js/app/packages/core/comments/Comment.tsx b/js/app/packages/core/comments/Comment.tsx
index 61149b51ad..918f0d663b 100644
--- a/js/app/packages/core/comments/Comment.tsx
+++ b/js/app/packages/core/comments/Comment.tsx
@@ -167,7 +167,7 @@ export function Comment(
if (newText.trim() === '') return;
setIsEditing(false);
setTextValue(newText);
- Promise.all([
+ return Promise.all([
commentOperations.updateComment(props.comment.id, {
text: newText,
threadId: props.comment.threadId,
@@ -193,7 +193,7 @@ export function CommentReply(
replyId: number;
threadId: number;
deleteReply: () => void;
- updateReply: (content: string) => void;
+ updateReply: (content: string) => unknown | Promise<unknown>;
isOwned: boolean;
isActive: boolean;
isThreaded?: boolean;
@@ -283,9 +283,10 @@ export function CommentReply(
}}
onSend={(newText: string) => {
if (newText.trim() === '') return;
- props.updateReply(newText);
+ const result = props.updateReply(newText);
setIsEditing(false);
setTextValue(newText);
+ return result;
}}
hidePadding
isReply
diff --git a/js/app/packages/core/comments/Inputs.tsx b/js/app/packages/core/comments/Inputs.tsx
index f5e102fde6..d33f1774e9 100644
--- a/js/app/packages/core/comments/Inputs.tsx
+++ b/js/app/packages/core/comments/Inputs.tsx
@@ -11,6 +11,7 @@ function EditBottomRow(props: {
handleSend: () => void;
hideHorizontalPadding?: boolean;
hasContent?: boolean;
+ isSending?: boolean;
}) {
return (
<div class="absolute bottom-1 right-1 flex items-center">
@@ -29,7 +30,7 @@ function EditBottomRow(props: {
size="icon-sm"
class="rounded-xs"
variant="ghost"
- disabled={!props.hasContent}
+ disabled={!props.hasContent || props.isSending}
on:click={props.handleSend}
>
<PaperPlaneRight class={cn({ 'text-accent': props.hasContent })} />
@@ -40,7 +41,7 @@ function EditBottomRow(props: {
export function EditInput(props: {
handleCancel: () => void;
- onSend: (newText: string) => void;
+ onSend: (newText: string) => unknown | Promise<unknown>;
hidePadding?: boolean;
isNewReply?: boolean;
isNewThread?: boolean;
@@ -49,6 +50,7 @@ export function EditInput(props: {
textValue: string;
}) {
const [editState, setEditState] = createSignal('');
+ const [isSending, setIsSending] = createSignal(false);
const { setActiveThread } = useContext(CommentsContext);
const { mentionsSignal } = useContext(ThreadContext);
const [, setMentions] = mentionsSignal;
@@ -69,8 +71,17 @@ export function EditInput(props: {
});
};
- const handleSend = () => {
- props.onSend(editState());
+ const handleSend = async () => {
+ if (isSending()) return;
+ const text = editState();
+ if (text.trim().length === 0) return;
+
+ setIsSending(true);
+ try {
+ await props.onSend(text);
+ } finally {
+ setIsSending(false);
+ }
};
const onRemoveMention = (itemMention: ItemMention) => {
@@ -98,7 +109,7 @@ export function EditInput(props: {
initialValue={props.textValue}
type="markdown"
onEnter={() => {
- handleSend();
+ void handleSend();
return true;
}}
placeholder="Add a comment..."
@@ -116,6 +127,7 @@ export function EditInput(props: {
handleSend={handleSend}
hideHorizontalPadding={props.hidePadding}
hasContent={editState().trim().length > 0}
+ isSending={isSending()}
/>
</div>
</div>
@@ -123,7 +135,7 @@ export function EditInput(props: {
}
export function NewReplyInput(props: {
- createReply: (message: string) => void;
+ createReply: (message: string) => unknown | Promise<unknown>;
isEditing: boolean;
setEditing: (newVal: boolean) => void;
setTextValue: (newVal: string) => void;
@@ -150,8 +162,9 @@ export function NewReplyInput(props: {
textValue={props.textValue}
handleCancel={() => props.setTextValue('')}
onSend={(message) => {
- props.createReply(message);
+ const result = props.createReply(message);
props.setTextValue('');
+ return result;
}}
isNewReply
isReply
diff --git a/js/app/packages/core/comments/Thread.tsx b/js/app/packages/core/comments/Thread.tsx
index e420b3bfa4..4f1e516271 100644
--- a/js/app/packages/core/comments/Thread.tsx
+++ b/js/app/packages/core/comments/Thread.tsx
@@ -221,7 +221,7 @@ export function Thread(props: {
onSend={(content: string) => {
if (content.trim() === '') return;
// NOTE: we need the server to return the thread id first
- commentOperations.createComment({
+ return commentOperations.createComment({
threadId: props.comment.threadId,
text: content,
mentions: getAndClearCommentMentions(mentionsSignal),
@@ -277,7 +277,7 @@ export function Thread(props: {
})
}
updateReply={(content) => {
- Promise.all([
+ return Promise.all([
commentOperations.updateComment(replyId, {
text: content,
threadId: props.comment.threadId,
@@ -299,7 +299,7 @@ export function Thread(props: {
createReply={(content) => {
if (content.trim() === '') return;
dispatch({ action: 'hard', editing: false });
- commentOperations.createComment({
+ return commentOperations.createComment({
threadId: props.comment.threadId,
text: content,
mentions: getAndClearCommentMentions(mentionsSignal),