diff --git a/src/App.js b/src/App.js index 02c5f43..1f8c3b4 100644 --- a/src/App.js +++ b/src/App.js @@ -38,6 +38,14 @@ function App() { setAnon(undefined) navigate(`/poll/${data}`) } + function onExist(data) { + console.log(' 🪲 APP onExist data: ', data) + setExist(Boolean(data)) + if (data) { + console.log(' 🪲 APP onExist join: ', data) + socket.emit('join', data); + } + } function onJoin(data) { console.log(' 🪲 APP onJoin data: ', data) setUser(data.user) @@ -49,10 +57,6 @@ function App() { setPoll(data.poll) setUser(data.user) } - function onExist(data) { - console.log(' 🪲 APP onExist data: ', data) - setExist(data) - } function onInfo(data) { console.log(' 🪲 APP onInfo data: ', data) if (data.anonymous !== undefined) { diff --git a/src/view/Home.jsx b/src/view/Home.jsx index 65d9239..15ffcd8 100644 --- a/src/view/Home.jsx +++ b/src/view/Home.jsx @@ -34,11 +34,11 @@ const Home = (props) => { return (
  • -
    -
    ☆ {item.title}
    -
    - ({item.users}) - {item.anonymous ? anonymous : {item.user}} +
    +

    {item.title}

    +
    + {item.users} votes + {item.anonymous ? anonymous : {item.user}}
    diff --git a/src/view/Poll.jsx b/src/view/Poll.jsx index 9238bee..0c4e223 100644 --- a/src/view/Poll.jsx +++ b/src/view/Poll.jsx @@ -41,30 +41,39 @@ function Poll(props) { } useEffect(() => { - console.log('POLL props:', props) + console.log('POLL 🎱 props:', props) + console.log('POLL 🎱 id:', id) + console.log('POLL 🎱 exist:', exist) + console.log('POLL 🎱 anon:', anon) + console.log('POLL 🎱 token:', Boolean(token)) if (exist === undefined) { console.log('POLL emit.exist.id:', id) socket.emit('exist', id) } - if (anon === undefined) { + if (exist && anon === undefined) { console.log('POLL emit.info.id:', id) socket.emit('info', id) } - if (exist && !token && anon !== undefined && anon) { + if (exist && anon !== undefined && anon && !token) { const data = {pid:id, user:randomUser(24)}; - socket.emit('join', data); console.log('POLL emit.join.data:', data) + socket.emit('join', data); } - if (exist && !token && anon !== undefined && !anon) { + if (exist && anon !== undefined && !anon && !token) { console.log('POLL redirect anon:', JSON.stringify(anon)) return navigate(`/poll/${id}/join`) } + if (exist && anon !== undefined && anon && token) { + const data = {pid:id, user:user}; + console.log('POLL emit.join.data:', data) + socket.emit('join', data); + } if (exist && token) { console.log('POLL emit.poll.token:', token) socket.emit('poll', token); } - },[user, exist, anon]) + },[id, exist, anon, token]) const onCopy = () => { console.log('onCopy')