diff --git a/web/ts/api/admin-lecture-list.ts b/web/ts/api/admin-lecture-list.ts index 9ef78740d..1fa9465df 100644 --- a/web/ts/api/admin-lecture-list.ts +++ b/web/ts/api/admin-lecture-list.ts @@ -348,7 +348,16 @@ export const AdminLectureList = { */ delete: async function (courseId: number, lectureIds: number[]): Promise { return await post(`/api/course/${courseId}/deleteLectures`, { - streamIDs: lectureIds, + streamIDs: lectureIds.map((id) => `${id}`), }); }, + + /** + * Delete lecture series of a lecture + * @param courseId + * @param lectureId + */ + deleteSeries: async function (courseId: number, lectureId: number): Promise { + return await del(`/api/course/${courseId}/deleteLectureSeries/${lectureId}`); + }, }; diff --git a/web/ts/data-store/admin-lecture-list.ts b/web/ts/data-store/admin-lecture-list.ts index 4712a24ca..ffbb539c5 100644 --- a/web/ts/data-store/admin-lecture-list.ts +++ b/web/ts/data-store/admin-lecture-list.ts @@ -71,6 +71,17 @@ export class AdminLectureListProvider extends StreamableMapProvider l.lectureId === lectureId)?.seriesIdentifier ?? null; + const lectureIds = lectures.filter((l) => l.seriesIdentifier === seriesIdentifier).map((l) => l.lectureId); + + this.data[courseId] = lectures.filter((s) => !lectureIds.includes(s.lectureId)); + await this.triggerUpdate(courseId); + } + async updateMeta(courseId: number, lectureId: number, props: UpdateMetaProps) { const updateSeries = props?.options?.saveSeries === true; const seriesIdentifier = diff --git a/web/ts/edit-course.ts b/web/ts/edit-course.ts index e71b44053..bc1d9f717 100644 --- a/web/ts/edit-course.ts +++ b/web/ts/edit-course.ts @@ -227,6 +227,14 @@ export function lectureEditor(lecture: Lecture): AlpineComponent { section.startSeconds < 60 ); }, + + deleteLecture() { + DataStore.adminLectureList.delete(this.lectureData.courseId, [this.lectureData.lectureId]); + }, + + deleteLectureSeries() { + DataStore.adminLectureList.deleteSeries(this.lectureData.courseId, this.lectureData.lectureId); + }, /** * Opens the series lecture editor UI @@ -884,10 +892,10 @@ export function createLectureForm(args: { s: [] }) { postData("/api/course/" + this.courseID + "/createLecture", payload) .then(async (res) => { const { ids } = await res.json(); - /*const url = new URL(window.location.href); + const url = new URL(window.location.href); url.hash = `lectures:${ids.join(",")}`; window.location.assign(url); - window.location.reload();*/ + window.location.reload(); }) .catch((e) => { console.log(e);