Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dd #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

dd #17

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 5 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,7 @@
# Getting Started with Create React App
Live Demo: https://lukaszdutka.github.io/coders-camp-hackathon-2021-frontend

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
Frontend:
https://github.com/lukaszdutka/coders-camp-hackathon-2021-frontend

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.\
You will also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)

### Analyzing the Bundle Size

This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)

### Making a Progressive Web App

This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)

### Advanced Configuration

This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)

### Deployment

This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)

### `npm run build` fails to minify

This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
Backend:
https://github.com/lukaszdutka/coders-camp-hackathon-2021-backend
2 changes: 1 addition & 1 deletion src/api/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export class Rooms {
static async updateGuests(id, guest) {
// guest = {email: "test@test.com", name: "Albus Dumbledore"}
try {
const response = await fetch(`${Rooms.apiUrl}/${id}`, {
const response = await fetch(`${Rooms.apiUrl}/${id}/guests`, {
method: "PATCH",
mode: "cors",
headers: {
Expand Down
9 changes: 2 additions & 7 deletions src/components/forms/GuestForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,22 @@ import {
Button,
FormGroup,
TextField,
FormControl,
InputLabel,
MenuItem,
} from "@material-ui/core";
import * as yup from "yup";
import { useFormik } from "formik";
import { Rooms } from "../../api/rooms";
import { Collections } from "../../api/collections";

const validationSchema = yup.object({
email: yup.string("Enter your e-mail").required("E-mail is required"),
name: yup.string("Enter your name").required("Name is required"),
});

export const GuestForm = ({ id, setGuestEmail, setGuestName }) => {
export const GuestForm = ({ roomId, setGuestEmail, setGuestName }) => {
const [error, setError] = useState("");

const onSubmit = async (values) => {
setError(<CircularProgress />);
const result = await Rooms.updateGuests(id, { email: values.email, name: values.name });
const result = await Rooms.updateGuests(roomId, { email: values.email, name: values.name });
if (!result.error) {
setError("You successfully entered the room!");
setGuestEmail(values.email);
Expand Down Expand Up @@ -66,7 +62,6 @@ export const GuestForm = ({ id, setGuestEmail, setGuestName }) => {
helperText={formik.touched.email && formik.errors.email}
/>
<FormHelperText error>{error}</FormHelperText>

<Button type="submit">Submit</Button>
</FormGroup>
</form>
Expand Down
28 changes: 28 additions & 0 deletions src/components/forms/Question.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Button, AppBar, Toolbar, Typography, Paper } from "@material-ui/core";
import { CodeSharp } from "@material-ui/icons";
import { Rooms } from "../../api/rooms";

export const Question = ({
activeQuestion: { _id, answers, text, timeForAnswer, updatedAt },
setActiveQuestion,
roomId,
email
}) => {
const handleAnswer = async (e) => {
const res = await Rooms.postAnswer(roomId, _id, e.target.name, email);
if (res.error) console.log(res.error)
if (!res.error) console.log(res)
};

const answerList = answers.map((answer, index) => (
<Button variant="contained" color="secondary" onClick={handleAnswer} name={index}>
{answer}
</Button>
));
return (
<Paper>
<Typography variant="h6">{text}</Typography>
{answers && answerList}
</Paper>
);
};
24 changes: 23 additions & 1 deletion src/views/guest/Guest.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,28 @@ import { useParams } from "react-router-dom";
import { Rooms } from "../../api/rooms";
import { GuestForm } from "../../components/forms/GuestForm";
import { Typography, Paper } from "@material-ui/core";
import { Question } from "../../components/forms/Question";

export const Guest = () => {
const { id } = useParams();
const [room, setRoom] = useState(null);
const [guestName, setGuestName] = useState("");
const [guestEmail, setGuestEmail] = useState("");
const [activeQuestion, setActiveQuestion] = useState(null);

useEffect(() => {});
useEffect(() => {
const getActiveQuestion = async () => {
const question = await Rooms.getActiveQuestion(id, guestEmail);
if (!question.error) setActiveQuestion(question);
if (question.error || !question) setActiveQuestion("");
console.log(question);
};
if (guestEmail) {
getActiveQuestion();
const interval = setInterval(() => getActiveQuestion(), 1000);
return () => clearInterval(interval);
}
}, [guestEmail, id]);
return (
<div>
{!guestName && !guestEmail ? (
Expand All @@ -21,6 +35,14 @@ export const Guest = () => {
<Typography variant="body1">Please wait for questions</Typography>
</Paper>
)}
{activeQuestion && guestName && guestEmail && (
<Question
activeQuestion={activeQuestion}
setActiveQuestion={setActiveQuestion}
roomId={id}
email={guestEmail}
/>
)}
</div>
);
};