Skip to content

Commit 8734bc6

Browse files
author
Aishwarya Nair
committed
Add new q submit functionality
1 parent de83ba0 commit 8734bc6

File tree

6 files changed

+65
-30
lines changed

6 files changed

+65
-30
lines changed

peer-prep/src/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import './App.css';
22
//import { LoginSignUp } from './Components/LoginSignUp/LoginSignUp';
33
import { Navbar } from './Components/Navbar/Navbar';
4-
import { Questions } from './Components/Questions/Questions';
4+
import { Questions } from './Components/QuestionList/QuestionList';
55

66
function App() {
77
return (

peer-prep/src/Components/Questions/QuestionForm.css renamed to peer-prep/src/Components/QuestionList/QuestionForm.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
height: 130px;
7575
color: #fff;
7676
background: #52CC65;
77+
border: none;
7778
border-radius: 5px;
7879
font-size: 19px;
7980
cursor: pointer;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import React, { useState } from 'react'
2+
import './QuestionForm.css'
3+
4+
5+
export const QuestionForm = ({qId, addQuestion, setAddQ}) => {
6+
const [title, setTitle] = useState("");
7+
const [difficulty, setDifficulty] = useState("");
8+
const [topic, setTopic] = useState("");
9+
const [description, setDescription] = useState("")
10+
11+
const handleSubmit = (toggleAddQ, addQ) => e => {
12+
e.preventDefault();
13+
toggleAddQ(false);
14+
addQ(title, difficulty, topic, description)
15+
}
16+
return (
17+
<form className = "container" onSubmit={handleSubmit(setAddQ, addQuestion)}>
18+
<div className="q-header">
19+
<div className="q-id">#{qId}</div>
20+
<input type="text" className="q-title q-input"
21+
placeholder='Question Title' onChange = {
22+
(e) => setTitle(e.target.value)
23+
}/>
24+
</div>
25+
26+
<div className="q-tags">
27+
<input type="text" className="q-tag q-input"
28+
placeholder = 'Difficulty'
29+
onChange = {
30+
(e) => setDifficulty(e.target.value)
31+
}/>
32+
<input type="text" className="q-tag q-input"
33+
placeholder = 'Topic'
34+
onChange = {
35+
(e) => setTopic(e.target.value)
36+
}
37+
/>
38+
</div>
39+
<textarea type="text" className="q-description q-input"
40+
placeholder = "Question description"
41+
onChange = {
42+
(e) => setDescription(e.target.value)
43+
}/>
44+
45+
<button type = "submit" className="submit-btn">Submit</button>
46+
47+
48+
</form>
49+
)
50+
}
File renamed without changes.

peer-prep/src/Components/Questions/Questions.jsx renamed to peer-prep/src/Components/QuestionList/QuestionList.jsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1-
import React, { useState } from 'react'
1+
import React, { useState, useEffect} from 'react'
22
import { QuestionForm } from './QuestionForm'
3-
import './Questions.css'
3+
import './QuestionList.css'
44

55
export const Questions = () => {
66
const [qId, setQId] = useState(0);
77
const [isAddQ, setAddQ] = useState(false);
8+
const [qs, setQs] = useState([])
9+
10+
const addQuestion = (qTitle, qDifficulty, qTopic, qDescription) => {
11+
setQs([...qs, {id: qId, title: qTitle, difficulty: qDifficulty,
12+
topic: qTopic, description: qDescription}]);
13+
}
14+
15+
useEffect(() => console.log(qs), [qs]);
16+
817
return (
918
<div className="q-wrapper">
10-
{isAddQ === false ? <div></div> : <QuestionForm qId = {qId}/>}
19+
{isAddQ === false ? <div></div> : <QuestionForm qId = {qId} addQuestion = {addQuestion}
20+
setAddQ = {setAddQ}/>}
1121
<div className="add-q-btn" onClick = {() => {
1222
setQId(qId + 1);
1323
setAddQ(true);

peer-prep/src/Components/Questions/QuestionForm.jsx

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)