Skip to content

Commit 12aad40

Browse files
author
Aishwarya Nair
committed
fix default code not appearing bug
1 parent be7767c commit 12aad40

File tree

3 files changed

+123
-102
lines changed

3 files changed

+123
-102
lines changed

CollaborationService/database/collaborativeInputDb.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const initCollaborativeCode = async (initTime, sessionId, language, userId) => {
7373
return [input[1], input[2]];
7474
}
7575
} catch (error) {
76-
console.log(`Failed to add collaborative input for ${sessionId}`);
76+
console.log(`Failed to add collaborative input for ${sessionId}: ${error}`);
7777

7878
return ["None", []];
7979
}
Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
1-
const mongoose = require('mongoose');
1+
const mongoose = require("mongoose");
22

33
const lineInputSchema = new mongoose.Schema({
4-
line: Number,
5-
code: String,
6-
lastModifier: String
4+
line: Number,
5+
code: String,
6+
lastModifier: String,
77
});
88

99
const collaborativeInputSchema = new mongoose.Schema({
10-
sessionId: String,
11-
initTime: Number,
12-
language: String,
13-
codes: [lineInputSchema]
10+
sessionId: String,
11+
initTime: Number,
12+
language: String,
13+
codes: [lineInputSchema],
1414
});
1515

16+
const CollaborativeInput = mongoose.model(
17+
"CollaborativeInput",
18+
collaborativeInputSchema
19+
);
20+
const LineInput = mongoose.model("LineInput", lineInputSchema);
1621

17-
module.exports = mongoose.model('CollaborativeInput', collaborativeInputSchema);
22+
module.exports = {
23+
LineInput,
24+
CollaborativeInput,
25+
};

Frontend/src/Components/Collaboration/CollaborationWindow.jsx

Lines changed: 105 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
import React, { useState, useEffect, useReducer, useRef } from 'react';
2-
import './CollaborationWindow.css';
3-
import Timer from './Timer';
4-
import { useNavigate } from 'react-router-dom';
5-
import socketIOClient, { Socket } from "socket.io-client";
6-
import 'firebase/auth';
7-
import CodeEditor from './CodeEditor';
8-
import Popup from 'reactjs-popup';
9-
import 'reactjs-popup/dist/index.css';
10-
import { getUserId } from '../../User/UserState';
11-
import { useLocation } from 'react-router-dom';
12-
import CommunicationWindow from './CommunicationWindow';
13-
14-
import axios from "axios"
15-
1+
import React, {useState, useEffect, useReducer, useRef} from "react";
2+
import "./CollaborationWindow.css";
3+
import Timer from "./Timer";
4+
import {useNavigate} from "react-router-dom";
5+
import socketIOClient, {Socket} from "socket.io-client";
6+
import "firebase/auth";
7+
import CodeEditor from "./CodeEditor";
8+
import Popup from "reactjs-popup";
9+
import "reactjs-popup/dist/index.css";
10+
import {getUserId} from "../../User/UserState";
11+
import {useLocation} from "react-router-dom";
12+
import CommunicationWindow from "./CommunicationWindow";
13+
14+
import axios from "axios";
1615

1716
const CollaborationWindow = () => {
1817
const [sessionStarted, setSessionStarted] = useState(false);
@@ -81,15 +80,6 @@ const CollaborationWindow = () => {
8180
navigate("/landing"); // Navigate to home or another route
8281
});
8382

84-
socket.current.on("user-disconnected", (userId) => {
85-
console.log(`User ${userId} has disconnected`);
86-
// Update the UI to reflect the user's disconnection
87-
showToast(
88-
`Experiencing a temporary glitch. Reestablishing your connection...`
89-
);
90-
// Additional logic can be added here
91-
});
92-
9383
socket.current.on("user-reconnected", (userId) => {
9484
console.log(`User ${userId} has reconnected`);
9585
// Handle the user's reconnection in the UI
@@ -188,78 +178,101 @@ const CollaborationWindow = () => {
188178

189179
// Modify the handleExtendTimer function
190180
const handleExtendTimer = () => {
191-
if (socket.current) {
192-
socket.current.emit('extend-time'); // 15 minutes in milliseconds
193-
showToast('Timer extended for 15 minutes');
194-
} else {
195-
console.log("reponse not available");
196-
}
197-
};
181+
if (socket.current) {
182+
socket.current.emit("extend-time"); // 15 minutes in milliseconds
183+
showToast("Timer extended for 15 minutes");
184+
} else {
185+
console.log("reponse not available");
186+
}
187+
};
198188

199189
// useEffect for the countdown logic
200-
useEffect(() => {
201-
let interval;
202-
203-
if (sessionStarted && timeRemaining > 0) {
204-
interval = setInterval(() => {
205-
setTimeRemaining(prevTime => {
206-
// When time runs out, show the popup and stop the interval
207-
if (prevTime <= 1000) {
208-
clearInterval(interval);
209-
setPopup(true);
210-
return 0;
211-
}
212-
// Otherwise, continue counting down
213-
return prevTime - 1000;
214-
});
215-
}, 1000);
216-
}
217-
218-
// Cleanup interval on component unmount or when session ends
219-
return () => {
220-
if (interval) {
221-
clearInterval(interval);
222-
}
223-
};
224-
}, [sessionStarted, timeRemaining]);
190+
useEffect(() => {
191+
let interval;
192+
193+
if (sessionStarted && timeRemaining > 0) {
194+
interval = setInterval(() => {
195+
setTimeRemaining((prevTime) => {
196+
// When time runs out, show the popup and stop the interval
197+
if (prevTime <= 1000) {
198+
clearInterval(interval);
199+
setPopup(true);
200+
return 0;
201+
}
202+
// Otherwise, continue counting down
203+
return prevTime - 1000;
204+
});
205+
}, 1000);
206+
}
207+
208+
// Cleanup interval on component unmount or when session ends
209+
return () => {
210+
if (interval) {
211+
clearInterval(interval);
212+
}
213+
};
214+
}, [sessionStarted, timeRemaining]);
225215

226216
return (
227217
<div className="collaboration-window">
228-
<Timer sessionId={sessionId} userId={userId} setTimeRemaining={setTimeRemaining} socket={socket.current}/>
229-
<Popup open={popup}>
230-
<div className="modal">
231-
<div className="header"> Time Up </div>
232-
<div className="content">
233-
<div>Do you want to extend the time ?</div>
234-
</div>
235-
<div className="actions">
236-
<button className="button extend-popup" onClick={(e) => {handleExtendTimer(); onClosePopup()}}>
237-
Yes
238-
</button>
239-
<button className="button close-popup" onClick={(e) => {onClosePopup(); handleEndSession()}}>
240-
No
241-
</button>
242-
</div>
243-
</div>
244-
</Popup>
245-
<div className="timer-bar">
246-
<div className="left">
247-
<span className="time-remaining">Time remaining: {formatTime(timeRemaining)}</span>
248-
<button className="extend-time" onClick={handleExtendTimer}>Extend Timer</button>
249-
</div>
250-
<div className="right">
251-
<button className="end-session" onClick={handleEndSession}>End Session</button>
252-
</div>
253-
</div>
254-
<div className="content-area">
255-
<div className="question-section">
256-
{question && (
257-
<>
258-
<h2>{question.title}</h2>
259-
<p>{question.description}</p>
260-
</>
261-
)}
262-
</div>
218+
<Timer
219+
sessionId={sessionId}
220+
userId={userId}
221+
setTimeRemaining={setTimeRemaining}
222+
socket={socket.current}
223+
/>
224+
<Popup open={popup}>
225+
<div className="modal">
226+
<div className="header"> Time Up </div>
227+
<div className="content">
228+
<div>Do you want to extend the time ?</div>
229+
</div>
230+
<div className="actions">
231+
<button
232+
className="button extend-popup"
233+
onClick={(e) => {
234+
handleExtendTimer();
235+
onClosePopup();
236+
}}
237+
>
238+
Yes
239+
</button>
240+
<button
241+
className="button close-popup"
242+
onClick={(e) => {
243+
onClosePopup();
244+
handleEndSession();
245+
}}
246+
>
247+
No
248+
</button>
249+
</div>
250+
</div>
251+
</Popup>
252+
<div className="timer-bar">
253+
<div className="left">
254+
<span className="time-remaining">
255+
Time remaining: {formatTime(timeRemaining)}
256+
</span>
257+
<button className="extend-time" onClick={handleExtendTimer}>
258+
Extend Timer
259+
</button>
260+
</div>
261+
<div className="right">
262+
<button className="end-session" onClick={handleEndSession}>
263+
End Session
264+
</button>
265+
</div>
266+
</div>
267+
<div className="content-area">
268+
<div className="question-section">
269+
{question && (
270+
<>
271+
<h2>{question.title}</h2>
272+
<p>{question.description}</p>
273+
</>
274+
)}
275+
</div>
263276
<div className="editor-section">
264277
{/* Placeholder for code editor */}
265278
{/*<p>Code editor will go here...</p>*/}
@@ -285,4 +298,4 @@ const CollaborationWindow = () => {
285298
);
286299
};
287300

288-
export default CollaborationWindow;
301+
export default CollaborationWindow;

0 commit comments

Comments
 (0)