import * as React from 'react'; import { TaskTooltip } from '@renderer/components/team/TaskTooltip'; import { useStore } from '@renderer/store'; import { calculateInlineMatchPositions } from '@renderer/utils/chipUtils'; import { findTaskReferenceMatches } from '@renderer/utils/taskReferenceUtils'; import type { MentionSuggestion } from '@renderer/types/mention'; import type { InlineMatchPosition } from '@renderer/utils/chipUtils'; interface TaskReferenceInteractionLayerProps { taskSuggestions: MentionSuggestion[]; value: string; textareaRef: React.RefObject; scrollTop: number; } type PositionedTaskReference = InlineMatchPosition; export const TaskReferenceInteractionLayer = ({ taskSuggestions, value, textareaRef, scrollTop, }: TaskReferenceInteractionLayerProps): React.JSX.Element | null => { const [positions, setPositions] = React.useState([]); const openGlobalTaskDetail = useStore((s) => s.openGlobalTaskDetail); React.useLayoutEffect(() => { if (taskSuggestions.length === 0 || !value.includes('#')) { setPositions([]); return; } const textarea = textareaRef.current; if (!textarea) return; const matches = findTaskReferenceMatches(value, taskSuggestions).map((match) => ({ item: match.suggestion, start: match.start, end: match.end, token: match.raw, })); setPositions(calculateInlineMatchPositions(textarea, value, matches)); }, [taskSuggestions, textareaRef, value]); if (positions.length === 0) return null; return (
{positions.map((position, index) => { const suggestion = position.item; const taskId = suggestion.taskId; const teamName = suggestion.teamName; if (!taskId) return null; return (
); };