Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/app/home/course/course.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,19 @@
}
</ion-col>
<ion-col size="12" size-lg [ngClass]="currentVideo ? 'scroll-area' : ''">
@if (list$ | async; as list) {
<ion-searchbar
(ionInput)="onSearchChange($event)"
placeholder="Search videos by title or lecturer..."
debounce="300">
</ion-searchbar>
@if (filteredList$ | async; as list) {
@if (list.length === 0 && searchQuery) {
<ion-card>
<ion-card-content>
No videos found matching "{{ searchQuery }}"
</ion-card-content>
</ion-card>
}
<ion-list>
@for (lecture of list; track lecture.id) {
<ion-item button (click)="viewVideo(lecture)"
Expand Down
26 changes: 26 additions & 0 deletions src/app/home/course/course.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
IonListHeader,
IonProgressBar,
IonRow,
IonSearchbar,
IonText,
IonTitle,
IonToolbar,
Expand Down Expand Up @@ -63,6 +64,7 @@ import {ModalEvaluationComponent} from './modal-evaluation.component';
IonLabel,
IonItem,
IonIcon,
IonSearchbar,
NgClass,
IonProgressBar,
AsyncPipe,
Expand All @@ -78,10 +80,13 @@ export class CoursePage implements OnInit, AfterViewInit, OnDestroy {
course: string;
courseId?: string;
list$: Observable<Lecture[]>;
filteredList$: Observable<Lecture[]>;
courseProgress = {
viewed: 0,
duration: 0
};
searchQuery = '';
searchQuery$ = new Subject<string>();
isAndroid = /Android/i.test(navigator.userAgent);
isIos = /iPad/i.test(navigator.userAgent) || /iPhone/i.test(navigator.userAgent);
lastPlayedVideoKey: number = null;
Expand Down Expand Up @@ -128,6 +133,10 @@ export class CoursePage implements OnInit, AfterViewInit, OnDestroy {
return EMPTY;
})
);

this.filteredList$ = combineLatest([this.list$, this.searchQuery$.pipe(startWith(''))]).pipe(
map(([videos, query]) => this.filterVideos(videos, query))
);
}

ngAfterViewInit() {
Expand Down Expand Up @@ -276,6 +285,23 @@ export class CoursePage implements OnInit, AfterViewInit, OnDestroy {
: videoInfo;
}

filterVideos(videos: Lecture[], query: string): Lecture[] {
if (!query.trim()) {
return videos;
}

const lowerQuery = query.toLowerCase();
return videos.filter(video =>
video.title.toLowerCase().includes(lowerQuery) ||
(video.lecturer && video.lecturer.toLowerCase().includes(lowerQuery))
);
}

onSearchChange(event: any) {
this.searchQuery = event.detail.value ?? '';
this.searchQuery$.next(this.searchQuery);
}

viewVideo(video: Lecture) {
video.sources = video.sources.filter(source => {
if (source.type === 'video/youtube') {
Expand Down