From 0bc71d47911c9b87cbe92f20f7d024c0027349e1 Mon Sep 17 00:00:00 2001 From: 4gray Date: Sat, 19 Feb 2022 23:40:59 +0100 Subject: [PATCH] feat: switch playlists from the sidebar --- api.ts | 1 + src/app/home/home.component.ts | 40 +++------ .../channel-list-container.component.html | 44 +++++++--- .../channel-list-container.component.scss | 30 ++++++- .../channel-list-container.component.ts | 19 ++++ .../video-player/video-player.component.html | 19 +++- .../video-player/video-player.component.ts | 88 +++++++++++++++++-- 7 files changed, 186 insertions(+), 55 deletions(-) diff --git a/api.ts b/api.ts index e635dbf98..1f99c5fd6 100644 --- a/api.ts +++ b/api.ts @@ -328,6 +328,7 @@ export class Api { count: 1, title: 1, _id: 1, + id: 1, url: 1, importDate: 1, userAgent: 1, diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index c837ca070..8812eb4bf 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -1,10 +1,8 @@ -import { TranslateService } from '@ngx-translate/core'; import { Component, NgZone } from '@angular/core'; -import { UploadFile } from 'ngx-uploader'; -import { ChannelStore, createChannel } from '../state'; -import { Router } from '@angular/router'; import { MatSnackBar } from '@angular/material/snack-bar'; -import { Playlist } from '../../../shared/playlist.interface'; +import { Router } from '@angular/router'; +import { TranslateService } from '@ngx-translate/core'; +import { UploadFile } from 'ngx-uploader'; import { ERROR, PLAYLIST_GET_ALL, @@ -18,8 +16,10 @@ import { PLAYLIST_UPDATE, PLAYLIST_UPDATE_RESPONSE, } from '../../../shared/ipc-commands'; -import { DialogService } from './../services/dialog.service'; +import { Playlist } from '../../../shared/playlist.interface'; import { DataService } from '../services/data.service'; +import { ChannelStore } from '../state'; +import { DialogService } from './../services/dialog.service'; /** Type to describe meta data of a playlist */ export type PlaylistMeta = Pick< @@ -51,8 +51,10 @@ export class HomeComponent { commandsList = [ { id: PLAYLIST_PARSE_RESPONSE, - execute: (response: { payload: Playlist }): void => - this.setPlaylist(response.payload), + execute: (response: { payload: Playlist }): void => { + this.channelStore.setPlaylist(response.payload); + this.navigateToPlayer(); + }, }, { id: PLAYLIST_GET_ALL_RESPONSE, @@ -97,9 +99,9 @@ export class HomeComponent { */ constructor( private electronService: DataService, - private channelStore: ChannelStore, private dialogService: DialogService, private ngZone: NgZone, + private channelStore: ChannelStore, private router: Router, private snackBar: MatSnackBar, private translate: TranslateService @@ -175,26 +177,6 @@ export class HomeComponent { }); } - /** - * Sets the given playlist as active for the current session - * @param playlist playlist object - */ - setPlaylist(playlist: Playlist): void { - this.channelStore.remove(); - const favorites = playlist.favorites || []; - const channels = playlist.playlist.items.map((element) => - createChannel(element) - ); - this.channelStore.upsertMany(channels); - this.channelStore.update((store) => ({ - ...store, - active: undefined, - favorites, - playlistId: playlist.id, - })); - this.navigateToPlayer(); - } - /** * Triggers on remove click * @param playlistId playlist id to remove diff --git a/src/app/player/components/channel-list-container/channel-list-container.component.html b/src/app/player/components/channel-list-container/channel-list-container.component.html index eb2b7b722..dafcab6f2 100644 --- a/src/app/player/components/channel-list-container/channel-list-container.component.html +++ b/src/app/player/components/channel-list-container/channel-list-container.component.html @@ -1,3 +1,29 @@ +
+
+ +
+
{{ playlistMeta?.filename }}
+
{{ playlistMeta?.count }} channels
+
+ + +
+
+ @@ -6,20 +32,9 @@ class="full-width search-bar" type="search" #search - placeholder="{{ 'CHANNELS.SEARCH_CHANNEL' | translate }} ({{ - _channelList?.length - }})" + [placeholder]="'CHANNELS.SEARCH_CHANNEL' | translate" [(ngModel)]="searchTerm.name" /> - @@ -99,7 +114,10 @@ - + = { + count: this.channelQuery.getValue().playlistCount, + filename: this.channelQuery.getValue().playlistFilename, + }; + + /** Toggles the sidebar view from channels to playlists */ + @Output() changeView = new EventEmitter(); + /** Object with channels sorted by groups */ groupedChannels: { [key: string]: Channel[] }; @@ -106,4 +118,11 @@ export class ChannelListContainerComponent { trackByFn(index: number, channel: Channel): string { return channel.id; } + + /** + * Emits event to the parent to toggle to the playlists overview + */ + showPlaylists() { + this.changeView.emit('PLAYLISTS'); + } } diff --git a/src/app/player/components/video-player/video-player.component.html b/src/app/player/components/video-player/video-player.component.html index 9fce54e64..43eddeacc 100644 --- a/src/app/player/components/video-player/video-player.component.html +++ b/src/app/player/components/video-player/video-player.component.html @@ -8,8 +8,19 @@ disableClose > - + + + + + @@ -32,13 +43,13 @@ > {{ - (favorites$ | async).includes(activeChannel.id) + (favorites$ | async).includes(activeChannel?.id) ? 'star' : 'star_outline' }} - {{ activeChannel.name }} + {{ activeChannel?.name }}