import React, { useEffect, useRef, useState } from 'react'; import { Placeholder } from '@times-components/image'; import { initSettings, initStyleSheet, initScript, initElement, initComponent } from '../../utils/config'; import { PlaceholderContainer } from '../../shared/shared-styles'; import { PageViewContainer, WidgetContainer } from './styles'; export const OptaFootballCompetitionStatsPageView: React.FC<{ season: string; competition: string; isApp?: boolean; full_width?: boolean; heightSm?: number; heightMd?: number; heightLg?: number; [key: string]: any; }> = React.memo( ({ season, competition, isApp = false, full_width, heightSm, heightMd, heightLg }) => { const ref = useRef(null); const [isReady, setIsReady] = useState(false); useEffect( () => { const sport = 'football'; initSettings(); initStyleSheet(sport); initScript() .then(() => { if (ref.current) { ref.current.innerHTML = initElement('opta-widget', { sport, widget: 'competition_stats', season, competition, template: 'normal', graph_style: 'relative', show_images: true, show_crests: true, show_ranks: true, show_player_rankings: true, show_team_rankings: true, visible_stats: 'games_played,goals,goals_per_game,penalties,cards_yellow,cards_red', limit: '3', team_naming: 'full', player_naming: 'full', show_logo: true, show_title: true, breakpoints: '700' }).outerHTML; initComponent(); } }) .then(() => { setIsReady(true); }); return undefined; }, [competition, season] ); return ( {!isReady && ( )} ); } );