Skip to content

Commit

Permalink
Update main.ts
Browse files Browse the repository at this point in the history
pinnedCourses are added to recently.
  • Loading branch information
barisgul15 committed Oct 26, 2023
1 parent e337d87 commit 12ba887
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions web/ts/components/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Course>([], 10, (c: Course) => c.LastRecording.FetchThumbnail()),
Expand All @@ -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));
}
Expand Down Expand Up @@ -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]));
},
};
}
}

0 comments on commit 12ba887

Please sign in to comment.