Skip to content

Commit

Permalink
Update main.ts (TUM-Dev#1221)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
barisgul15 committed Nov 8, 2023
1 parent e337d87 commit ae10abd
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 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,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));
}
Expand Down Expand Up @@ -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]));
Expand Down

0 comments on commit ae10abd

Please sign in to comment.