Skip to content

Commit c5dcd0e

Browse files
committed
changes
1 parent f64aed0 commit c5dcd0e

7 files changed

Lines changed: 60 additions & 37 deletions

File tree

backend/.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
TOKEN_SECRET="shivamgupta"
22
CLIENT_ID=540174704725-dh2d8m3i11jikb8l724b44q2rql5cnmn.apps.googleusercontent.com
33
CLIENT_SECRET=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
4-
PORT=5000
4+
PORT=5000
5+
DB_URI="mongodb+srv://testing_node:test1234@cluster0.jriry7x.mongodb.net/Zcoder?retryWrites=true&w=majority&appName=Cluster0"

backend/config/database.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
const mongoose=require('mongoose')
2+
const dotenv=require('dotenv');
3+
dotenv.config();
4+
const mongo_uri=process.env.DB_URI;
25
const connect = async ()=>{
36
try {
47
console.log('Connecting to database')
5-
await mongoose.connect("mongodb+srv://testing_node:test1234@cluster0.jriry7x.mongodb.net/Zcoder?retryWrites=true&w=majority&appName=Cluster0"
8+
await mongoose.connect(mongo_uri
69
).then(()=>{
710
console.log('Database connected');
811
}).catch((err)=>{

backend/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ const app = express();
33
const {createServer}=require('http');
44
const {Server}=require('socket.io')
55
const cors=require('cors');
6-
const port =process.env.PORT || 10000;
6+
7+
78
const connect = require('./config/database');
89
const auth=require('./middleware/auth');
910
//const userRouter=require('./routes/userRoute');
@@ -20,6 +21,7 @@ const middleware=require('./middleware/auth');
2021
dotenv.config();
2122
const profile = require('./pages/profile/profile');
2223
const ask = require('./pages/problem/problem')
24+
const port =process.env.PORT;
2325
app.use(express.json());
2426
app.use(express.urlencoded({ extended: false }));
2527
app.use(session({

frontend-next/app/components/ui/textareaeditor.jsx

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,35 @@
22
import { useEffect, useState } from "react";
33
import axios from "axios";
44

5-
const Testareaanswer = ({_id}) => {
5+
const Testareaanswer = ({ _id, onAnswerPosted }) => {
66
console.log(_id)
77
const [addAnswer, setAddAnswer] = useState({
88
user_id: "",
99
name: "",
1010
answer: "",
1111
});
1212
useEffect(() => {
13-
const userdetails=async()=>{
14-
const token = window.sessionStorage.getItem("token");
15-
try {
16-
const res = await axios.get("https://zcoder-backend-dm5b.onrender.com/api/getAuth", {
17-
headers: {
18-
'Authorization': `${token}`,
19-
},
20-
});
21-
console.log(res.data);
22-
setAddAnswer({...addAnswer,user_id:res.data._id,name:res.data.name});
23-
} catch (err) {
24-
console.log(err);
13+
const userdetails = async () => {
14+
const token = window.sessionStorage.getItem("token");
15+
try {
16+
const res = await axios.get("https://zcoder-backend-dm5b.onrender.com/api/getAuth", {
17+
headers: {
18+
'Authorization': `${token}`,
19+
},
20+
});
21+
console.log(res.data);
22+
setAddAnswer({ ...addAnswer, user_id: res.data._id, name: res.data.name });
23+
} catch (err) {
24+
console.log(err);
25+
}
2526
}
26-
}
27-
userdetails();
28-
},[]);
29-
const handleanswer = async () => {
27+
userdetails();
28+
}, []);
29+
const handleanswer = async (e) => {
30+
e.preventDefault();
3031
const token = window.sessionStorage.getItem("token");
3132
try {
32-
if(addAnswer.answer===""){
33+
if (addAnswer.answer === "") {
3334
alert("Please enter the answer first");
3435
return;
3536
}
@@ -39,27 +40,34 @@ const Testareaanswer = ({_id}) => {
3940
},
4041
});
4142
console.log(res.data);
42-
setAddAnswer("");
43+
if (res.status === 200) {
44+
onAnswerPosted();
45+
setAddAnswer((prev) => ({
46+
...prev,
47+
answer: ""
48+
}));
49+
}
50+
4351
// window.location.reload();
4452
} catch (err) {
4553
console.log(err);
4654
}
4755
}
4856
return (
4957
<>
50-
<form className="answerbox my-5">
58+
<div className="answerbox my-5">
5159
<div className="w-full border border-gray-200 rounded-lg bg-gray-50 dark:bg-gray-700 dark:border-gray-600">
5260
<div className="px-4 py-2 bg-white rounded-t-lg dark:bg-gray-800">
5361
<label htmlFor="comment" className="sr-only">Your answer</label>
54-
<textarea id="comment" rows="4" className="w-full px-0 text-sm text-gray-900 bg-white border-0 dark:bg-gray-800 focus:ring-0 dark:text-white dark:placeholder-gray-400 h-56" placeholder="Write a answer..." required onChange={(e)=>setAddAnswer({...addAnswer,answer:e.target.value})}></textarea>
62+
<textarea id="comment" rows="4" className="w-full px-0 text-sm text-gray-900 bg-white border-0 dark:bg-gray-800 focus:ring-0 dark:text-white dark:placeholder-gray-400 h-56" placeholder="Write a answer..." required value={addAnswer?.answer} onChange={(e) => setAddAnswer({ ...addAnswer, answer: e.target.value })}></textarea>
5563
</div>
5664
<div className="flex items-center justify-between px-3 py-2 border-t dark:border-gray-600">
57-
<button type="submit" className="inline-flex items-center py-2.5 px-4 text-xs font-medium text-center text-white bg-blue-700 rounded-lg focus:ring-4 focus:ring-blue-200 dark:focus:ring-blue-900 hover:bg-blue-800" onClick={handleanswer}>
65+
<button type="button" className="inline-flex items-center py-2.5 px-4 text-xs font-medium text-center text-white bg-blue-700 rounded-lg focus:ring-4 focus:ring-blue-200 dark:focus:ring-blue-900 hover:bg-blue-800" onClick={handleanswer}>
5866
Post Answer
5967
</button>
6068
</div>
6169
</div>
62-
</form>
70+
</div>
6371

6472
</>
6573
)

frontend-next/app/joinroom/page.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const JoinRoom = () => {
1414

1515
const getAllrooms = async () => {
1616
try {
17-
const res = await axios.get('https://zback-49lo.onrender.com/api/room/getallrooms');
17+
const res = await axios.get('https://zcoder-backend-dm5b.onrender.com/api/room/getallrooms');
1818
setRoomList(res.data);
1919
} catch (err) {
2020
console.log(err);
@@ -25,7 +25,7 @@ const JoinRoom = () => {
2525
const getAuthUser = async () => {
2626
const token = window.sessionStorage.getItem('token');
2727
const instance = axios.create({
28-
baseURL: 'https://zback-49lo.onrender.com/api',
28+
baseURL: 'https://zcoder-backend-dm5b.onrender.com/api',
2929
withCredentials: true,
3030
headers: {
3131
'Content-Type': 'application/json',
@@ -48,7 +48,7 @@ const JoinRoom = () => {
4848
const handleJoinRoom = async (room) => {
4949
console.log(room);
5050
try {
51-
const res = await axios.post("https://zback-49lo.onrender.com/api/room/joinroom", { roomName:room.roomName, roomPassword:room.roomPassword,member:authUser._id });
51+
const res = await axios.post("https://zcoder-backend-dm5b.onrender.com/api/room/joinroom", { roomName:room.roomName, roomPassword:room.roomPassword,member:authUser._id });
5252
console.log(res.data);
5353
setAlertStatus('success');
5454
window.location.href = `/room?id=${res.data._id}`

frontend-next/app/page.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const Home = () => {
2727
fetch();
2828

2929
}, []);
30+
3031
console.log(problems);
3132

3233
return (

frontend-next/app/question/[id]/page.jsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const QuestionPage = ({ params }) => {
1313
const [question_, setQuestion_] = useState(null);
1414
const [loading, setLoading] = useState(true);
1515
const [error, setError] = useState(null);
16-
useEffect(() => {
17-
const fetchQuestion = async () => {
16+
17+
const fetchQuestion = async () => {
1818
const token = window.sessionStorage.getItem("token");
1919
try {
2020
const response = await axios.get(`https://zcoder-backend-dm5b.onrender.com/api/problem/${_id}`, {
@@ -29,20 +29,28 @@ const QuestionPage = ({ params }) => {
2929
setLoading(false);
3030
}
3131
};
32+
33+
34+
useEffect(() => {
35+
3236
fetchQuestion();
3337
}, []);
3438

35-
if (loading) {
36-
return (<div>Loading...</div>); // Show a loading state while the data is being fetched
37-
}
39+
// if (loading) {
40+
// return (<div>Loading...</div>); // Show a loading state while the data is being fetched
41+
// }
3842

3943
if (error) {
4044
return (<div>Error: {error.message}</div>); // Show an error message if the request fails
4145
}
4246

47+
48+
4349
if (!question_) {
44-
return (<div>No data found</div>); // Handle the case where no question data is returned
50+
return (<div>We are fetching.</div>); // Handle the case where no question data is returned
4551
}
52+
53+
4654
console.log(question_);
4755
const { title, question, answers, tag, date,name } = question_.problems;
4856
const currentTime = new Date();
@@ -125,7 +133,7 @@ const QuestionPage = ({ params }) => {
125133
)}
126134
<div className="answereditor mt-6">
127135
<div className="text-sm font-medium mt-4">Write your answer here</div>
128-
<Testareaanswer _id={_id}/>
136+
<Testareaanswer _id={_id} onAnswerPosted={fetchQuestion}/>
129137
</div>
130138
</div>
131139
</div>
@@ -136,4 +144,4 @@ const QuestionPage = ({ params }) => {
136144
);
137145
}
138146

139-
export default auth(QuestionPage);
147+
export default QuestionPage;

0 commit comments

Comments
 (0)