Skip to content

Commit

Permalink
feat: implement channel groups view
Browse files Browse the repository at this point in the history
  • Loading branch information
4gray committed Jul 4, 2020
1 parent 8551ffd commit 773e1ed
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@

.active {
background: #ddd;
}
}

.mat-list-base {
padding-top: 0;
}

::ng-deep .mat-expansion-panel-body {
padding: 0 !important;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,21 @@
</mat-list-item>
</mat-list>
<mat-nav-list id="channels-list">
<mat-list-item *ngFor=" let channel of channelList | filterBy: searchTerm; index as i"
[class.active]="selected?.id === channel.id" (click)="selectChannel(channel)">
{{i+1 + '. ' + channel?.name || 'Unnamed Channel'}}
<mat-divider></mat-divider>
</mat-list-item>
<mat-accordion class="example-headers-align" multi>
<ng-container *ngFor="let groups of channelList | keyvalue">
<mat-expansion-panel *ngIf="groups.value.length > 0">
<mat-expansion-panel-header>
{{groups.key || 'Ungrouped'}} ({{groups.value.length}})
</mat-expansion-panel-header>

<mat-list-item
*ngFor="let channel of groups.value | filterBy: searchTerm; index as i"
[class.active]="selected?.id === channel.id" (click)="selectChannel(channel)">
{{i+1 + '. ' + channel?.name || 'Unnamed Channel'}}
<mat-divider></mat-divider>
</mat-list-item>
</mat-expansion-panel>

</ng-container>
</mat-accordion>
</mat-nav-list>
16 changes: 8 additions & 8 deletions src/app/components/video-player/video-player.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { Component, OnInit, ViewChild } from '@angular/core';
import * as Hls from 'hls.js';
import { ChannelQuery, Channel } from 'src/app/state';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { MatSidenav } from '@angular/material/sidenav';
import * as _ from 'lodash';

@Component({
selector: 'app-video-player',
Expand Down Expand Up @@ -41,7 +43,9 @@ export class VideoPlayerComponent implements OnInit {
* Sets video player and subscribes to channel list from the store
*/
ngOnInit(): void {
this.channels$ = this.channelQuery.selectAll();
this.channels$ = this.channelQuery
.selectAll()
.pipe(map((channels) => _.groupBy(channels, 'group.title')));
this.videoPlayer = document.getElementById(
'video-player'
) as HTMLVideoElement;
Expand All @@ -58,16 +62,12 @@ export class VideoPlayerComponent implements OnInit {
* Starts to play the given channel
* @param channel given channel object
*/
playChannel(channel: { url: string; title: string }): void {
playChannel(channel: Channel): void {
if (Hls.isSupported()) {
console.log(
'... switching channel to ',
channel.title,
channel.url
);
console.log('... switching channel to ', channel.name, channel.url);
this.hls.loadSource(channel.url);
this.hls.attachMedia(this.videoPlayer);
this.channelTitle = channel.title;
this.channelTitle = channel.name;
} else if (
this.videoPlayer.canPlayType('application/vnd.apple.mpegurl')
) {
Expand Down
2 changes: 2 additions & 0 deletions src/app/material.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NgModule } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
import { MatExpansionModule } from '@angular/material/expansion';
import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';
import { MatListModule } from '@angular/material/list';
Expand All @@ -13,6 +14,7 @@ import { MatSnackBarModule } from '@angular/material/snack-bar';
exports: [
MatButtonModule,
MatCardModule,
MatExpansionModule,
MatIconModule,
MatInputModule,
MatListModule,
Expand Down
11 changes: 4 additions & 7 deletions src/app/state/channel.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ import { Channel } from './channel.model';
export interface ChannelState extends EntityState<Channel> {}

@Injectable({ providedIn: 'root' })
@StoreConfig({ name: 'channel' })
@StoreConfig({ name: 'channel', resettable: true })
export class ChannelStore extends EntityStore<ChannelState> {

constructor() {
super();
}

constructor() {
super();
}
}

0 comments on commit 773e1ed

Please sign in to comment.