11import { css } from '@emotion/react' ;
2- import type { ABTestAPI as ABTestAPIType } from '@guardian/ab-core' ;
32import { from , space } from '@guardian/source/foundations' ;
43import {
54 Button ,
@@ -8,16 +7,8 @@ import {
87 SvgChevronRightSingle ,
98} from '@guardian/source/react-components' ;
109import { useEffect , useRef , useState } from 'react' ;
11- import { submitComponentEvent } from '../client/ophan/ophan' ;
1210import { getZIndex } from '../lib/getZIndex' ;
1311import { ophanComponentId } from '../lib/ophan-helpers' ;
14- import {
15- clearHighlightsState ,
16- getOrderedHighlights ,
17- onHighlightEvent ,
18- resetHighlightsState ,
19- } from '../lib/personaliseHighlights' ;
20- import { useAB } from '../lib/useAB' ;
2112import { palette } from '../palette' ;
2213import type { DCRFrontCard } from '../types/front' ;
2314import { HighlightsCard } from './Masthead/HighlightsCard' ;
@@ -86,10 +77,6 @@ const carouselStyles = css`
8677 position : relative;
8778` ;
8879
89- const scrollSnapStyles = css `
90- scroll-snap-type : x mandatory;
91- ` ;
92-
9380const itemStyles = css `
9481 scroll-snap-align : start;
9582 grid-area : span 1 ;
@@ -219,55 +206,12 @@ const getOphanInfo = (frontId?: string) => {
219206 } ;
220207} ;
221208
222- const isEqual = (
223- historicalHighlights : DCRFrontCard [ ] ,
224- currentHighlights : DCRFrontCard [ ] ,
225- ) => {
226- const c = currentHighlights . map ( ( v ) => v . url ) ;
227- const h = historicalHighlights . map ( ( v ) => v . url ) ;
228- return c . every ( ( v ) => {
229- return h . includes ( v ) ;
230- } ) ;
231- } ;
232209export const ScrollableHighlights = ( { trails, frontId } : Props ) => {
233210 const carouselRef = useRef < HTMLOListElement | null > ( null ) ;
234211 const carouselLength = trails . length ;
235212 const imageLoading = 'eager' ;
236213 const [ showPreviousButton , setShowPreviousButton ] = useState ( false ) ;
237214 const [ showNextButton , setShowNextButton ] = useState ( true ) ;
238- const [ shouldShowHighlights , setShouldShowHighlights ] = useState ( false ) ;
239- const [ orderedTrails , setOrderedTrails ] = useState < DCRFrontCard [ ] > ( trails ) ;
240-
241- const ABTestAPI = useAB ( ) ?. api ;
242-
243- type Attr =
244- | 'click-tracking'
245- | 'view-tracking'
246- | 'click-and-view-tracking'
247- | 'not-in-test'
248- | undefined ;
249-
250- const getUserABAttr = ( api ?: ABTestAPIType ) : Attr => {
251- if ( ! api ) return undefined ;
252-
253- if ( api . isUserInVariant ( 'PersonalisedHighlights' , 'click-tracking' ) ) {
254- return 'click-tracking' ;
255- }
256- if ( api . isUserInVariant ( 'PersonalisedHighlights' , 'view-tracking' ) ) {
257- return 'view-tracking' ;
258- }
259- if (
260- api . isUserInVariant (
261- 'PersonalisedHighlights' ,
262- 'click-and-view-tracking' ,
263- )
264- ) {
265- return 'click-and-view-tracking' ;
266- }
267- return 'not-in-test' ;
268- } ;
269-
270- const abTestPersonalisedHighlightAttr = getUserABAttr ( ABTestAPI ) ;
271215
272216 const scrollTo = ( direction : 'left' | 'right' ) => {
273217 if ( ! carouselRef . current ) return ;
@@ -302,15 +246,6 @@ export const ScrollableHighlights = ({ trails, frontId }: Props) => {
302246 setShowNextButton ( scrollLeft < maxScrollLeft ) ;
303247 } ;
304248
305- useEffect ( ( ) => {
306- if (
307- abTestPersonalisedHighlightAttr === 'view-tracking' ||
308- abTestPersonalisedHighlightAttr === 'click-and-view-tracking'
309- ) {
310- onHighlightEvent ( 'VIEW' ) ;
311- }
312- } , [ abTestPersonalisedHighlightAttr ] ) ;
313-
314249 useEffect ( ( ) => {
315250 const carouselElement = carouselRef . current ;
316251 if ( ! carouselElement ) return ;
@@ -328,57 +263,11 @@ export const ScrollableHighlights = ({ trails, frontId }: Props) => {
328263 } ;
329264 } , [ ] ) ;
330265
331- useEffect ( ( ) => {
332- if ( abTestPersonalisedHighlightAttr === undefined ) {
333- return ;
334- }
335-
336- if ( abTestPersonalisedHighlightAttr === 'not-in-test' ) {
337- clearHighlightsState ( ) ;
338- setOrderedTrails ( trails ) ;
339- setShouldShowHighlights ( true ) ;
340- return ;
341- }
342-
343- const personalisedHighlights = getOrderedHighlights ( trails ) ;
344- if (
345- personalisedHighlights . length === 0 ||
346- personalisedHighlights . length !== trails . length ||
347- ! isEqual ( personalisedHighlights , trails )
348- ) {
349- /* Reset to editorial order */
350- resetHighlightsState ( trails ) ;
351- setOrderedTrails ( trails ) ;
352- setShouldShowHighlights ( true ) ;
353- return ;
354- }
355- /* Otherwise, use personalised order from local storage */
356- setOrderedTrails ( personalisedHighlights ) ;
357- setShouldShowHighlights ( true ) ;
358- /* Fire a view event only if the container has been personalised */
359- void submitComponentEvent (
360- {
361- component : {
362- componentType : 'CONTAINER' ,
363- id : `reordered-highlights-container` ,
364- } ,
365- action : 'VIEW' ,
366- } ,
367- 'Web' ,
368- ) ;
369- } , [ trails , abTestPersonalisedHighlightAttr ] ) ;
370-
371266 const { ophanComponentLink, ophanComponentName, ophanFrontName } =
372267 getOphanInfo ( frontId ) ;
373268
374269 return (
375- < div
376- css = { [
377- containerStyles ,
378- { visibility : shouldShowHighlights ? 'visible' : 'hidden' } ,
379- ] }
380- data-link-name = { ophanFrontName }
381- >
270+ < div css = { containerStyles } data-link-name = { ophanFrontName } >
382271 < ol
383272 data-link-name = { ophanComponentLink }
384273 data-component = { ophanComponentName }
@@ -387,16 +276,10 @@ export const ScrollableHighlights = ({ trails, frontId }: Props) => {
387276 css = { [
388277 carouselStyles ,
389278 generateCarouselColumnStyles ( carouselLength ) ,
390- /*
391- * Enable scroll-snap only when visible to prevent browser scroll anchoring.
392- * When items reorder, browsers try to keep previously visible items in view,
393- * causing unwanted scrolling. Enabling snap after reordering forces position 0.
394- // */
395- shouldShowHighlights && scrollSnapStyles ,
396279 ] }
397280 data-heatphan-type = "carousel"
398281 >
399- { orderedTrails . map ( ( trail ) => {
282+ { trails . map ( ( trail ) => {
400283 return (
401284 < li
402285 key = { trail . url }
@@ -416,16 +299,6 @@ export const ScrollableHighlights = ({ trails, frontId }: Props) => {
416299 showQuotedHeadline = { trail . showQuotedHeadline }
417300 mainMedia = { trail . mainMedia }
418301 starRating = { trail . starRating }
419- trackCardClick = { ( ) => {
420- if (
421- abTestPersonalisedHighlightAttr ===
422- 'click-tracking' ||
423- abTestPersonalisedHighlightAttr ===
424- 'click-and-view-tracking'
425- ) {
426- onHighlightEvent ( 'CLICK' , trail ) ;
427- }
428- } }
429302 />
430303 </ li >
431304 ) ;
0 commit comments