@@ -7,12 +7,15 @@ import { useCommentsFeed } from "@/app/(main)/components/comments_feed_provider"
77import { openKeyFactorsSectionAndScrollTo } from "@/app/(main)/questions/[id]/components/key_factors/utils" ;
88import { PostStatus , PostWithForecasts } from "@/types/post" ;
99import { sendAnalyticsEvent } from "@/utils/analytics" ;
10+ import { getQuestionForecastAvailability } from "@/utils/questions/forecastAvailability" ;
11+ import { isQuestionPost } from "@/utils/questions/helpers" ;
1012
1113import {
1214 MAX_TOP_KEY_FACTORS ,
1315 useTopKeyFactorsCarouselItems ,
1416} from "./hooks/use_top_key_factors_carousel_items" ;
1517import KeyFactorDetailOverlay from "./key_factor_detail_overlay" ;
18+ import KeyFactorsCarousel from "./key_factors_carousel" ;
1619import KeyFactorsConsumerCarousel from "./key_factors_consumer_carousel" ;
1720import { useShouldHideKeyFactors } from "./use_should_hide_key_factors" ;
1821import { useQuestionLayout } from "../question_layout/question_layout_context" ;
@@ -41,14 +44,21 @@ const KeyFactorsQuestionConsumerSection: FC<Props> = ({ post }) => {
4144
4245 if ( post . status === PostStatus . RESOLVED ) return null ;
4346
47+ const postForecastAvailability = isQuestionPost ( post )
48+ ? getQuestionForecastAvailability ( post . question )
49+ : null ;
50+ const forecastIsEmpty =
51+ ! ! postForecastAvailability ?. isEmpty &&
52+ ! postForecastAvailability ?. cpRevealsOn ;
53+
54+ if ( topItems . length === 0 && ! forecastIsEmpty ) return null ;
55+
4456 const openKeyFactorsElement = ( selector : string ) => {
4557 requestKeyFactorsExpand ?.( ) ;
4658 openKeyFactorsSectionAndScrollTo ( { selector, mobileOnly : false } ) ;
4759 sendAnalyticsEvent ( "KeyFactorClick" , { event_label : "fromTopList" } ) ;
4860 } ;
4961
50- if ( topItems . length === 0 ) return null ;
51-
5262 return (
5363 < div
5464 className = "-ml-4 flex w-[calc(100%+32px)] flex-col pb-4 sm:ml-0 sm:mt-8 sm:w-full"
@@ -58,18 +68,33 @@ const KeyFactorsQuestionConsumerSection: FC<Props> = ({ post }) => {
5868 < div className = "text-sm text-blue-800 dark:text-blue-800-dark" >
5969 { t ( "topKeyFactors" ) }
6070 </ div >
61- < button
62- onClick = { ( ) => {
63- openKeyFactorsElement ( "[id='key-factors']" ) ;
64- sendAnalyticsEvent ( "KeyFactorViewAllClick" ) ;
65- } }
66- className = "text-center text-sm font-normal leading-5 text-blue-600 hover:text-blue-700 dark:text-blue-600-dark dark:hover:text-blue-700-dark"
67- >
68- { t ( "viewAll" , { count : totalCount } ) }
69- </ button >
71+ { ! forecastIsEmpty && (
72+ < button
73+ onClick = { ( ) => {
74+ openKeyFactorsElement ( "[id='key-factors']" ) ;
75+ sendAnalyticsEvent ( "KeyFactorViewAllClick" ) ;
76+ } }
77+ className = "text-center text-sm font-normal leading-5 text-blue-600 hover:text-blue-700 dark:text-blue-600-dark dark:hover:text-blue-700-dark"
78+ >
79+ { t ( "viewAll" , { count : totalCount } ) }
80+ </ button >
81+ ) }
7082 </ div >
7183
72- < KeyFactorsConsumerCarousel post = { post } items = { topItems } />
84+ { forecastIsEmpty ? (
85+ < KeyFactorsCarousel
86+ listClassName = "pb-0 [&>:first-child]:pl-4 [&>:last-child]:pr-4 sm:[&>:first-child]:pl-0 sm:[&>:last-child]:pr-0"
87+ items = { Array . from ( { length : 5 } ) }
88+ renderItem = { ( _ , i ) => (
89+ < div
90+ key = { i }
91+ className = "h-[196px] w-[160px] shrink-0 rounded-xl bg-blue-200 dark:bg-blue-200-dark sm:w-[200px]"
92+ />
93+ ) }
94+ />
95+ ) : (
96+ < KeyFactorsConsumerCarousel post = { post } items = { topItems } />
97+ ) }
7398
7499 { keyFactorOverlay ?. kind === "keyFactor" && (
75100 < KeyFactorDetailOverlay
0 commit comments