From ae10abdc409c427f10b9ae1024246128d27bd77d Mon Sep 17 00:00:00 2001 From: barisgul15 <70471039+barisgul15@users.noreply.github.com> Date: Wed, 8 Nov 2023 01:38:48 +0100 Subject: [PATCH] Update main.ts (#1221) * Update main.ts pinnedCourses are added to recently. * Update main.ts eslint prettifier error, added an "enter" at line 39 * Update main.ts eslint prettifier errors are fixed. * Update main.ts eslint prettifier errors are fixed. --- web/ts/components/main.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/web/ts/components/main.ts b/web/ts/components/main.ts index 38e504bad..9e86302e6 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,25 @@ 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) { + // + const 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,6 +82,10 @@ 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]));