Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
b242062
First code to add numProblems sizer
jasonz6688 Apr 6, 2021
79d8257
Merge https://github.com/rocketden/main into numProblemsSlider
jasonz6688 Apr 6, 2021
8b5a242
adding tests
jasonz6688 Apr 6, 2021
5327ac6
first pass, not fully resolve issue with rest calls
jasonz6688 Apr 13, 2021
73183f0
to merge
jasonz6688 Apr 13, 2021
427b941
Merge branch 'numProblemsSlider' of https://github.com/rocketden/main
jasonz6688 Apr 13, 2021
0f14b51
responding to comments I can respond to
jasonz6688 Apr 14, 2021
e029262
Merge pull request #138 from rocketden/numProblemsSlider
jasonz6688 Apr 14, 2021
6d52dad
extra commit to run pipeline
jasonz6688 Apr 15, 2021
b9122f9
Let's see if this works
jasonz6688 Apr 16, 2021
98e6ed8
fix acc. yml rules
jasonz6688 Apr 16, 2021
3b7e4ea
Please let this website be right
jasonz6688 Apr 16, 2021
1a5200b
add back setstate function
jasonz6688 Apr 21, 2021
4e499fc
changing indexes so that dependency doesn't have to be added
jasonz6688 Apr 21, 2021
4817790
First pass fixing codeEditor
jasonz6688 Apr 22, 2021
c1a9cbd
Catching up
jasonz6688 Apr 22, 2021
79d3401
responding to some of Chris's comments
jasonz6688 Apr 24, 2021
1c622c0
using setCodeMap
jasonz6688 Apr 25, 2021
9f4a33a
resolve merge conflicts
jasonz6688 Apr 25, 2021
879e9a2
Merge branch 'stagingNumProblems' of https://github.com/CodeJoustHQ/m…
jasonz6688 Apr 25, 2021
382ed9b
fixing bugs
jasonz6688 Apr 27, 2021
d6f5c2e
Fixing final bugs
jasonz6688 Apr 28, 2021
202c52e
minute changes that I made while writing the PR
jasonz6688 Apr 29, 2021
620ebd0
Change so that submissions are used during reload page
jasonz6688 May 9, 2021
2788e35
some style changes
jasonz6688 May 12, 2021
e2927f2
responding to nits on PR
jasonz6688 May 19, 2021
383c6bb
committing and pushing to create a branch
jasonz6688 May 27, 2021
2341428
Fixing backend compilation
jasonz6688 May 28, 2021
fe35275
Merge Main into this
jasonz6688 Jun 3, 2021
4533ef3
works finally, fixed some, but not all bugs
jasonz6688 Jun 7, 2021
1bf1613
more final tweaks
jasonz6688 Jun 8, 2021
8860fdb
Address some comments
alankbi Jun 15, 2021
893b983
Merge pull request #167 from CodeJoustHQ/WereinEndGameNow
alankbi Jun 15, 2021
f337c45
Pull changes from main
alankbi Jun 16, 2021
ed4e3eb
Copy over changes to PlayerGameView.tsx file
alankbi Jun 16, 2021
14825f8
Get compiling and running with bugs
alankbi Jun 16, 2021
1e1d2c6
Get spectating and overall game working without major bugs
alankbi Jun 17, 2021
12d35a6
Implement score and time methods in backend mapper
alankbi Jun 18, 2021
ba3f9c1
Fix bug with incorrectly sorted leaderboard
alankbi Jun 18, 2021
ffb571f
Fix broken leaderboard tests
alankbi Jun 18, 2021
14c33c3
Clean up code for merging
alankbi Jun 20, 2021
5209fad
Merge branch 'main' of https://github.com/CodeJoustHQ/main into stagi…
jasonz6688 Jun 23, 2021
8c238fd
responding to first half of the nits
jasonz6688 Jun 27, 2021
bfdffb7
Merge branch 'stagingNumProblems' of https://github.com/CodeJoustHQ/m…
jasonz6688 Jun 27, 2021
5935480
Merge branch 'main' into stagingNumProblems
alankbi Jun 30, 2021
1be423b
final nits, hopefully
jasonz6688 Jul 1, 2021
907ed8c
fixing time and making solved array
jasonz6688 Jul 3, 2021
f546c74
making code SonarLint compliant
jasonz6688 Jul 6, 2021
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
7 changes: 4 additions & 3 deletions frontend/src/api/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import { Color } from './Color';

export type Player = {
user: User,
code: string,
language: string,
submissions: Submission[],
solved: boolean,
solved: boolean[],
color: Color,
};

Expand Down Expand Up @@ -41,12 +39,14 @@ export type RunSolutionParams = {
initiator: User,
input: string,
code: string,
problemIndex: number,
language: string,
};

export type SubmitSolutionParams = {
initiator: User,
code: string,
problemIndex: number,
language: string,
};

Expand All @@ -68,6 +68,7 @@ export enum SubmissionType {

export type Submission = {
code: string,
problemIndex: number,
language: string,
results: SubmissionResult[],
numCorrect: number,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/api/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export type UpdateSettingsParams = {
duration?: number,
problems?: ProblemIdParam[],
size?: number,
numProblems?: number,
};

export type ChangeHostParams = {
Expand Down
24 changes: 13 additions & 11 deletions frontend/src/components/card/LeaderboardCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Player } from '../../api/Game';
import { LowMarginText, SmallText } from '../core/Text';
import PlayerIcon from './PlayerIcon';
import { Color } from '../../api/Color';
import { useBestSubmission } from '../../util/Hook';
import { useGetScore, useGetSubmissionTime } from '../../util/Hook';

type ContentStyleType = {
isCurrentPlayer: boolean,
Expand Down Expand Up @@ -67,37 +67,39 @@ type LeaderboardCardProps = {
isCurrentPlayer: boolean,
place: number,
color: Color,
numProblems: number,
};

function LeaderboardCard(props: LeaderboardCardProps) {
const {
place, player, isCurrentPlayer, color,
place, player, isCurrentPlayer, color, numProblems,
} = props;

const [showHover, setShowHover] = useState(false);
const bestSubmission = useBestSubmission(player);
const score = useGetScore(player);
const time = useGetSubmissionTime(player);

const getScoreDisplay = () => {
if (!bestSubmission) {
return '0';
if (!score) {
return 0;
}
return `${bestSubmission.numCorrect}/${bestSubmission.numTestCases}`;
return score;
};

const getScorePercentage = () => {
if (!bestSubmission) {
if (!score) {
return '';
}
return ` ${Math.round((bestSubmission.numCorrect / bestSubmission.numTestCases) * 100)}%`;
return ` ${Math.round((score / numProblems) * 100)}%`;
};

const getSubmissionTime = () => {
if (!bestSubmission) {
if (!time) {
return 'Never';
}

const currentTime = new Date().getTime();
const diffMilliseconds = currentTime - new Date(bestSubmission.startTime).getTime();
const diffMilliseconds = currentTime - new Date(time).getTime();
const diffMinutes = Math.floor(diffMilliseconds / (60 * 1000));
return `${diffMinutes}m ago`;
};
Expand All @@ -113,7 +115,7 @@ function LeaderboardCard(props: LeaderboardCardProps) {
nickname={player.user.nickname}
active={Boolean(player.user.sessionId)}
/>
<LowMarginText bold={player.solved}>{`${place}.${getScorePercentage()}`}</LowMarginText>
<LowMarginText bold={player.solved.filter((element) => !element).length === 0}>{`${place}.${getScorePercentage()}`}</LowMarginText>

{showHover ? (
<HoverBar>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/game/Console.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function Console(props: ConsoleProps) {
// Default values
setTitle('Console');
setSubtitle('');
setInput(testCases[0].input);
setInput(testCases ? testCases[0].input : '');
setOutput('');
setConsoleOutput('');
}
Expand Down
60 changes: 47 additions & 13 deletions frontend/src/components/game/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,21 @@ import styled, { ThemeContext } from 'styled-components';
import Language, { fromString, languageToEditorLanguage } from '../../api/Language';
import { DefaultCodeType } from '../../api/Problem';

/**
* onLanguageChange - a callback, called when the currentLanguage changes
* onCodeChange - a callback, called when the code changes
* getCurrentLanguage - a function passed in, which can be called to get the current language
* defaultCodeMap - a map of all the default code for each problem and language
* currentProblem - the problem which is current being worked on
* liveCode - a string used for spectator view
*/
type EditorProps = {
onLanguageChange: ((language: Language) => void) | null,
onCodeChange: ((code: string) => void) | null,
codeMap: DefaultCodeType | null,
defaultLanguage: Language,
getCurrentLanguage: (() => Language) | null,
defaultCodeMap: DefaultCodeType[] | null,
defaultCode: string | null,
currentProblem: number,
liveCode: string | null,
};

Expand Down Expand Up @@ -89,17 +98,19 @@ const monacoEditorOptions: EditorConstructionOptions = {
// This function refreshes the width of Monaco editor upon change in container size
function ResizableMonacoEditor(props: EditorProps) {
const {
onLanguageChange, onCodeChange, codeMap, defaultLanguage,
defaultCode, liveCode,
onLanguageChange, onCodeChange, getCurrentLanguage,
defaultCodeMap, defaultCode, currentProblem, liveCode,
} = props;

const theme = useContext(ThemeContext);
const [currentLanguage, setCurrentLanguage] = useState<Language>(defaultLanguage);
const [codeEditor, setCodeEditor] = useState<monaco.editor.IStandaloneCodeEditor | null>(null);
const [codeMap, setCodeMap] = useState<DefaultCodeType[] | null>(defaultCodeMap);
const [previousProblem, setPreviousProblem] = useState<number>(0);
const [currentLanguage, setCurrentLanguage] = useState<Language>(Language.Java);

useEffect(() => {
setCurrentLanguage(defaultLanguage);
}, [defaultLanguage]);
setCodeMap(defaultCodeMap);
}, [defaultCodeMap]);

const handleEditorDidMount = (editor: monaco.editor.IStandaloneCodeEditor) => {
setCodeEditor(editor);
Expand All @@ -126,22 +137,45 @@ function ResizableMonacoEditor(props: EditorProps) {
const handleLanguageChange = (language: Language) => {
// Save the code for this language
if (codeMap != null && codeEditor != null) {
codeMap[currentLanguage] = codeEditor.getValue();
codeEditor.setValue(codeMap[language]);
const codeMapTemp = codeMap;
codeMapTemp[currentProblem][currentLanguage] = codeEditor.getValue();
setCodeMap(codeMapTemp);
codeEditor.setValue(codeMap[currentProblem][language]);
}

// Change the language and initial code for the editor
setCurrentLanguage(language);
// Call onLanguageChange
if (onLanguageChange) {
onLanguageChange(language);
}
};

// This hook will be called if the user switches the problem he or she is working on
useEffect(() => {
if (codeMap != null && codeEditor != null) {
codeEditor.setValue(codeMap[currentLanguage]);
if (codeMap[currentProblem] != null) {
const codeMapTemp = codeMap;

// If the value of the editor is not "Loading...", save it in the codeMap
if (codeEditor.getValue() !== 'Loading...') {
codeMapTemp[previousProblem][currentLanguage] = codeEditor.getValue();
}

setCodeMap(codeMapTemp);
setPreviousProblem(currentProblem);

// If getCurrentLanguage is defined, set currentLanguage to the returned value,
// which is the language that was last used for the new problem,
// and set the CodeEditor to be the code for the problem and language
if (getCurrentLanguage) {
setCurrentLanguage(getCurrentLanguage());
codeEditor.setValue(codeMap[currentProblem][getCurrentLanguage()]);
} else {
codeEditor.setValue(codeMap[currentProblem][currentLanguage]);
}
}
}
}, [currentLanguage, codeMap, codeEditor, setCodeEditor]);
}, [currentLanguage, codeMap, codeEditor, setCodeEditor, getCurrentLanguage,
currentProblem, previousProblem]);

return (
<Content>
Expand Down
Loading