// YetiPoll for React (web). Add this file to your project. // // // // Pass `signature` when your app requires signed wall links: compute it on // your server (HMAC-SHA256 of the user id with your secret key). import React, { useEffect, useRef, useState } from 'react'; const ORIGIN = 'https://yetipoll.com'; export function yetiPollWallUrl(appKey, userId, signature) { const query = new URLSearchParams({ app: appKey, user: userId, embed: '1' }); if (signature) { query.set('sig', signature); } return `${ORIGIN}/wall?${query}`; } export function YetiPollWall({ appKey, userId, signature, minHeight = 420, onSurveyOpened }) { const frame = useRef(null); const [height, setHeight] = useState(minHeight); useEffect(() => { function onMessage(event) { if (event.origin !== ORIGIN || !event.data || event.data.source !== 'yetipoll') { return; } if (frame.current && event.source !== frame.current.contentWindow) { return; } if (event.data.type === 'height') { setHeight(Math.max(minHeight, Number(event.data.height) || 0)); } if (event.data.type === 'survey_opened' && onSurveyOpened) { onSurveyOpened(); } } window.addEventListener('message', onMessage); return () => window.removeEventListener('message', onMessage); }, [minHeight, onSurveyOpened]); return (