import React, { useEffect, useState } from 'react'; import Button from '@custom/shared/components/Button'; import { Card, CardBody, CardFooter, CardHeader, } from '@custom/shared/components/Card'; import Field from '@custom/shared/components/Field'; import { TextInput, BooleanInput, SelectInput } from '@custom/shared/components/Input'; import Well from '@custom/shared/components/Well'; import { slugify } from '@custom/shared/lib/slugify'; import PropTypes from 'prop-types'; /** * Intro * --- * Specify which room we would like to join */ export const Intro = ({ tokenError, fetching, error, onJoin, }) => { const [rooms, setRooms] = useState({}); const [duration, setDuration] = useState("30"); const [roomName, setRoomName] = useState(); const [privacy, setPrivacy] = useState(true); const fetchRooms = async () => { const res = await fetch('/api/presence', { method: 'GET', headers: { 'Content-Type': 'application/json', }, }); const resJson = await res.json(); setRooms(resJson); } useEffect(() => { fetchRooms(); const i = setInterval(fetchRooms, 15000); return () => clearInterval(i); }, []); return (
Join a class {Object.keys(rooms).length === 0 && (

Looks like there's no class going on right now, start with creating one!

)} {Object.keys(rooms).map(room => (
{slugify.revert(room)}
{`${rooms[room].length} ${rooms[room].length > 1 ? 'people' : 'person'} in class`}
))}
OR
Create a class {error && ( Failed to create class

{error}

)} {tokenError && ( Failed to obtain token

{tokenError}

)} setRoomName(e.target.value)} required /> setDuration(e.target.value)} value={duration}> setPrivacy(e.target.checked)} />
); }; Intro.propTypes = { room: PropTypes.string, onJoin: PropTypes.func.isRequired, }; export default Intro;