Skip to content

Commit d5f7d97

Browse files
authored
Merge pull request #12 from CodeCrew-CodeSchool/gameroom
Gameroom
2 parents e2b1292 + e5aeced commit d5f7d97

File tree

5 files changed

+36
-18
lines changed

5 files changed

+36
-18
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
webapp/.env

server/server.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@ const http = require("http");
88
const { Server } = require("socket.io");
99
const cors = require("cors");
1010
const Redis = require("ioredis");
11-
const redis = new Redis();
11+
const redis = new Redis(process.env.REDIS);
1212
const cookie = require('cookie');
1313
const signature = require('cookie-signature');
1414
const port = 3001;
1515

1616
const app = express();
1717
app.use(cors({
18-
origin: ["http://localhost:5500", "http://localhost:3000"],
18+
origin: ["http://localhost:5500", "http://localhost:3000","https://codecrew-leetcode.onrender.com"],
1919
credentials: true
2020
}));
2121

2222
app.use(express.json())
2323
const server = http.createServer(app);
2424
const io = new Server(server, {
2525
cors: {
26-
origin: ["http://localhost:5500", "http://localhost:3000"],
26+
origin: ["http://localhost:5500", "http://localhost:3000", "https://codecrew-leetcode.onrender.com"],
2727
credentials: true
2828
}
2929
});

webapp/.env

Lines changed: 0 additions & 1 deletion
This file was deleted.

webapp/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414
# misc
1515
.DS_Store
16-
.env.local
16+
env.local
17+
.env
1718
.env.development.local
1819
.env.test.local
1920
.env.production.local

webapp/src/components/AdminView/SessionAddModal/SessionAddModal.js

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,30 @@ const SessionAddModal = ({ open, handleClose, allItems }) => {
4444

4545
const postSession = async (session, problemsList) => {
4646
try {
47-
const response = await axios.post(
48-
`https://codecrew-leetcode-api.onrender.com/gameroom/${session}`,
49-
problemsList
50-
);
47+
console.log(process.env.REACT_APP_GAMEROOM_API_URL, "URL GO BRRRRRRR")
48+
49+
const response = await axios.post(process.env.REACT_APP_GAMEROOM_API_URL, {
50+
gameroomId: session,
51+
problems: problemsList
52+
53+
});
5154

5255
console.log(response);
5356

54-
return response;
57+
return response.data;
5558
} catch (error) {
59+
60+
if (error.response) {
61+
62+
console.error('Server responded with error:', error.response.data);
63+
} else if (error.request) {
64+
65+
console.error('No response received from server:', error.request);
66+
} else {
67+
68+
console.error('Error setting up request:', error.message);
69+
}
70+
5671
throw new Error('Failed to post problem:', error);
5772
}
5873
};
@@ -65,13 +80,7 @@ const SessionAddModal = ({ open, handleClose, allItems }) => {
6580

6681
setSelectedProblems([...selectedProblems, problemId]);
6782
}
68-
try {
69-
const response = await postSession(sessionName,selectedProblems)
70-
console.log(response);
71-
72-
}catch(err){
73-
console.log(err);
74-
}
83+
7584

7685
};
7786
const handleModalClose = () => {
@@ -82,7 +91,7 @@ const SessionAddModal = ({ open, handleClose, allItems }) => {
8291
handleClose(); // Close the modal
8392
};
8493

85-
const handleSubmission = () => {
94+
const handleSubmission = async () => {
8695
if (selectedProblems.length === 3) {
8796

8897
const selectedProblemNames = selectedProblems.map((_id) => {
@@ -94,6 +103,13 @@ const SessionAddModal = ({ open, handleClose, allItems }) => {
94103
} else {
95104
console.error("Please select exactly 3 problems");
96105
}
106+
try {
107+
const response = await postSession(sessionName ,selectedProblems)
108+
console.log(response);
109+
110+
}catch(err){
111+
console.log(err);
112+
}
97113
};
98114

99115
return (

0 commit comments

Comments
 (0)