11import type { ReactElement } from 'react' ;
22import React from 'react' ;
3+ import { useQueryClient } from '@tanstack/react-query' ;
34import type { AdSquadItem , FeedItem } from '../hooks/useFeed' ;
45import { isBoostedPostAd , isBoostedSquadAd } from '../hooks/useFeed' ;
56import { PlaceholderGrid } from './cards/placeholder/PlaceholderGrid' ;
@@ -10,7 +11,7 @@ import { isSocialTwitterPost, PostType } from '../graphql/posts';
1011import type { LoggedUser } from '../lib/user' ;
1112import useLogImpression from '../hooks/feed/useLogImpression' ;
1213import type { FeedPostClick } from '../hooks/feed/useFeedOnPostClick' ;
13- import { Origin , TargetType } from '../lib/log' ;
14+ import { LogEvent , Origin , TargetType } from '../lib/log' ;
1415import type { UseVotePost } from '../hooks' ;
1516import { useFeedLayout } from '../hooks' ;
1617import { CollectionList } from './cards/collection/CollectionList' ;
@@ -41,7 +42,7 @@ import { ActivePostContextProvider } from '../contexts/ActivePostContext';
4142import { LogExtraContextProvider } from '../contexts/LogExtraContext' ;
4243import { SquadAdList } from './cards/ad/squad/SquadAdList' ;
4344import { SquadAdGrid } from './cards/ad/squad/SquadAdGrid' ;
44- import { adLogEvent , feedLogExtra } from '../lib/feed' ;
45+ import { adLogEvent , feedHighlightsLogEvent , feedLogExtra } from '../lib/feed' ;
4546import { useLogContext } from '../contexts/LogContext' ;
4647import { MarketingCtaVariant } from './marketingCta/common' ;
4748import { MarketingCtaBriefing } from './marketingCta/MarketingCtaBriefing' ;
@@ -53,6 +54,15 @@ import { SocialTwitterList } from './cards/socialTwitter/SocialTwitterList';
5354import { SignalList } from './cards/common/list/SignalList' ;
5455import { OtherFeedPage } from '../lib/query' ;
5556import { isSourceSquadOrMachine } from '../graphql/sources' ;
57+ import { HighlightGrid } from './cards/highlight/HighlightGrid' ;
58+ import { HighlightList } from './cards/highlight/HighlightList' ;
59+ import {
60+ getHighlightIdsKey ,
61+ getHighlightIds ,
62+ MAJOR_HEADLINES_MAX_FIRST ,
63+ majorHeadlinesQueryOptions ,
64+ } from '../graphql/highlights' ;
65+ import { HighlightPostModal } from './modals/HighlightPostModal' ;
5666
5767export type FeedItemComponentProps = {
5868 item : FeedItem ;
@@ -97,6 +107,8 @@ export function getFeedItemKey(item: FeedItem, index: number): string {
97107 switch ( item . type ) {
98108 case 'post' :
99109 return item . post . id ;
110+ case 'highlight' :
111+ return getHighlightIdsKey ( item . highlights ) || `highlight-${ index } ` ;
100112 case 'ad' :
101113 return `ad-${ index } ` ;
102114 default :
@@ -259,6 +271,10 @@ function FeedItemComponent({
259271 disableAdRefresh,
260272} : FeedItemComponentProps ) : ReactElement | null {
261273 const { logEvent } = useLogContext ( ) ;
274+ const queryClient = useQueryClient ( ) ;
275+ const [ selectedHighlightId , setSelectedHighlightId ] = React . useState <
276+ string | null
277+ > ( null ) ;
262278 const inViewRef = useLogImpression (
263279 item ,
264280 index ,
@@ -271,6 +287,100 @@ function FeedItemComponent({
271287
272288 const { shouldUseListFeedLayout, shouldUseListMode } = useFeedLayout ( ) ;
273289 const { boostedBy } = useFeedCardContext ( ) ;
290+
291+ if ( item . type === FeedItemType . Highlight ) {
292+ const HighlightTag =
293+ shouldUseListFeedLayout || shouldUseListMode
294+ ? HighlightList
295+ : HighlightGrid ;
296+ const highlightIds = getHighlightIds ( item . highlights ) ;
297+ const openHighlightModal = ( highlightId : string ) : void => {
298+ queryClient
299+ . fetchQuery (
300+ majorHeadlinesQueryOptions ( { first : MAJOR_HEADLINES_MAX_FIRST } ) ,
301+ )
302+ . catch ( ( ) => undefined )
303+ . finally ( ( ) => setSelectedHighlightId ( highlightId ) ) ;
304+ } ;
305+
306+ return (
307+ < >
308+ < HighlightTag
309+ ref = { inViewRef }
310+ highlights = { item . highlights }
311+ onReadAllClick = { ( ) => {
312+ const [ firstHighlight ] = item . highlights ;
313+
314+ if ( ! firstHighlight ) {
315+ return ;
316+ }
317+
318+ logEvent (
319+ feedHighlightsLogEvent ( LogEvent . Click , {
320+ columns : virtualizedNumCards ,
321+ column,
322+ row,
323+ feedName,
324+ ranking,
325+ action : 'read_all_click' ,
326+ count : item . highlights . length ,
327+ highlightIds,
328+ feedMeta : item . feedMeta ,
329+ } ) ,
330+ ) ;
331+
332+ openHighlightModal ( firstHighlight . id ) ;
333+ } }
334+ onHighlightClick = { ( highlight , position ) => {
335+ logEvent (
336+ feedHighlightsLogEvent ( LogEvent . Click , {
337+ columns : virtualizedNumCards ,
338+ column,
339+ row,
340+ feedName,
341+ ranking,
342+ action : 'highlight_click' ,
343+ position,
344+ count : item . highlights . length ,
345+ clickedHighlight : highlight ,
346+ highlightIds,
347+ feedMeta : item . feedMeta ,
348+ } ) ,
349+ ) ;
350+
351+ openHighlightModal ( highlight . id ) ;
352+ } }
353+ />
354+ < HighlightPostModal
355+ isOpen = { ! ! selectedHighlightId }
356+ selectedHighlightId = { selectedHighlightId }
357+ highlights = { item . highlights }
358+ onRequestClose = { ( ) => setSelectedHighlightId ( null ) }
359+ onHighlightClick = { ( highlight , position , modalHighlights ) => {
360+ logEvent (
361+ feedHighlightsLogEvent ( LogEvent . Click , {
362+ columns : virtualizedNumCards ,
363+ column,
364+ row,
365+ feedName,
366+ ranking,
367+ action : 'modal_highlight_click' ,
368+ position,
369+ count : modalHighlights . length ,
370+ clickedHighlight : highlight ,
371+ highlightIds : getHighlightIds ( modalHighlights ) ,
372+ feedMeta : item . feedMeta ,
373+ } ) ,
374+ ) ;
375+ } }
376+ onSelectHighlight = { ( highlight ) => {
377+ setSelectedHighlightId ( highlight . id ) ;
378+ } }
379+ />
380+ </ >
381+ ) ;
382+ }
383+
274384 const {
275385 PostTag,
276386 AdTag,
0 commit comments