From 12ba887dce677b457707e5d415a5dd00e9cab189 Mon Sep 17 00:00:00 2001 From: barisgul15 Date: Thu, 26 Oct 2023 14:31:44 +0200 Subject: [PATCH] Update main.ts pinnedCourses are added to recently. --- web/ts/components/main.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/web/ts/components/main.ts b/web/ts/components/main.ts index 38e504bad..cdab04ee8 100644 --- a/web/ts/components/main.ts +++ b/web/ts/components/main.ts @@ -9,6 +9,7 @@ export function mainContext(year: number, term: string) { term: term as string, publicCourses: [] as Course[], + pinnedCourses: [] as Course[], userCourses: [] as Course[], liveToday: [] as Course[], recently: new AutoPaginator([], 10, (c: Course) => c.LastRecording.FetchThumbnail()), @@ -26,15 +27,23 @@ export function mainContext(year: number, term: string) { reload(year: number, term: string) { this.year = year; this.term = term; - Promise.all([this.loadUserCourses(), this.loadPublicCourses()]) + Promise.all([this.loadUserCourses(), this.loadPublicCourses(), this.loadPinnedCourses()]) .catch((err) => { console.error(err); }) .then(() => { this.liveToday = this.getLiveToday(); if (this.userCourses.length > 0) { - this.recently.set(this.getRecently(this.userCourses)); - this.loadProgresses(this.userCourses.map((c) => c.LastRecording.ID)); + if (this.pinnedCourses.length > 0) { + // + let pinnedOrUserCourses : Course[] = this.userCourses.concat(this.pinnedCourses.filter((c : Course) => this.userCourses.indexOf(c) < 0)); + this.recently.set(this.getRecently(pinnedOrUserCourses)); + this.loadProgresses(pinnedOrUserCourses.map((c) => c.LastRecording.ID)); + } else { + // If user did not pin any course, just show the userCourses on recently VOD section + this.recently.set(this.getRecently(this.userCourses)); + this.loadProgresses(this.userCourses.map((c) => c.LastRecording.ID)); + } } else { this.recently.set(this.getRecently(this.publicCourses)); } @@ -71,9 +80,13 @@ export function mainContext(year: number, term: string) { this.userCourses = await CoursesAPI.getUsers(this.state.year, this.state.term); }, + async loadPinnedCourses() { + this.pinnedCourses = await CoursesAPI.getPinned(this.state.year, this.state.term); + }, + async loadProgresses(ids: number[]) { const progresses = await ProgressAPI.getBatch(ids); this.recently.forEach((r, i) => (r.LastRecording.Progress = progresses[i])); }, }; -} +} \ No newline at end of file