diff --git a/.gitignore b/.gitignore index bc4e2f22..fca8713e 100644 --- a/.gitignore +++ b/.gitignore @@ -36,4 +36,7 @@ yarn-error.log* /playwright/.cache/ # private folder where I store firebase admin key private -.env \ No newline at end of file +.env + +# ignore downloaded firebase data +/db_analysis/*.json \ No newline at end of file diff --git a/pages/[id].tsx b/pages/[id].tsx index 34c893c5..63e32a4e 100644 --- a/pages/[id].tsx +++ b/pages/[id].tsx @@ -30,13 +30,13 @@ import { useNullableUserContext } from '../src/context/UserContext'; import useUserPermission from '../src/hooks/useUserPermission'; import { SettingsModal } from '../src/components/settings/SettingsModal'; import { getSampleIndex } from '../src/components/JudgeInterface/Samples'; -import useJudgeResults from '../src/hooks/useJudgeResults'; import JudgeResult from '../src/types/judge'; import useUserFileConnection from '../src/hooks/useUserFileConnection'; import useUpdateUserDashboard from '../src/hooks/useUpdateUserDashboard'; import { ConfirmOverrideModal } from '../src/components/ConfirmOverrideModal'; import Link from 'next/link'; import Head from 'next/head'; +import useJudgeResults from '../src/context/JudgeResultsContext'; function EditorPage() { const { fileData, updateFileData } = useEditorContext(); @@ -51,6 +51,7 @@ function EditorPage() { const getMainEditorValue = useAtomValue(mainEditorValueAtom); const getInputEditorValue = useAtomValue(inputEditorValueAtom); const [judgeResults, setJudgeResults] = useJudgeResults(); + const [isCodeRunning, setIsCodeRunning] = useState(false); useUserFileConnection(); useUpdateUserDashboard(); @@ -74,11 +75,6 @@ function EditorPage() { const handleRunCode = () => { const problem = fileData.settings.problem; - const setIsRunning = (isRunning: boolean) => { - updateFileData({ - isCodeRunning: isRunning, - }); - }; const fetchJudge = ( code: string, input: string, @@ -113,7 +109,7 @@ function EditorPage() { return; } - setIsRunning(true); + setIsCodeRunning(true); setResultAt(inputTabIndex, null); const code = getMainEditorValue(); @@ -133,7 +129,7 @@ function EditorPage() { ); console.error(e); }) - .finally(() => setIsRunning(false)); + .finally(() => setIsCodeRunning(false)); }; const runAllSamples = async () => { @@ -143,7 +139,7 @@ function EditorPage() { } const samples = problem.samples; - setIsRunning(true); + setIsCodeRunning(true); setResultAt(1, null); const code = getMainEditorValue(); @@ -206,7 +202,7 @@ function EditorPage() { } catch (e) { console.error(e); } - setIsRunning(false); + setIsCodeRunning(false); }; if (inputTab === 'input') { @@ -234,7 +230,7 @@ function EditorPage() { runButton={ } diff --git a/src/components/Workspace/Workspace.tsx b/src/components/Workspace/Workspace.tsx index 278ffd7c..2a9bc62a 100644 --- a/src/components/Workspace/Workspace.tsx +++ b/src/components/Workspace/Workspace.tsx @@ -27,11 +27,12 @@ import { Output } from '../Output'; import { TabBar } from '../TabBar'; import { UserList } from '../UserList/UserList'; import Samples from '../JudgeInterface/Samples'; -import useJudgeResults from '../../hooks/useJudgeResults'; import { useEditorContext } from '../../context/EditorContext'; import useUserPermission from '../../hooks/useUserPermission'; import { useUserContext } from '../../context/UserContext'; import { Sample } from '../JudgeInterface/Samples'; +import useJudgeResults from '../../context/JudgeResultsContext'; + export type ProblemData = { id: number; submittable: boolean; diff --git a/src/components/settings/SettingsModal.tsx b/src/components/settings/SettingsModal.tsx index 57f19ea2..910b6469 100644 --- a/src/components/settings/SettingsModal.tsx +++ b/src/components/settings/SettingsModal.tsx @@ -20,11 +20,11 @@ import JudgeSettings from './JudgeSettings'; import SignInSettings from './SignInSettings'; import JudgeResult from '../../types/judge'; -import useJudgeResults from '../../hooks/useJudgeResults'; import { EditorMode, useUserContext } from '../../context/UserContext'; import { FileSettings, useEditorContext } from '../../context/EditorContext'; import useUserPermission from '../../hooks/useUserPermission'; import firebase from 'firebase/app'; +import useJudgeResults from '../../context/JudgeResultsContext'; export interface SettingsDialogProps { isOpen: boolean; diff --git a/src/context/EditorContext.tsx b/src/context/EditorContext.tsx index 92ff6890..5f10b4e3 100644 --- a/src/context/EditorContext.tsx +++ b/src/context/EditorContext.tsx @@ -38,10 +38,6 @@ export type FileData = { }; }; settings: FileSettings; - isCodeRunning: boolean; - state: { - judge_resuts: any; // ??? - }; chat: { [key: string]: Omit; }; diff --git a/src/context/JudgeResultsContext.tsx b/src/context/JudgeResultsContext.tsx new file mode 100644 index 00000000..99c95ae7 --- /dev/null +++ b/src/context/JudgeResultsContext.tsx @@ -0,0 +1,30 @@ +import { createContext, useContext, useState } from 'react'; +import JudgeResult from '../types/judge'; + +const JudgeResultsContext = createContext< + [(JudgeResult | null)[], (newResults: (JudgeResult | null)[]) => void] | null +>(null); + +export default function useJudgeResults() { + const context = useContext(JudgeResultsContext); + if (context === null) { + throw new Error( + 'useJudgeResults must be used within an JudgeResultsProvider' + ); + } + + return context; +} + +export function JudgeResultsProvider({ + children, +}: { + children: React.ReactNode; +}) { + const state = useState<(JudgeResult | null)[]>([]); + return ( + + {children} + + ); +} diff --git a/src/hooks/useJudgeResults.ts b/src/hooks/useJudgeResults.ts deleted file mode 100644 index 15955e4d..00000000 --- a/src/hooks/useJudgeResults.ts +++ /dev/null @@ -1,15 +0,0 @@ -import firebase from 'firebase/app'; -import { useEditorContext } from '../context/EditorContext'; -import JudgeResult from '../types/judge'; -import useFirebaseState from './useFirebaseState'; - -export default function useJudgeResults() { - const { fileData, updateFileData } = useEditorContext(); - return [ - fileData.state?.judge_resuts ?? [], - (new_judge_results: any) => - updateFileData({ - state: { ...fileData.state, judge_resuts: new_judge_results }, - }), - ]; -}