Skip to content

Commit ed36158

Browse files
committed
Fix bug in computing diff with previous backup
Caused by not fixing old code when reversing the chronological order of backups in the Timeline tab
1 parent e3e34b8 commit ed36158

1 file changed

Lines changed: 4 additions & 22 deletions

File tree

  • src/snapshots-app/client/bundles/components/submission/tabs/timeline

src/snapshots-app/client/bundles/components/submission/tabs/timeline/TimelineTab.jsx

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,15 @@ function TimelineTab() {
241241

242242
// Fetch previous backup file contents
243243
React.useEffect(() => {
244-
if (selectedBackup === 0 || backups.length === 0 || file === "") {
244+
if (backups.length === 0 || file === "") {
245245
return;
246246
}
247247

248248
const queryParams = new URLSearchParams();
249+
const prevBackupIndex = Math.min(selectedBackup + 1, backups.length - 1);
249250
queryParams.append(
250251
"object_key",
251-
`${backups[selectedBackup - 1].file_contents_location}/${file}`,
252+
`${backups[prevBackupIndex].file_contents_location}/${file}`,
252253
);
253254

254255
fetch(`/api/files?${queryParams}`, {
@@ -265,14 +266,6 @@ function TimelineTab() {
265266
});
266267
}, [backups, selectedBackup, file]);
267268

268-
const backupCreatedTimestamps = React.useMemo(() => {
269-
if (backups.length === 0) {
270-
return [];
271-
}
272-
273-
return backups.map((backup) => backup.created);
274-
}, [backups]);
275-
276269
function getTotalQuestionsSolved(history) {
277270
return history.reduce(
278271
(total, currQuestion) => total + (currQuestion.solved ? 1 : 0),
@@ -580,8 +573,7 @@ function TimelineTab() {
580573
height: "100%",
581574
}}
582575
>
583-
{selectedBackup === 0 ||
584-
code === "" ||
576+
{code === "" ||
585577
prevFileContents === "" ||
586578
prevFileContents === code ? (
587579
<BasicFileViewer
@@ -594,7 +586,6 @@ function TimelineTab() {
594586
<DiffViewer
595587
open={true}
596588
onClose={() => setDiffViewerOpen(false)}
597-
prevBackup={backups[selectedBackup - 1]}
598589
currentFileContents={code}
599590
selectedFile={file}
600591
prevFileContents={prevFileContents}
@@ -644,15 +635,6 @@ function TimelineTab() {
644635
/>
645636

646637
{getOutputDialog()}
647-
648-
{/* <DiffViewer
649-
open={diffViewerOpen}
650-
onClose={() => setDiffViewerOpen(false)}
651-
prevBackup={backups[selectedBackup - 1]}
652-
currentFileContents={code}
653-
selectedFile={file}
654-
prevFileContents={prevFileContents}
655-
/> */}
656638
</Box>
657639
);
658640
}

0 commit comments

Comments
 (0)