Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { useAiCompletion } from 'state/api/ai';
import { generateCommentPrompt } from 'state/api/ai/prompts';
import useGetCommunityByIdQuery from 'state/api/communities/getCommuityById';
import { useAIFeatureEnabled, useUserAiSettingsStore } from 'state/ui/user';
import { useTurnstile } from 'views/components/useTurnstile';
import { User } from 'views/components/user/user';
import { jumpHighlightComment } from 'views/pages/discussions/CommentTree/helpers';
import { ImageActionModal } from '../../ImageActionModal/ImageActionModal';
Expand Down Expand Up @@ -53,6 +52,10 @@ export type CommentEditorProps = {
webSearchEnabled?: boolean;
setWebSearchEnabled?: (enabled: boolean) => void;
communityId?: string;
isTurnstileEnabled?: boolean;
turnstileToken?: string | null;
resetTurnstile?: () => void;
TurnstileWidget?: React.FC;
};

// eslint-disable-next-line react/display-name
Expand Down Expand Up @@ -81,6 +84,10 @@ const CommentEditor = forwardRef<unknown, CommentEditorProps>(
webSearchEnabled,
setWebSearchEnabled,
communityId,
isTurnstileEnabled = false,
turnstileToken,
resetTurnstile,
TurnstileWidget,
},
_ref,
) => {
Expand All @@ -102,15 +109,6 @@ const CommentEditor = forwardRef<unknown, CommentEditorProps>(

const { generateCompletion } = useAiCompletion();

const {
resetTurnstile,
turnstileToken,
isTurnstileEnabled,
TurnstileWidget,
} = useTurnstile({
action: 'create-comment',
});

// Fetch community details
const { data: community } = useGetCommunityByIdQuery({
id: thread?.communityId || '',
Expand Down Expand Up @@ -162,6 +160,7 @@ ${parentCommentText ? `Parent Comment: ${parentCommentText}` : ''}`;
});
};

const TurnstileWidgetComponent = TurnstileWidget ?? (() => <></>);
const handleEnhancedSubmit = async () => {
// Immediately close the editor before any operations
onCancel?.(
Expand All @@ -182,7 +181,7 @@ ${parentCommentText ? `Parent Comment: ${parentCommentText}` : ''}`;
} catch (error) {
console.error('Failed to submit comment:', error);
if (isTurnstileEnabled) {
resetTurnstile();
resetTurnstile?.();
}
return;
}
Expand Down Expand Up @@ -236,7 +235,7 @@ ${parentCommentText ? `Parent Comment: ${parentCommentText}` : ''}`;
} catch (error) {
console.error('Error during submission:', error);
if (isTurnstileEnabled) {
resetTurnstile();
resetTurnstile?.();
}
}
};
Expand Down Expand Up @@ -316,7 +315,7 @@ ${parentCommentText ? `Parent Comment: ${parentCommentText}` : ''}`;
placeholder={placeholder}
/>

{isTurnstileEnabled && <TurnstileWidget />}
{isTurnstileEnabled && <TurnstileWidgetComponent />}

<div className="form-bottom">
<div className="form-buttons">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,10 @@ const StickyInput = (props: StickyInputProps) => {
webSearchEnabled={webSearchEnabled}
setWebSearchEnabled={setWebSearchEnabled}
communityId={props.communityId}
isTurnstileEnabled={isTurnstileEnabled}
turnstileToken={turnstileToken}
resetTurnstile={resetTurnstile}
TurnstileWidget={TurnstileWidget}
/>
)}
</div>
Expand Down
Loading