diff --git a/web/ts/api/admin-lecture-list.ts b/web/ts/api/admin-lecture-list.ts index 94d8e853b..bdd4fd82a 100644 --- a/web/ts/api/admin-lecture-list.ts +++ b/web/ts/api/admin-lecture-list.ts @@ -17,6 +17,11 @@ export interface UpdateLectureMetaRequest { isChatEnabled?: boolean; } +export interface UpdateLectureDateTimeRequest { + startDate: Date; + endTime: Date; +} + export class LectureFile { readonly id: number; readonly fileType: number; @@ -282,6 +287,19 @@ export const AdminLectureList = { await post(`/api/course/${courseId}/updateLectureSeries/${lectureId}`); }, + /** + * Updates date time of a lecture. + * @param courseId + * @param lectureId + * @param request + */ + updateDateTime: async function (courseId: number, lectureId: number, request: UpdateLectureDateTimeRequest) { + await post(`/api/course/${courseId}/updateDateTime/${lectureId}`, { + startDate: request.startDate, + endTime: request.endTime.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }), + }); + }, + /** * Add sections to a lecture * @param lectureId diff --git a/web/ts/data-store/admin-lecture-list.ts b/web/ts/data-store/admin-lecture-list.ts index c460a0cb5..b637d57d4 100644 --- a/web/ts/data-store/admin-lecture-list.ts +++ b/web/ts/data-store/admin-lecture-list.ts @@ -2,7 +2,7 @@ import { StreamableMapProvider } from "./provider"; import { AdminLectureList, Lecture, - LectureFile, + LectureFile, UpdateLectureDateTimeRequest, UpdateLectureMetaRequest, VideoSection, videoSectionSort, @@ -113,6 +113,22 @@ export class AdminLectureListProvider extends StreamableMapProvider { + if (s.lectureId === lectureId) { + return { + ...s, + start: payload.startDate, + end: payload.endTime, + }; + } + return s; + }); + await this.triggerUpdate(courseId); + } + async uploadAttachmentFile(courseId: number, lectureId: number, file: File) { const res = await AdminLectureList.uploadAttachmentFile(courseId, lectureId, file); const newFile = new LectureFile({ diff --git a/web/ts/edit-course.ts b/web/ts/edit-course.ts index 55bbf0e54..98cb20f4f 100644 --- a/web/ts/edit-course.ts +++ b/web/ts/edit-course.ts @@ -413,7 +413,7 @@ export function lectureEditor(lecture: Lecture): AlpineComponent { * Save changes send them to backend and commit change set. */ async saveEdit() { - const { courseId, lectureId, name, description, lectureHallId, isChatEnabled, videoSections } = + const { courseId, lectureId, name, description, lectureHallId, isChatEnabled, videoSections, start, end } = this.lectureData; const changedKeys = this.changeSet.changedKeys(); @@ -433,7 +433,7 @@ export function lectureEditor(lecture: Lecture): AlpineComponent { // Save new date and time if (changedKeys.includes("start") || changedKeys.includes("end")) { - + await DataStore.adminLectureList.updateDateTime(courseId, lectureId, { startDate: new Date(start), endTime: new Date(end) }); } // Saving VideoSections