feat(#680): add embed component

andreidekterev 3 years ago
parent 0e147688a5
commit 03345ce187
  1. 39
      src/pages/StatsView/components/EmbeddedComponent.tsx
  2. 4
      src/pages/StatsView/hooks.tsx
  3. 5
      src/pages/StatsView/index.tsx

@ -0,0 +1,39 @@
import styled from 'styled-components/macro'
import { ButtonSolid, Input } from 'features/Common'
const EmbedContainer = styled.div`
display: flex;
flex-direction: column;
align-items: center;
max-width: 100%;
`
const EmbedInput = styled(Input)`
margin: 0;
max-width: 400px;
wrapperHeight: none;
`
type EmbedProps = {
url: string,
}
export const EmbeddedComponent = ({ url }:EmbedProps) => {
const iframeString = `<iframe src=${url}" width="300px" border="0" class="insports-embed" allowFullScreen srcdoc=${document.querySelector('#statsview')} />`
const handleCopy = async (src: string) => {
await navigator.clipboard.writeText(src)
}
return (
<EmbedContainer>
<EmbedInput
disabled={!!true}
label='Embed Code'
defaultValue={iframeString}
/>
<ButtonSolid onClick={() => handleCopy(iframeString)}>Copy code</ButtonSolid>
</EmbedContainer>
)
}

@ -22,6 +22,7 @@ const INTERVAL_FETCH_STATS = 30 * 1000
export const useStatsView = () => { export const useStatsView = () => {
const [matchProfile, setMatchProfile] = useState<MatchInfo>(null) const [matchProfile, setMatchProfile] = useState<MatchInfo>(null)
const [stats, setStats] = useState<TeamsStats>({}) const [stats, setStats] = useState<TeamsStats>({})
const { const {
profileId, profileId,
sportName, sportName,
@ -55,13 +56,14 @@ export const useStatsView = () => {
const { start, stop } = useInterval({ const { start, stop } = useInterval({
callback: fetchStats, callback: fetchStats,
intervalDuration: INTERVAL_FETCH_STATS, intervalDuration: INTERVAL_FETCH_STATS,
startImmediate: true, startImmediate: false,
}) })
useEffect(() => { useEffect(() => {
if (!sportName || !profileId) return undefined if (!sportName || !profileId) return undefined
start() start()
fetchStats()
fetchMatchInfo() fetchMatchInfo()
return () => stop() return () => stop()

@ -9,7 +9,7 @@ const StatsView = () => {
const { matchProfile, teamsStats } = useStatsView() const { matchProfile, teamsStats } = useStatsView()
return ( return (
<Container> <Container id='statsview'>
<header className='header__logo'> <header className='header__logo'>
<Logo /> <Logo />
</header> </header>
@ -28,6 +28,9 @@ const StatsView = () => {
</Powered> </Powered>
</a> </a>
</footer> </footer>
{/* пока закомментил, потому что он будет вставляться вместе со страницей
<EmbeddedComponent url={window.location.href} /> */}
</Container> </Container>
) )
} }

Loading…
Cancel
Save