Skip to content

Commit 6e21697

Browse files
author
Aishwarya Nair
committed
fix history service bug with code fetching
1 parent 452b413 commit 6e21697

File tree

5 files changed

+219
-180
lines changed

5 files changed

+219
-180
lines changed

CollaborationService/database/collaborativeInputDb.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ const initCollaborativeCode = async (initTime, sessionId, language, userId) => {
4848
const input = await getCollaborativeInput(sessionId);
4949

5050
if (input[0] === "None") {
51+
if (language === "None") {
52+
language = "python";
53+
}
5154
const collaborativeInput = new CollaborativeInput({
5255
sessionId: sessionId,
5356
initTime: initTime,
@@ -158,7 +161,7 @@ const updateInitTime = async (sessionId, initTime) => {
158161
} catch (error) {
159162
console.log(`Failed to update init time for ${sessionId}`);
160163
}
161-
}
164+
};
162165

163166
const updateCollaborativeLanguage = async (sessionId, language) => {
164167
try {
@@ -203,7 +206,6 @@ const deleteCollaborativeInput = async (sessionId) => {
203206
console.log(`Successfully deleted:`, result);
204207

205208
return true;
206-
207209
} catch (error) {
208210
console.log(`Failed to delete collaborative input for ${sessionId}`);
209211

@@ -239,4 +241,4 @@ module.exports = {
239241
updateCollaborativeLanguage,
240242
deleteCollaborativeInput,
241243
deleteCollaborativeLineInput,
242-
};
244+
};
Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,58 @@
11
.attempt-container {
2-
display: flex;
3-
gap: 10px;
4-
background: #f6f6f6;
5-
padding: 0.1rem 0.1rem;
6-
border-radius: 5px;
7-
align-items: center;
8-
justify-content: space-between;
9-
-webkit-transition-duration: 0.2s; /* Safari */
10-
transition-duration: 0.2s;
2+
display: flex;
3+
gap: 10px;
4+
background: #f6f6f6;
5+
padding: 0.1rem 0.1rem;
6+
border-radius: 5px;
7+
align-items: center;
8+
justify-content: space-between;
9+
-webkit-transition-duration: 0.2s; /* Safari */
10+
transition-duration: 0.2s;
1111
}
1212

13-
.attempt-container:hover{
14-
box-shadow: rgba(149, 157, 165, 0.2) 0px 8px 24px;
15-
background: #e9e9e9;
13+
.attempt-container:hover {
14+
box-shadow: rgba(149, 157, 165, 0.2) 0px 8px 24px;
15+
background: #e9e9e9;
1616
}
1717

1818
.attempt-name {
19-
width: 60%;
20-
display: flex;
21-
align-items: center;
22-
min-height: 50px;
23-
font-size: 18px;
24-
overflow: hidden;
25-
font-weight: 500;
19+
width: fit-content;
20+
display: flex;
21+
align-items: center;
22+
min-height: 50px;
23+
font-size: 18px;
24+
overflow: hidden;
25+
font-weight: 500;
2626
}
2727

2828
.attempt-id {
29-
padding: 0.5rem 1rem;
29+
padding: 0.5rem 1rem;
3030
}
3131

3232
.attempt-title {
33-
padding: 0.5rem 0.5rem;
34-
overflow: hidden;
35-
text-overflow: ellipsis;
36-
white-space: nowrap;
33+
padding: 0.5rem 0.5rem;
34+
overflow: hidden;
35+
text-overflow: ellipsis;
36+
white-space: nowrap;
3737
}
3838

3939
.attempt-tags {
40-
padding: 0 1rem;
41-
display:flex;
42-
gap: 10px;
40+
width: fit-content;
41+
overflow: hidden;
42+
padding: 0 1rem;
43+
display: flex;
44+
gap: 10px;
45+
}
46+
47+
.attempt-tags div {
48+
overflow: hidden;
49+
text-overflow: ellipsis !important;
50+
white-space: nowrap;
51+
align-items: center;
52+
justify-content: space-between;
4353
}
4454

4555
.attempt-date {
46-
background: #E9E9E9;
47-
color: #A8A4A4;
56+
background: #e9e9e9;
57+
color: #a8a4a4;
4858
}
Lines changed: 79 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,83 @@
1-
import React, {useState, useEffect} from 'react'
2-
import "./AttemptView.css"
3-
import CodeEditor from '../Collaboration/CodeEditor'
4-
import Utility from "../../Utility/Utility"
5-
import axios from 'axios';
1+
import React, {useState, useEffect} from "react";
2+
import Editor from "@monaco-editor/react";
3+
import "./AttemptView.css";
4+
import Utility from "../../Utility/Utility";
5+
import axios from "axios";
66

7-
import back_icon from "../Assets/back.png"
7+
import back_icon from "../Assets/back.png";
88

9-
const COLLABORATION_SERVICE_HOST = "http://localhost:3005/";;
9+
const COLLABORATION_SERVICE_HOST = "http://localhost:3005/";
1010

1111
export const AttemptView = ({attempt, setIsList}) => {
12-
//to be replaced with attempt.code
13-
const [code, setCode] = useState("#Here is the code from your attempt");
14-
const [lang, setLang] = useState("python")
15-
16-
let tagClass = Utility.setDifficultyTag("user-q-tag", attempt.complexity);
17-
18-
const fetchCode = async () => {
19-
const result = await axios.get(COLLABORATION_SERVICE_HOST + "getCollaborationHistory/" + attempt.sessionId)
20-
21-
if (result.status === 200) {
22-
console.log(result)
23-
setCode(result.data.codes);
24-
setLang(result.data.language);
25-
}
26-
}
27-
28-
useEffect(() => {
29-
fetchCode();
30-
}, [])
31-
32-
return (
33-
<div className="attempt-view-container">
34-
<div className="back-container">
35-
<img src = {back_icon} className="back-button" alt = "" onClick = {() => setIsList(true)}/>
36-
</div>
37-
<div className="attempt-details-container">
38-
<div className="attempt-q">
39-
<div className="attempt-q-header">
40-
<div className="attempt-q-name">{attempt.questionTitle}</div>
41-
<div className="attempt-q-tags">
42-
<div className={tagClass}>{attempt.questionComplexity}</div>
43-
<div className="user-q-tag">{attempt.questionCategory}</div>
44-
</div>
45-
</div>
46-
<div className="attempt-q-desc">
47-
{attempt.questionDescription}
48-
</div>
49-
</div>
50-
<div className="attempt-code">
51-
{/* replace language with state variable - attempt.language*/}
52-
<CodeEditor code={code} setCode={setCode} language={lang} isReadOnly = {true}/>
53-
</div>
54-
</div>
55-
</div>
56-
)
57-
}
12+
//to be replaced with attempt.code
13+
const [code, setCode] = useState([]);
14+
const [lang, setLang] = useState("python");
15+
16+
let tagClass = Utility.setDifficultyTag("user-q-tag", attempt.complexity);
17+
18+
const fetchCode = async () => {
19+
const result = await axios.get(
20+
COLLABORATION_SERVICE_HOST +
21+
"getCollaborationHistory/" +
22+
attempt.sessionId
23+
);
24+
25+
if (result.status === 200) {
26+
console.log(result);
27+
setCode(result.data.codes);
28+
if (result.data.language === "None") {
29+
setLang(result.data.language);
30+
}
31+
}
32+
};
33+
34+
useEffect(() => {
35+
fetchCode();
36+
}, []);
37+
38+
const toCode = (collabInput) => {
39+
collabInput.sort((a, b) => {
40+
return a.line - b.line;
41+
});
42+
return collabInput.map((item) => item.code).join("\n");
43+
};
44+
45+
return (
46+
<div className="attempt-view-container">
47+
<div className="back-container">
48+
<img
49+
src={back_icon}
50+
className="back-button"
51+
alt=""
52+
onClick={() => setIsList(true)}
53+
/>
54+
</div>
55+
<div className="attempt-details-container">
56+
<div className="attempt-q">
57+
<div className="attempt-q-header">
58+
<div className="attempt-q-name">{attempt.questionTitle}</div>
59+
<div className="attempt-q-tags">
60+
<div className={tagClass}>{attempt.questionComplexity}</div>
61+
<div className="user-q-tag">{attempt.questionCategory}</div>
62+
</div>
63+
</div>
64+
<div className="attempt-q-desc">{attempt.questionDescription}</div>
65+
</div>
66+
<div className="attempt-code">
67+
<Editor
68+
language={lang.toLowerCase()}
69+
theme="vs-light"
70+
value={toCode(code)}
71+
options={{
72+
inlineSuggest: true,
73+
fontSize: "16px",
74+
formatOnType: true,
75+
minimap: {enabled: false},
76+
readOnly: true,
77+
}}
78+
/>
79+
</div>
80+
</div>
81+
</div>
82+
);
83+
};

0 commit comments

Comments
 (0)