From 05c1e06f38ef5ed2b9b1463b9b5ee3db8f42c7af Mon Sep 17 00:00:00 2001 From: Adrian De Lisle Date: Thu, 4 Mar 2021 15:29:54 -0800 Subject: [PATCH] 105 example of videoask embedding and complete message --- pages/video-ask-experiment.js | 81 +++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 pages/video-ask-experiment.js diff --git a/pages/video-ask-experiment.js b/pages/video-ask-experiment.js new file mode 100644 index 0000000..0da309e --- /dev/null +++ b/pages/video-ask-experiment.js @@ -0,0 +1,81 @@ +import { useEffect, useState } from 'react' + +import styled from 'styled-components' + +import { SiteHeader } from 'components' +import { ContentRoot } from 'components/layout' +import { MOBILE_SIZE, TABLET_LARGE_SIZE } from 'styles/constants' + +const HeroSection = styled.section` + display: flex; + flex-direction: column; + color: #ffffff; + background: #000000; + background: linear-gradient(248.66deg, #010242 0%, #0f1011 100%); + overflow: hidden; + flex-grow: 1; +` + +const Content = styled.div` + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + flex-grow: 1; + margin: 0 5rem; + @media only screen and (max-width: ${TABLET_LARGE_SIZE}) { + margin: 0 3rem; + } + + @media only screen and (max-width: ${MOBILE_SIZE}) { + margin: 0 1rem; + } +` + +const VideoAskExperiment = () => { + const [isVideoaskSubmitted, setVideoaskSubmitted] = useState(false) + + useEffect(() => { + if (process.browser) { + const isVideoaskMessage = (message) => + message.origin === 'https://www.videoask.com' && + message.data && + message.data.type && + message.data.type.startsWith('videoask_') + + window.addEventListener('message', (message) => { + if (!isVideoaskMessage(message)) { + return + } + + console.log('got videoask message', message.data) + + const { type } = message.data + if (type === 'videoask_submitted') { + setVideoaskSubmitted(true) + } + }) + } + }, []) + return ( + + + + + {!isVideoaskSubmitted && ( +