11"use client" ;
22
3- import { FC } from "react" ;
3+ import { FC , useRef } from "react" ;
44
55import { useCommentsFeed } from "@/app/(main)/components/comments_feed_provider" ;
66import { ImpactMetadata , KeyFactor } from "@/types/comment" ;
@@ -10,6 +10,7 @@ import { getImpactDirectionFromMetadata } from "@/utils/key_factors";
1010import KeyFactorBaseRate from "./base_rate/key_factor_base_rate" ;
1111import KeyFactorDriver from "./driver/key_factor_driver" ;
1212import KeyFactorCardContainer from "./key_factor_card_container" ;
13+ import { ImpactVoteHandler } from "./key_factor_strength_item" ;
1314import KeyFactorVotePanels , {
1415 useKeyFactorVotePanels ,
1516} from "./key_factor_vote_panels" ;
@@ -62,8 +63,11 @@ export const KeyFactorItem: FC<Props> = ({
6263 handleUpvotePanelToggle,
6364 handleDownvotePanelToggle,
6465 handleMorePanelToggle,
66+ closeAllPanels,
6567 } = useKeyFactorVotePanels ( ) ;
6668
69+ const impactVoteRef = useRef < ImpactVoteHandler | null > ( null ) ;
70+
6771 return (
6872 < div ref = { impactPanel . anchorRef } className = "self-start" >
6973 < KeyFactorCardContainer
@@ -72,7 +76,10 @@ export const KeyFactorItem: FC<Props> = ({
7276 linkToComment = { linkToComment }
7377 isCompact = { isCompact }
7478 mode = { mode }
75- onClick = { onClick }
79+ onClick = { ( ) => {
80+ closeAllPanels ( ) ;
81+ onClick ?.( ) ;
82+ } }
7683 className = { className }
7784 impactDirection = { impactDirection }
7885 impactStrength = { impactStrength }
@@ -82,6 +89,7 @@ export const KeyFactorItem: FC<Props> = ({
8289 keyFactor = { liveKeyFactor }
8390 mode = { mode }
8491 isCompact = { isCompact }
92+ impactVoteRef = { impactVoteRef }
8593 onVotePanelToggle = { handleUpvotePanelToggle }
8694 onDownvotePanelToggle = { handleDownvotePanelToggle }
8795 onMorePanelToggle = { handleMorePanelToggle }
@@ -94,6 +102,7 @@ export const KeyFactorItem: FC<Props> = ({
94102 isCompact = { isCompact }
95103 mode = { mode }
96104 isSuggested = { isSuggested }
105+ impactVoteRef = { impactVoteRef }
97106 onVotePanelToggle = { handleUpvotePanelToggle }
98107 onDownvotePanelToggle = { handleDownvotePanelToggle }
99108 onMorePanelToggle = { handleMorePanelToggle }
@@ -105,6 +114,7 @@ export const KeyFactorItem: FC<Props> = ({
105114 keyFactor = { liveKeyFactor }
106115 mode = { mode }
107116 isCompact = { isCompact }
117+ impactVoteRef = { impactVoteRef }
108118 onVotePanelToggle = { handleUpvotePanelToggle }
109119 onDownvotePanelToggle = { handleDownvotePanelToggle }
110120 onMorePanelToggle = { handleMorePanelToggle }
@@ -122,6 +132,7 @@ export const KeyFactorItem: FC<Props> = ({
122132 inline = { inlineVotePanels }
123133 keyFactor = { liveKeyFactor }
124134 projectPermission = { projectPermission }
135+ onImpactSelect = { ( option ) => impactVoteRef . current ?.( option ) }
125136 />
126137 </ div >
127138 ) ;
0 commit comments