Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve code editor frontend styling #45

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 28 additions & 19 deletions frontend/src/components/CodeContainer/CodeContainer.scss
Original file line number Diff line number Diff line change
@@ -1,62 +1,71 @@
.CodeContainer {
display: flex;
justify-content: space-between;

.left-side {
flex: 0.4;
padding: 10px;
width: 35%;
color: #fff;
display: flex;
flex-direction: column;
flex-direction: row;

.md-editor {
background-color: #1e1e1e;
border-radius: 10px;
border: 1px solid #3c3c3c;
padding: 20px;
color: #fff;
height: 500px;
overflow: auto;
}
}

.right-side {
flex: 0.6;
padding: 10px;
width: 63%;
max-width: 63%;
color: #fff;
display: flex;
flex-direction: column;

.right-side-container {
background-color: #2c2c2c;
border-radius: 10px;
border: 1px solid #3c3c3c;
}

.header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
margin-inline: 10px;

.language-select {
background-color: #1e1e1e;
color: #fff;
border: 1px solid #3c3c3c;
padding: 5px;
border-radius: 10px !important;
margin: 0px;
}

.language-select-icon {
color: white !important;
}

.buttons {
display: flex;
gap: 20px;
}

.runcode-button {
border-radius: 5px;
}

.submit-button {
background-color: #caff33;
color: #121212;
border-radius: 5px;

&.disabled {
color: #6c757d;
}
}
}

.code-editor {
background-color: #1e1e1e;
border-radius: 10px;
border: 1px solid #3c3c3c;
color: #fff;
overflow: hidden;
font-size: 18px;
height: 500px;
}
}

Expand Down
75 changes: 47 additions & 28 deletions frontend/src/components/CodeContainer/CodeContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { useMainDialog } from "../../contexts/MainDialogContext";
import QuestionService from "../../services/question.service";
import { SessionContext } from "../../contexts/SessionContext";
import { UserContext } from "../../contexts/UserContext";
import { Button, Typography } from "@mui/material";
import { Button, MenuItem, Select, SelectChangeEvent, Typography } from "@mui/material";
import { useNavigate } from "react-router-dom";
import "./CodeContainer.scss";
import HintBox from "../HintBox/HintBox";
Expand Down Expand Up @@ -285,7 +285,7 @@ const CodeContainer: React.FC<CodeContainerProps> = ({
[sid: string]: { cursor_position: number; color: string };
}>({});

const handleLanguageChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
const handleLanguageChange = (e: SelectChangeEvent) => {
const newLanguage = e.target.value as Language;
if (["python", "cpp", "javascript", "java"].includes(newLanguage)) {
setLanguage(newLanguage);
Expand Down Expand Up @@ -420,36 +420,55 @@ const CodeContainer: React.FC<CodeContainerProps> = ({
</div>

<div className="right-side">
<div className="header">
<select className="language-select" onChange={handleLanguageChange} value={language}>
<option value="python">Python</option>
<option value="cpp">C++</option>
<option value="java">Java</option>
</select>
<div>
<Button
variant="contained"
<div className="right-side-container">
<div className="header">
<Select
className="language-select"
value={language}
size="small"
className={"submit-button" + (isExecuting ? " disabled" : "")}
onClick={executeCode}
disabled={isExecuting}
autoWidth
onChange={handleLanguageChange}
inputProps={{
classes: {
icon: "language-select-icon",
},
}}
>
Run Code
</Button>
<Button variant="contained" size="small" onClick={submitAndEndSession} disabled={isExecuting}>
Submit
</Button>
<MenuItem value="python">Python</MenuItem>
<MenuItem value="cpp">C++</MenuItem>
<MenuItem value="java">Java</MenuItem>
</Select>
<div className="buttons">
<Button
variant="outlined"
size="small"
className="runcode-button"
onClick={executeCode}
disabled={isExecuting}
>
Run Code
</Button>
<Button
className="submit-button"
variant="contained"
size="small"
onClick={submitAndEndSession}
disabled={isExecuting}
>
Submit
</Button>
</div>
</div>
<CodeMirror
value={code}
className={"code-editor"}
height="500px"
extensions={[...(languageExtensions[language] || []), cursorDecorationsExtension]}
onChange={handleCodeChange}
onUpdate={(viewUpdate) => handleCursorChange(viewUpdate)}
theme={okaidia}
/>
</div>
<CodeMirror
value={code}
height="500px"
style={{ fontSize: "18px" }}
extensions={[...(languageExtensions[language] || []), cursorDecorationsExtension]}
onChange={handleCodeChange}
onUpdate={(viewUpdate) => handleCursorChange(viewUpdate)}
theme={okaidia}
/>
</div>

{/* Floating AI Hint Button */}
Expand Down
13 changes: 13 additions & 0 deletions frontend/src/components/QuestionContainer/QuestionContainer.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
.question-container {
margin-bottom: 20px;
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;

.question-header {
display: flex;
flex-direction: column;
}

.question-title {
margin-bottom: 10px;
Expand All @@ -18,4 +27,8 @@
border-radius: 6px;
}
}

.leave-button {
margin-right: 20px;
}
}
60 changes: 45 additions & 15 deletions frontend/src/components/QuestionContainer/QuestionContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,61 @@
import { Chip, Typography } from "@mui/material";
import { ReactElement } from "react";
import { Button, Chip, Typography } from "@mui/material";
import { ReactElement, useContext } from "react";
import OpenInNewIcon from "@mui/icons-material/OpenInNew";
import { Question } from "../../models/question.model";
import Spinner from "../Spinner/Spinner";
import "./QuestionContainer.scss";
import { useConfirmationDialog } from "../../contexts/ConfirmationDialogContext";
import { SessionContext } from "../../contexts/SessionContext";
import { useNavigate } from "react-router-dom";

const QuestionContainer = (props: { questionData: Question | null }): ReactElement => {
const { questionData } = props;
const { setConfirmationDialogTitle, setConfirmationDialogContent, setConfirmationCallBack, openConfirmationDialog } =
useConfirmationDialog();
const { clearSession } = useContext(SessionContext);
const navigate = useNavigate();

return (
<div>
{questionData ? (
<div className="question-container">
<Typography variant="h3" className="question-title">
{questionData?.title}
</Typography>
<div className="question-header">
<Typography variant="h3" className="question-title">
{questionData?.title}
</Typography>

<div className="details">
<Chip label={`Difficulty: ${questionData?.complexity}`} className="detail-chip light-grey-chip" />
<Chip label={`Topic: ${questionData?.categories.join(", ")}`} className="detail-chip light-grey-chip" />
<Chip
label={`URL: ${questionData?.link}`}
className="detail-chip light-grey-chip"
clickable
onClick={() => window.open(questionData?.link, "_blank")}
icon={<OpenInNewIcon style={{ color: "#caff33" }} />}
/>
<div className="details">
<Chip label={`Difficulty: ${questionData?.complexity}`} className="detail-chip light-grey-chip" />
<Chip label={`Topic: ${questionData?.categories.join(", ")}`} className="detail-chip light-grey-chip" />
<Chip
label={`URL: ${questionData?.link}`}
className="detail-chip light-grey-chip"
clickable
onClick={() => window.open(questionData?.link, "_blank")}
icon={<OpenInNewIcon style={{ color: "#caff33" }} />}
/>
</div>
</div>

<div>
<Button
variant="outlined"
color="error"
className="leave-button"
onClick={() => {
setConfirmationDialogTitle("Leave Session");
setConfirmationDialogContent(
"Are you sure you want to leave the session?\nYou will be able to rejoin if your partner is still in the session.",
);
setConfirmationCallBack(() => () => {
clearSession();
navigate("/");
});
openConfirmationDialog();
}}
>
Leave Session
</Button>
</div>
</div>
) : (
Expand Down
4 changes: 0 additions & 4 deletions frontend/src/pages/CodeEditor/CodeEditor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
background: var(--Grey-10, #1a1a1a);
}

.buttons {
margin: 10px;
}

.chatbox-icon {
z-index: 100;
position: fixed;
Expand Down
22 changes: 0 additions & 22 deletions frontend/src/pages/CodeEditor/CodeEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import QuestionService from "../../services/question.service";
import { UserContext } from "../../contexts/UserContext";
import { ChatMessage } from "../../models/communication.model";
import { SessionContext, SessionState } from "../../contexts/SessionContext";
import { useConfirmationDialog } from "../../contexts/ConfirmationDialogContext";
import Peer, { MediaConnection } from "peerjs";
import TestCases from "../../components/TestCases/TestCases";
import { Circle } from "@mui/icons-material";
Expand All @@ -25,8 +24,6 @@ const VIDEO_PEER_SERVICE_PORT = process.env.REACT_APP_VIDEO_SERVICE_PORT;
const CodeEditor: React.FC = () => {
const { user } = useContext(UserContext);
const { sessionState, questionId, clearSession, otherUserId, otherUserProfile } = useContext(SessionContext);
const { setConfirmationDialogTitle, setConfirmationDialogContent, setConfirmationCallBack, openConfirmationDialog } =
useConfirmationDialog();
const navigate = useNavigate();

const { roomNumber } = useParams();
Expand Down Expand Up @@ -314,25 +311,6 @@ const CodeEditor: React.FC = () => {
setCustomTestCases={setCustomTestCases}
/>
</div>

<div className="buttons">
<Button
variant="contained"
color="error"
className="buttons-leave"
onClick={() => {
setConfirmationDialogTitle("Leave Session");
setConfirmationDialogContent("Are you sure you want to leave the session?");
setConfirmationCallBack(() => () => {
clearSession();
navigate("/");
});
openConfirmationDialog();
}}
>
Leave Session
</Button>
</div>
</div>

{/* Floating Chatbox Icon */}
Expand Down
Loading