import { useState, useEffect } from "react"; import { useNavigate, useParams } from "react-router-dom"; import { CopyToClipboard } from "react-copy-to-clipboard"; import { FacebookShareButton, FacebookIcon, ViberShareButton, ViberIcon, LinkedinShareButton, LinkedinIcon, TwitterShareButton, TwitterIcon, WhatsappShareButton, WhatsappIcon, TelegramShareButton, TelegramIcon } from "react-share"; import { Title } from "../ui/title"; import Answers from './Answers' function Poll(props) { const { user, anon, poll, exist, socket } = props const { id } = useParams(); const navigate = useNavigate(); const token = localStorage.getItem(id) const FRONT_URL = `https://${window.location.hostname}` const shareUrl = `${FRONT_URL}/poll/${id}` const [copied, setCopied] = useState(false); const randomUser = (length) => { let result = ""; const characters = "abcdefghijklmnopqrstuvwxyz123456789"; const charactersLength = characters.length; let counter = 0; while (counter < length) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); counter += 1; } return result; } useEffect(() => { if (!token) { console.log('POLL 🎱 id:', id) console.log('POLL 🎱 token:', Boolean(token)) const data = {pid:id}; console.log(' 💾 POLL emit.join.data:', data) socket.emit('join', data); } if (token) { console.log('POLL 🎱 id:', id) console.log('POLL 🎱 token:', Boolean(token)) const data = {pid:id, token: token}; console.log(' 💾 POLL emit.join.data:', data) socket.emit('join', data); } },[id, token]) useEffect(() => { console.log('POLL 🎱 id:', id) console.log('POLL 🎱 exist:', exist) console.log('POLL 🎱 anon:', anon) console.log('POLL 🎱 user:', user) console.log('POLL 🎱 token:', Boolean(token)) console.log('POLL 🎱 poll:', poll) if (token) { console.log('POLL 🎱 id:', id) console.log('POLL 🎱 token:', Boolean(token)) console.log('POLL emit.poll.token:', token) socket.emit('poll', token); } },[token]) const onCopy = () => { console.log('onCopy') setCopied(true); setTimeout(() => setCopied(false), 2000); } return (
Hello {poll.anonymous ? 'Anonymous' : user}{user}, please choose the answer you like
Share the poll URL to the voters