From a6340e1d83bc1d71463350956dbc2284924f41c0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Simon=20K=C3=BCnzel?= <simonk@fsmpi.rwth-aachen.de>
Date: Tue, 22 Apr 2025 23:26:13 +0200
Subject: [PATCH] Clear download status on changes and allow unselecting a
 lecture

---
 src/videoag/course/DownloadManager.tsx | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/videoag/course/DownloadManager.tsx b/src/videoag/course/DownloadManager.tsx
index df1eb49..2c6e3f6 100644
--- a/src/videoag/course/DownloadManager.tsx
+++ b/src/videoag/course/DownloadManager.tsx
@@ -296,7 +296,7 @@ function DownloadAllLectureListItem({
 }: {
     lecture: lecture;
     selectedMediumId: int | undefined;
-    setSelectedMediumId: (mediumId: int) => void;
+    setSelectedMediumId: (mediumId: int | undefined) => void;
     isDownloading: boolean;
     downloadStatus: DownloadStatus | undefined;
 }) {
@@ -369,7 +369,9 @@ function DownloadAllLectureListItem({
                     className="form-check-input"
                     checked={selectedMediumId !== undefined}
                     disabled={isDownloading || media.length == 0}
-                    onChange={(e) => setSelectedMediumId(media[0].id)}
+                    onChange={(e) =>
+                        setSelectedMediumId(e.target.checked ? media[0].id : undefined)
+                    }
                 />
             </td>
             <td
@@ -461,17 +463,24 @@ export default function DownloadAllModal({ course }: { course: course }) {
             if (publishMedia.length > 0) newChosenMedia.set(lecture.id, publishMedia[0].id);
         }
         setChosenMediumIdByLectureId(newChosenMedia);
+        setDownloadStatus(undefined);
     };
     const selectNone = () => {
         if (isDownloading) return;
         setChosenMediumIdByLectureId(new Map());
+        setDownloadStatus(undefined);
     };
-    const setLectureToMediumId = (lecture_id: int, medium_id: int) => {
+    const setLectureToMediumId = (lecture_id: int, medium_id: int | undefined) => {
         if (isDownloading) return;
 
         const newChosenMedia = new Map(chosenMediumIdByLectureId);
-        newChosenMedia.set(lecture_id, medium_id);
+        if (medium_id !== undefined) {
+            newChosenMedia.set(lecture_id, medium_id);
+        } else {
+            newChosenMedia.delete(lecture_id);
+        }
         setChosenMediumIdByLectureId(newChosenMedia);
+        setDownloadStatus(undefined);
     };
     const setAllToQuality = (qualityToSet: string) => {
         if (isDownloading) return;
@@ -485,6 +494,7 @@ export default function DownloadAllModal({ course }: { course: course }) {
             }
         }
         setChosenMediumIdByLectureId(newChosenMedia);
+        setDownloadStatus(undefined);
     };
 
     const startDownloads = async () => {
-- 
GitLab