more code

This commit is contained in:
Ste Vadis 2023-09-12 22:49:57 +03:00
parent 565e9c9804
commit 024fdd9823
14 changed files with 109 additions and 51 deletions

1
.env Normal file
View File

@ -0,0 +1 @@
WDS_SOCKET_PORT=443

View File

@ -16,7 +16,7 @@
"web-vitals": "^2.1.4" "web-vitals": "^2.1.4"
}, },
"scripts": { "scripts": {
"start": "react-scripts start", "start": "export PORT=80; react-scripts start",
"build": "react-scripts build", "build": "react-scripts build",
"test": "react-scripts test", "test": "react-scripts test",
"eject": "react-scripts eject" "eject": "react-scripts eject"

View File

@ -19,6 +19,7 @@ function App() {
const [data, setData] = useState(); const [data, setData] = useState();
const [poll, setPoll] = useState(); const [poll, setPoll] = useState();
const [user, setUser] = useState(); const [user, setUser] = useState();
const [list, setList] = useState();
const [isConnected, setIsConnected] = useState(socket.connected); const [isConnected, setIsConnected] = useState(socket.connected);
const navigate = useNavigate(); const navigate = useNavigate();
@ -45,12 +46,17 @@ function App() {
console.log('APP onPoll data: ', data) console.log('APP onPoll data: ', data)
setPoll(data) setPoll(data)
} }
function onInfo(data) {
console.log('APP onInfo data: ', data)
setList(data)
}
socket.on('connect', onConnect); socket.on('connect', onConnect);
socket.on('disconnect', onDisconnect); socket.on('disconnect', onDisconnect);
socket.on('create', onCreate); socket.on('create', onCreate);
socket.on('register', onRegister); socket.on('register', onRegister);
socket.on('poll', onPoll); socket.on('poll', onPoll);
socket.on('info', onInfo);
return () => { return () => {
socket.off('connect', onConnect); socket.off('connect', onConnect);
@ -58,6 +64,7 @@ function App() {
socket.off('create', onCreate); socket.off('create', onCreate);
socket.off('register', onRegister); socket.off('register', onRegister);
socket.off('poll', onPoll); socket.off('poll', onPoll);
socket.off('info', onInfo);
}; };
}, []); }, []);
@ -67,15 +74,13 @@ function App() {
<div className="mx-4"> <div className="mx-4">
<div className="max-w-md mt-8 mx-auto mr-2rounded-xl overflow-hidden md:max-w-2xl bg-black bg-opacity-50 shadow-lg py-6 px-6"> <div className="max-w-md mt-8 mx-auto mr-2rounded-xl overflow-hidden md:max-w-2xl bg-black bg-opacity-50 shadow-lg py-6 px-6">
<Routes> <Routes>
<Route path="/" element={<Home />} /> <Route path="/" element={<Home list={list} socket={socket} />} />
<Route path="/create" element={<Create socket={socket} io={io} />} /> <Route path="/create" element={<Create socket={socket} io={io} />} />
<Route path="/poll/:id" element={<Poll socket={socket} io={io} user={user} poll={poll} />} /> <Route path="/poll/:id" element={<Poll socket={socket} io={io} user={user} poll={poll} />} />
<Route path="/poll/:id/join" element={<Join socket={socket} />} /> <Route path="/poll/:id/join" element={<Join socket={socket} />} />
</Routes> </Routes>
</div> </div>
</div> </div>
{/* <ConnectionState isConnected={isConnected} /> */}
{/* <ConnectionManager /> */}
<Footer /> <Footer />
</div> </div>
) )

View File

@ -17,6 +17,10 @@
} }
} }
html {
font-size: 14px;
}
body { body {
background: linear-gradient(126deg, #0094a1, #b03ab6); background: linear-gradient(126deg, #0094a1, #b03ab6);
background-size: 400% 400%; background-size: 400% 400%;

View File

@ -8,6 +8,9 @@ const Header = () => {
return ( return (
<div className="flex flex-grow justify-between bg-black bg-opacity-40 p-2"> <div className="flex flex-grow justify-between bg-black bg-opacity-40 p-2">
<div className="flex flex-row cursor-pointer" onClick={() => navigate('/')}> <div className="flex flex-row cursor-pointer" onClick={() => navigate('/')}>
<div className="mr-0">
<IconSignal />
</div>
<div className="text-2xl font-bold text-white mt-1">Poll</div> <div className="text-2xl font-bold text-white mt-1">Poll</div>
</div> </div>
<div className="m-1"> <div className="m-1">

View File

@ -1,5 +1,11 @@
import { io } from 'socket.io-client'; import { io } from 'socket.io-client';
const URL = 'http://192.168.1.14:4000'; const options = {
rejectUnauthorized: false, // allow self-signed certs
requestCert: false,
secure: false
};
export const socket = io(URL); const URL = 'https://pollback.vaidis.eu';
export const socket = io(URL, options);

View File

@ -8,9 +8,9 @@ export const Button = ({
big big
}) => { }) => {
const clsCommon = 'flex text-white text-center w-full justify-center rounded-lg'; const clsCommon = 'flex text-white text-center w-full justify-center rounded-lg';
const clsEnabled = 'bg-gradient-to-r from-green-500 to-blue-500 hover:from-green-600 hover:to-blue-600 focus:outline-none shadow-md rounded-lg mx-auto'; const clsEnabled = 'bg-gradient-to-r from-green-500 to-blue-500 hover:from-green-600 hover:to-blue-600 focus:outline-none shadow-md rounded-lg mx-auto shadow-black';
const clsDisabled = 'text-slate-500 bg-black'; const clsDisabled = 'text-slate-500 bg-black';
const clsBig = `p-4` const clsBig = `p-5`
const clsSmall = `py-1 px-3` const clsSmall = `py-1 px-3`
const cls = classNames( const cls = classNames(

View File

@ -85,9 +85,9 @@ export const IconCopy = () => <svg
export const IconSignal = () => <svg export const IconSignal = () => <svg
width="32" width="30"
height="32" height="30"
viewBox="0 0 18 20" viewBox="0 0 16 20"
fill="white" fill="white"
> >
<path <path

View File

@ -2,7 +2,7 @@ export const Title = ({ label, variant }) => {
const Heading = `h${variant}`; const Heading = `h${variant}`;
return ( return (
<Heading className="text-white font-medium leading-tight text-primary inline-block align-middle"> <Heading className="text-white text-2xl font-medium leading-tight text-primary inline-block align-middle">
{variant === 1 && <span className="mr-4">&#9733;</span>} {variant === 1 && <span className="mr-4">&#9733;</span>}
{label} {label}
</Heading> </Heading>

View File

@ -44,7 +44,7 @@ const Answers = (props) => {
<div key={index} className="flex flex-col my-8"> <div key={index} className="flex flex-col my-8">
<div className="flex flex-row"> <div className="flex flex-row">
{countVotes(index)} {countVotes(index)}
<button className="w-10/12 p-2 text-center align-middle bg-white rounded-r-lg drop-shadow-lg" onClick={() => onVote(index)} > <button className="w-10/12 p-2 text-center text-black align-middle bg-white rounded-r-lg drop-shadow-lg" onClick={() => onVote(index)} >
{answer} {answer}
</button> </button>
</div> </div>

View File

@ -19,6 +19,7 @@ const Create = (props) => {
}); });
useEffect(() => { useEffect(() => {
// todo: validate for spaces only answer
if ( if (
formData.answers.indexOf("") === -1 && formData.answers.indexOf("") === -1 &&
formData.answers.length > 1 && formData.answers.length > 1 &&
@ -136,7 +137,7 @@ const Create = (props) => {
</div> </div>
</div> </div>
<div className="mt-4 ml-4 w-full"> <div className="mt-10 ml-4 w-full">
<Checkbox <Checkbox
id='anon' id='anon'
label="Don't show voters names" label="Don't show voters names"

View File

@ -1,36 +1,73 @@
import { useNavigate } from "react-router-dom"; import { useState, useEffect } from "react";
import { useNavigate, Link} from "react-router-dom";
import { Title } from "../ui/title"; import { Title } from "../ui/title";
import { Button } from "../ui/button"; import { Button } from "../ui/button";
import { IconPlus } from "../ui/icons"; import { IconPlus } from "../ui/icons";
const Home = () => { const Home = (props) => {
const { list, socket } = props;
const storage = localStorage
const navigate = useNavigate(); const navigate = useNavigate();
const FRONT_URL="https://poll.vaidis.eu"
useEffect(() => {
if (Object.keys(storage).length > 0) {
socket.emit('info', storage);
}
},[])
if (list && Object.keys(list).length > 0) {
console.log("list:", list);
return (
<div>
<div className="mb-8">
<Title variant={1} label="Your polls:" />
</div>
<ul className="text-white">
{
list && list.map((item, index) => {
return (
<li className="my-6" key={index}><Link to={`${FRONT_URL}/poll/${item.id}`}>
&#9734; {item.title}
<span className="text-gray-500"> ({item.users})</span>
</Link></li>
)
})
}
</ul>
</div>
)
}
else {
return ( return (
<div className="flex flex-col"> <div className="flex flex-col">
<Title variant={1} label="Lets make a poll real fast!" /> <Title variant={1} label="Lets make a poll really fast!" />
<div className="text-white my-8"> <div className="text-white my-8">
<p><span className="mr-4">&#9734;</span>$0 cost.</p> <p><span className="mr-4">&#9734;</span>$0 cost.</p>
<p><span className="mr-4">&#9734;</span>No sign up. No personal data.</p> <p><span className="mr-4">&#9734;</span>No sign up. No personal data.</p>
<p><span className="mr-4">&#9734;</span>Anonymous voting option available!</p> <p><span className="mr-4">&#9734;</span>Anonymous voting available!</p>
<p><span className="mr-4">&#9734;</span>Blazing fast poll creation with only 3 quick steps:</p> <br/>
<ul className="list-decimal my-8 pl-12"> <p>Just 3 quick steps:</p>
<li className="pl-2">Create the poll with only title and questions.</li> <ul className="list-decimal my-8 pl-6">
<li className="pl-2">Join the poll with a nickname.</li> <li className="pl-2"><strong>Create</strong> the poll only with title and questions.</li>
<li className="pl-2">Share the poll url to votes.</li> <li className="pl-2"><strong>Join</strong> the poll with a nickname.</li>
<li className="pl-2"><strong>Share</strong> the poll url to voters.</li>
</ul> </ul>
<p>Surprice the voters, its free!</p> <p>Surprice the voters, its free!</p>
</div> </div>
<div className="w-15"> <div className="w-15">
<Button <Button
className="p-15" className="p-25"
label="Create new poll" label="Create new poll"
icon={<IconPlus />} icon={<IconPlus />}
onClick={() => navigate('/create')} onClick={() => navigate('/create')}
big={true}
/> />
</div> </div>
</div> </div>
) )
} }
}
export default Home export default Home

View File

@ -5,8 +5,6 @@ import { Title } from "../ui/title";
import { Button } from "../ui/button"; import { Button } from "../ui/button";
import { Input } from "../ui/input"; import { Input } from "../ui/input";
const URL ="http://192.168.1.14:4001"
const Join = (props) => { const Join = (props) => {
const {socket} = props const {socket} = props
const [user, setUser] = useState(''); const [user, setUser] = useState('');

View File

@ -6,13 +6,16 @@ import { Title } from "../ui/title";
import Answers from './Answers' import Answers from './Answers'
function Poll(props) { function Poll(props) {
const { user, poll, socket } = props
const navigate = useNavigate();
const { id } = useParams();
const token = localStorage.getItem(id)
const [copied, setCopied] = useState(false);
console.log('Poll props:', props) console.log('Poll props:', props)
const FRONT_URL = "http://192.168.1.14:3000"
const { user, poll, socket } = props
const { id } = useParams();
const navigate = useNavigate();
const token = localStorage.getItem(id)
const FRONT_URL = "https://poll.vaidis.eu"
const [copied, setCopied] = useState(false);
useEffect(() => { useEffect(() => {
if (!token) { if (!token) {
return navigate(`/poll/${id}/join`) return navigate(`/poll/${id}/join`)
@ -33,7 +36,7 @@ function Poll(props) {
{poll && {poll &&
<div className="mb-8"> <div className="mb-8">
<Title variant={1} label={poll.title} /> <Title variant={1} label={poll.title} />
<p className="text-white text-sm">Hello <strong>{user}</strong>, please choose the answer you like</p> <p className="text-white mt-6 text-sm">Hello <strong>{user}</strong>, please choose the answer you like</p>
<Answers poll={poll} id={id} user={user} socket={socket} /> <Answers poll={poll} id={id} user={user} socket={socket} />
</div> </div>
} }
@ -45,7 +48,7 @@ function Poll(props) {
{FRONT_URL}/poll/{id} {FRONT_URL}/poll/{id}
</div> </div>
<div className=""> <div className="">
<CopyToClipboard onCopy={onCopy} text={`${URL}/poll/${id}`}> <CopyToClipboard onCopy={onCopy} text={`${FRONT_URL}/poll/${id}`}>
<i className="flex mr-2 gg-copy"></i> <i className="flex mr-2 gg-copy"></i>
</CopyToClipboard> </CopyToClipboard>
</div> </div>