diff --git a/app/components/chat/LoadProblemButton.tsx b/app/components/chat/LoadProblemButton.tsx index 0996e466..974425b0 100644 --- a/app/components/chat/LoadProblemButton.tsx +++ b/app/components/chat/LoadProblemButton.tsx @@ -20,7 +20,7 @@ export function setLastLoadedProblem(problem: BoltProblem) { localStorage.setItem('loadedProblemId', problem.problemId); localStorage.setItem('loadedProblem', problemSerialized); } catch (error: any) { - // Remove loadedProblem, so we don't accidentally associate a solution with the wrong problem. + // Remove loadedProblem, so we don't accidentally associate (e.g. reproduction) data with the wrong problem. localStorage.removeItem('loadedProblem'); console.error( `Failed to set last loaded problem (size=${(problemSerialized.length / 1024).toFixed(2)}kb):`, diff --git a/app/components/sidebar/Menu.client.tsx b/app/components/sidebar/Menu.client.tsx index 745c5de8..e5064e8c 100644 --- a/app/components/sidebar/Menu.client.tsx +++ b/app/components/sidebar/Menu.client.tsx @@ -12,7 +12,7 @@ import { HistoryItem } from './HistoryItem'; import { binDates } from './date-binning'; import { useSearchFilter } from '~/lib/hooks/useSearchFilter'; import { SaveProblem } from './SaveProblem'; -import { SaveSolution } from './SaveSolution'; +import { SaveReproductionModal } from './SaveReproduction'; import { getNutIsAdmin } from '~/lib/replay/Problems'; const menuVariants = { @@ -140,7 +140,7 @@ export const Menu = () => { Problems - {getNutIsAdmin() && } + {getNutIsAdmin() && } (false); + const [savedReproduction, setSavedReproduction] = useState(false); const [problem, setProblem] = useState(null); - const handleSaveSolution = async () => { + const handleSaveReproduction = async () => { const loadId = toast.loading('Loading problem...'); try { - const savedProblem = await getOrFetchLastLoadedProblem(); + const lastProblem = await getOrFetchLastLoadedProblem(); - if (!savedProblem) { + if (!lastProblem) { toast.error('No problem loaded'); return; } - setProblem(savedProblem); - setFormData({ - evaluator: savedProblem.solution?.evaluator || '', - }); + setProblem(lastProblem); } finally { toast.dismiss(loadId); } - setSavedSolution(false); + setSavedReproduction(false); setIsModalOpen(true); }; - const handleInputChange = (e: React.ChangeEvent) => { - const { name, value } = e.target; - setFormData((prev) => ({ - ...prev, - [name]: value, - })); - }; - - const handleSubmitSolution = async () => { + const handleSubmitReproduction = async () => { if (!problem) { toast.error('No problem loaded'); return; } if (!isSimulatingOrHasFinished()) { - toast.error('No simulation found (neither in progress nor finished)'); + toast.error('No simulation data found (neither in progress nor finished)'); return; } @@ -80,9 +66,8 @@ export function SaveSolution() { toast.dismiss(loadId); } - toast.info('Submitting solution...'); - - console.log('SubmitSolution', formData); + toast.info('Submitting reproduction...'); + console.log('SubmitReproduction'); const simulationData = getLastUserSimulationData(); @@ -98,40 +83,33 @@ export function SaveSolution() { return; } - /* - * The evaluator is only present when the problem has been solved. - * We still create a "solution" object even if it hasn't been - * solved quite yet, which is used for working on the problem. - * + const reproData = { simulationData, messages }; + + /** * TODO: Split `solution` into `reproData` and `evaluator`. */ - const evaluator = formData.evaluator.length ? formData.evaluator : undefined; + const solution: BoltProblemSolution = { + evaluator: problem.solution?.evaluator, + ...reproData, + + /* + * TODO: Also store recordingId for easier debugging. + * recordingId, + */ + }; const problemUpdatePacket: BoltProblemInput = { + ...problem, version: 2, - title: problem.title, - description: problem.description, - username: problem.username, - repositoryContents: problem.repositoryContents, - status: evaluator ? BoltProblemStatus.Solved : BoltProblemStatus.Unsolved, - solution: { - simulationData, - messages, - evaluator, - - /* - * TODO: Also store recordingId for easier debugging. - * recordingId, - */ - }, + solution, }; await updateProblem(problem.problemId, problemUpdatePacket); - setSavedSolution(true); + setSavedReproduction(true); } catch (error: any) { - console.error('Error saving solution', error?.stack || error); - toast.error(`Error saving solution: ${error?.message}`); + console.error('Error saving reproduction', error?.stack || error); + toast.error(`Error saving reproduction: ${error?.message}`); } }; @@ -140,9 +118,9 @@ export function SaveSolution() { - Save Solution + Save Reproduction - {savedSolution && ( + {savedReproduction && ( <> -
Solution Saved
+
Reproduction Saved