From 2df60eb8f521dd5793f84ae0c4244faebad0b0df Mon Sep 17 00:00:00 2001 From: 4gray Date: Thu, 17 Feb 2022 23:11:22 +0100 Subject: [PATCH] refactor: move `setPlaylist` to channel store --- src/app/state/channel.store.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/app/state/channel.store.ts b/src/app/state/channel.store.ts index a3c5831e5..19ec2ac1a 100644 --- a/src/app/state/channel.store.ts +++ b/src/app/state/channel.store.ts @@ -1,12 +1,14 @@ import { Injectable } from '@angular/core'; import { EntityState, EntityStore, StoreConfig } from '@datorama/akita'; import * as moment from 'moment'; +import { createChannel } from '.'; import { Channel } from '../../../shared/channel.interface'; import { CHANNEL_SET_USER_AGENT, EPG_GET_PROGRAM, PLAYLIST_UPDATE_FAVORITES, } from '../../../shared/ipc-commands'; +import { Playlist } from '../../../shared/playlist.interface'; import { EpgProgram } from '../player/models/epg-program.model'; import { DataService } from '../services/data.service'; @@ -137,4 +139,25 @@ export class ChannelStore extends EntityStore { currentEpgProgram, })); } + + /** + * Sets the given playlist as active for the current session + * @param playlist playlist object + */ + setPlaylist(playlist: Playlist): void { + this.remove(); + const favorites = playlist.favorites || []; + const channels = playlist.playlist.items.map((element) => + createChannel(element) + ); + this.upsertMany(channels); + this.update((store) => ({ + ...store, + active: undefined, + favorites, + playlistId: playlist._id, + playlistFilename: playlist.title || playlist.filename, + playlistCount: playlist.count, + })); + } }