diff --git a/web/utils/tooltip-action-utils.js b/web/utils/tooltip-action-utils.js --- a/web/utils/tooltip-action-utils.js +++ b/web/utils/tooltip-action-utils.js @@ -305,37 +305,29 @@ onMouseLeave: ?() => mixed, }; -type CreateTooltipParams = { - +tooltipMessagePosition: ?PositionInfo, +type GetTooltipPositionStyleParams = { + +tooltipSourcePosition: ?PositionInfo, +tooltipSize: TooltipSize, +availablePositions: $ReadOnlyArray, - +containsInlineEngagement: boolean, - +tooltipActions: $ReadOnlyArray, - +messageTimestamp: string, - +item: ChatMessageInfoItem, - +threadInfo: ThreadInfo, + +preventDisplayingBelowSource?: boolean, }; -function createTooltip(params: CreateTooltipParams) { +function getTooltipPositionStyle(params: GetTooltipPositionStyleParams) { const { - tooltipMessagePosition, + tooltipSourcePosition, tooltipSize, availablePositions, - containsInlineEngagement, - tooltipActions, - messageTimestamp, - item, - threadInfo, + preventDisplayingBelowSource, } = params; - if (!tooltipMessagePosition) { + if (!tooltipSourcePosition) { return undefined; } const tooltipPosition = findTooltipPosition({ - sourcePositionInfo: tooltipMessagePosition, + sourcePositionInfo: tooltipSourcePosition, tooltipSize, availablePositions, defaultPosition: availablePositions[0], - preventDisplayingBelowSource: containsInlineEngagement, + preventDisplayingBelowSource, }); if (!tooltipPosition) { return undefined; @@ -343,21 +335,11 @@ const tooltipPositionStyle = getTooltipStyle({ tooltipPosition, - sourcePositionInfo: tooltipMessagePosition, + sourcePositionInfo: tooltipSourcePosition, tooltipSize, }); - const tooltip = ( - - ); - return { tooltip, tooltipPositionStyle }; + return tooltipPositionStyle; } function useMessageTooltip({ @@ -404,21 +386,27 @@ const messagePosition = { top, bottom, left, right, height, width }; setTooltipMessagePosition(messagePosition); - const tooltipResult = createTooltip({ - tooltipMessagePosition: messagePosition, + const tooltipPositionStyle = getTooltipPositionStyle({ + tooltipSourcePosition: messagePosition, tooltipSize, availablePositions, - containsInlineEngagement, - tooltipActions, - messageTimestamp, - item, - threadInfo, + preventDisplayingBelowSource: containsInlineEngagement, }); - if (!tooltipResult) { + + if (!tooltipPositionStyle) { return; } - const { tooltip, tooltipPositionStyle } = tooltipResult; + const tooltip = ( + + ); const renderTooltipResult = renderTooltip({ newNode: tooltip, tooltipPositionStyle, @@ -446,21 +434,28 @@ return; } - const tooltipResult = createTooltip({ - tooltipMessagePosition, + const tooltipPositionStyle = getTooltipPositionStyle({ + tooltipSourcePosition: tooltipMessagePosition, tooltipSize, availablePositions, - containsInlineEngagement, - tooltipActions, - messageTimestamp, - item, - threadInfo, + preventDisplayingBelowSource: containsInlineEngagement, }); - if (!tooltipResult) { + if (!tooltipPositionStyle) { return; } - updateTooltip.current?.(tooltipResult.tooltip); + const tooltip = ( + + ); + + updateTooltip.current?.(tooltip); }, [ availablePositions, containsInlineEngagement,