Skip to content

Commit

Permalink
add frontend calls
Browse files Browse the repository at this point in the history
  • Loading branch information
mono424 committed Sep 27, 2023
1 parent 957dae1 commit 3aa37df
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
18 changes: 18 additions & 0 deletions web/ts/api/admin-lecture-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion web/ts/data-store/admin-lecture-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { StreamableMapProvider } from "./provider";
import {
AdminLectureList,
Lecture,
LectureFile,
LectureFile, UpdateLectureDateTimeRequest,
UpdateLectureMetaRequest,
VideoSection,
videoSectionSort,
Expand Down Expand Up @@ -113,6 +113,22 @@ export class AdminLectureListProvider extends StreamableMapProvider<number, Lect
await this.triggerUpdate(courseId);
}

async updateDateTime(courseId: number, lectureId: number, payload: UpdateLectureDateTimeRequest) {
await AdminLectureList.updateDateTime(courseId, lectureId, payload);

this.data[courseId] = (await this.getData(courseId)).map((s) => {
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({
Expand Down
4 changes: 2 additions & 2 deletions web/ts/edit-course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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
Expand Down

0 comments on commit 3aa37df

Please sign in to comment.