Files
iptvnator/apps/web/src/app/shared/utils/portal-collection-context.ts
T
4gray 7bb61ab64c refactor: streamline navigation and layout handling across components
- Updated StalkerShellComponent to utilize utility functions for workspace layout detection and portal section resolution.
- Refactored StalkerVod utilities to include inline detail state normalization and added tests for new functionality.
- Modified workspace context panels to import shared components for better organization.
- Enhanced DownloadsComponent to utilize a collection context for managing categories and downloads.
- Updated FavoritesComponent to leverage a portal collection shell layout and improved category management.
- Refactored RecentlyViewedComponent to use a shared collection shell layout and optimized item filtering.
- Improved SearchResultsComponent to utilize query parameter signals for search term handling.
- Updated XtreamMainContainer and XtreamShell components to streamline layout detection and section management.
2026-03-06 23:20:57 +01:00

47 lines
1.3 KiB
TypeScript

import { DestroyRef, Signal, effect, inject } from '@angular/core';
import { XtreamCategory } from 'shared-interfaces';
import { FavoritesContextService } from '../../workspace/favorites-context.service';
export interface PortalCollectionContextBridge {
readonly selectedCategoryId: Signal<string>;
setCategoryId(id: string): void;
}
interface CreatePortalCollectionContextOptions {
ctx: FavoritesContextService;
categories: () => XtreamCategory[];
enabled?: () => boolean;
}
export function createPortalCollectionContext(
options: CreatePortalCollectionContextOptions
): PortalCollectionContextBridge {
const destroyRef = inject(DestroyRef);
const isEnabled = options.enabled ?? (() => true);
let managesContext = false;
effect(() => {
if (!isEnabled()) {
return;
}
managesContext = true;
options.ctx.setCategories(options.categories());
});
destroyRef.onDestroy(() => {
if (managesContext && isEnabled()) {
options.ctx.reset();
}
});
return {
selectedCategoryId: options.ctx.selectedCategoryId,
setCategoryId(id: string): void {
if (isEnabled()) {
options.ctx.setCategoryId(id);
}
},
};
}