From 0b1e0b0d5840914512b3a1303f87b8e649ef7c7d Mon Sep 17 00:00:00 2001 From: 4gray Date: Sat, 11 Apr 2026 18:37:38 +0200 Subject: [PATCH] fix(xtream): streamline serial details initialization and loading logic --- .../serial-details.component.ts | 45 ++++++++++++++----- 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/libs/portal/xtream/feature/src/lib/serial-details/serial-details.component.ts b/libs/portal/xtream/feature/src/lib/serial-details/serial-details.component.ts index 3e6ac3836..ad6013557 100644 --- a/libs/portal/xtream/feature/src/lib/serial-details/serial-details.component.ts +++ b/libs/portal/xtream/feature/src/lib/serial-details/serial-details.component.ts @@ -64,6 +64,7 @@ export class SerialDetailsComponent implements OnInit, OnDestroy { readonly currentPlaylistId = signal(''); readonly xtreamDownloadContext = signal(null); + private readonly detailsInitDone = signal(false); private lastSaveTime = 0; private unsubscribePositionUpdates: (() => void) | null = null; readonly openingEpisodeId = signal(null); @@ -100,6 +101,17 @@ export class SerialDetailsComponent implements OnInit, OnDestroy { ); }); + effect(() => { + const playlistId = this.xtreamStore.currentPlaylist()?.id; + const { categoryId, serialId } = this.route.snapshot.params; + if (!playlistId || this.detailsInitDone()) { + return; + } + + this.initializeSerialDetails(playlistId, categoryId, serialId); + this.detailsInitDone.set(true); + }); + effect(() => { const session = this.externalPlayback.activeSession(); const selectedItem = this.selectedItem(); @@ -157,19 +169,14 @@ export class SerialDetailsComponent implements OnInit, OnDestroy { } ngOnInit(): void { + const currentPlaylist = this.xtreamStore.currentPlaylist(); + if (!currentPlaylist?.id) { + return; + } + const { categoryId, serialId } = this.route.snapshot.params; - this.xtreamStore.fetchSerialDetailsWithMetadata({ - serialId, - categoryId, - }); - this.xtreamStore.checkFavoriteStatus( - serialId, - this.xtreamStore.currentPlaylist().id - ); - void this.loadSeriesPlaybackPositions( - this.xtreamStore.currentPlaylist().id, - Number(serialId) - ); + this.initializeSerialDetails(currentPlaylist.id, categoryId, serialId); + this.detailsInitDone.set(true); } ngOnDestroy(): void { @@ -323,4 +330,18 @@ export class SerialDetailsComponent implements OnInit, OnDestroy { updated.delete(contentXtreamId); this.episodePlaybackPositions.set(updated); } + + private initializeSerialDetails( + playlistId: string, + categoryId: string | number, + serialId: string + ): void { + this.xtreamStore.fetchSerialDetailsWithMetadata({ + serialId, + categoryId: Number(categoryId), + }); + const serialXtreamId = Number(serialId); + this.xtreamStore.checkFavoriteStatus(serialXtreamId, playlistId); + void this.loadSeriesPlaybackPositions(playlistId, serialXtreamId); + } }