feat(recently-viewed): enhance UI with playlist grouping and global search support

This commit is contained in:
4gray committed 2025-01-27 08:55:21 +01:00
1 parent 5f44107d5e
commit a56e3594b4
6 files changed
+616 -106

No files matched your search

@@ -2,49 +2,119 @@
<div class="recent-container">
<div class="header">
<h2>Recently Viewed</h2>
@if (items.length) {
<button mat-button color="warn" (click)="clearHistory()">
<mat-icon>delete</mat-icon>
Clear History
</button>
}
</div>
@if (items.length) {
<div class="items-grid">
@for (item of items; track $index) {
<mat-card class="item-card" (click)="openItem(item)">
<button
mat-icon-button
class="remove-button"
(click)="removeItem($event, item.id)"
>
<mat-icon>close</mat-icon>
</button>
<img
[src]="
item.poster_url ||
'./assets/images/default-poster.png'
"
(error)="
$event.target.src =
'./assets/images/default-poster.png'
"
[alt]="item.title"
class="poster"
/>
<div class="item-info">
<h3>{{ item.title }}</h3>
<p [class]="item.type" class="type-badge">
{{ item.type | titlecase }}
</p>
<p class="viewed-at">
{{ item.viewed_at | date: 'd MMMM, y, hh:mm' }}
</p>
</div>
</mat-card>
<div class="header-actions">
@if (recentItems()?.length) {
<button mat-button color="warn" (click)="clearHistory()">
<mat-icon>delete</mat-icon>
Clear History
</button>
}
@if (isGlobal) {
<button mat-icon-button (click)="dialogRef.close()">
<mat-icon>close</mat-icon>
</button>
}
</div>
</div>
@if (recentItems()?.length) {
@if (isGlobal) {
<div class="playlist-section">
<h2 class="section-title">
Found {{ recentItems().length }} items across
{{ (getGroupedItems() | keyvalue).length }} playlists
</h2>
@for (group of getGroupedItems() | keyvalue; track group.key) {
<div class="playlist-group">
<h3 class="playlist-title">
<mat-icon>playlist_play</mat-icon>
{{ group.key }}
<span class="item-count"
>({{ $any(group).value.length }} items)</span
>
</h3>
<div class="items-grid">
@for (item of $any(group).value; track item.id) {
<mat-card
class="item-card"
(click)="openItem(item)"
>
<button
mat-icon-button
class="remove-button"
(click)="removeItem($event, item.id)"
>
<mat-icon>close</mat-icon>
</button>
<img
[src]="
item.poster_url ||
'./assets/images/default-poster.png'
"
(error)="
$event.target.src =
'./assets/images/default-poster.png'
"
[alt]="item.title"
class="poster"
/>
<div class="item-info">
<h3>{{ item.title }}</h3>
<p
[class]="item.type"
class="type-badge"
>
{{ item.type | titlecase }}
</p>
<p class="viewed-at">
{{
item.viewed_at
| date: 'd MMMM, y, HH:mm'
}}
</p>
</div>
</mat-card>
}
</div>
</div>
}
</div>
} @else {
<div class="items-grid">
@for (item of recentItems(); track item.id) {
<mat-card class="item-card" (click)="openItem(item)">
<button
mat-icon-button
class="remove-button"
(click)="removeItem($event, item.id)"
>
<mat-icon>close</mat-icon>
</button>
<img
[src]="
item.poster_url ||
'./assets/images/default-poster.png'
"
(error)="
$event.target.src =
'./assets/images/default-poster.png'
"
[alt]="item.title"
class="poster"
/>
<div class="item-info">
<h3>{{ item.title }}</h3>
<p [class]="item.type" class="type-badge">
{{ item.type | titlecase }}
</p>
<p class="viewed-at">
{{ item.viewed_at | date: 'd MMMM, y, hh:mm' }}
</p>
</div>
</mat-card>
}
</div>
}
} @else {
<div class="no-items">
<mat-icon>history</mat-icon>
@@ -15,6 +15,12 @@
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
.header-actions {
display: flex;
align-items: center;
gap: 8px;
}
}
.items-grid {
@@ -105,4 +111,53 @@
background: #43a047;
color: white;
}
}
.playlist-section {
.section-title {
margin: 0 0 1.5rem;
font-size: 1.2rem;
font-weight: normal;
color: var(--text-color-secondary);
padding: 0 8px;
}
}
.playlist-group {
margin-bottom: 2rem;
.playlist-title {
display: flex;
align-items: center;
gap: 8px;
margin: 0 0 1rem 0;
padding: 8px;
background: rgba(0, 0, 0, 0.05);
border-radius: 4px;
font-size: 1.1rem;
font-weight: 500;
mat-icon {
opacity: 0.7;
}
.item-count {
margin-left: auto;
font-size: 0.9rem;
opacity: 0.7;
}
}
}
:host-context(.global-search-overlay) {
.recent-container {
background: var(--background);
height: 100vh;
}
.playlist-group {
.playlist-title {
background: var(--surface);
}
}
}
@@ -1,15 +1,24 @@
import { CommonModule } from '@angular/common';
import { Component, inject } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { CommonModule, KeyValuePipe } from '@angular/common';
import { Component, computed, inject, Optional } from '@angular/core';
import { MatButtonModule, MatIconButton } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { MatIconModule } from '@angular/material/icon';
import { ActivatedRoute, Router } from '@angular/router';
import groupBy from 'lodash/groupBy';
import { XtreamStore } from '../xtream.store';
@Component({
selector: 'app-recently-viewed',
standalone: true,
imports: [CommonModule, MatCardModule, MatButtonModule, MatIconModule],
imports: [
CommonModule,
MatCardModule,
MatButtonModule,
MatIconModule,
KeyValuePipe,
MatIconButton,
],
templateUrl: './recently-viewed.component.html',
styleUrl: './recently-viewed.component.scss',
})
@@ -17,32 +26,78 @@ export class RecentlyViewedComponent {
private xtreamStore = inject(XtreamStore);
private activatedRoute = inject(ActivatedRoute);
private router = inject(Router);
private dialogData = inject(MAT_DIALOG_DATA, { optional: true });
readonly recentItems = this.xtreamStore.recentItems;
readonly isGlobal = this.dialogData?.isGlobal ?? false;
readonly recentItems = computed(() =>
this.isGlobal
? this.xtreamStore.globalRecentItems()
: this.xtreamStore.recentItems()
);
readonly currentPlaylist = this.xtreamStore.currentPlaylist;
constructor() {
this.xtreamStore.loadRecentItems(this.currentPlaylist);
constructor(
@Optional() public dialogRef?: MatDialogRef<RecentlyViewedComponent>
) {
if (this.isGlobal) {
this.loadGlobalItems();
} else if (this.currentPlaylist()) {
this.xtreamStore.loadRecentItems(this.currentPlaylist);
}
}
private async loadGlobalItems() {
try {
await this.xtreamStore.loadGlobalRecentItems();
} catch (error) {
console.error('Error loading global items:', error);
}
}
clearHistory() {
this.xtreamStore.clearRecentItems(this.xtreamStore.currentPlaylist);
if (this.isGlobal) {
this.xtreamStore.clearGlobalRecentlyViewed();
} else {
this.xtreamStore.clearRecentItems(this.xtreamStore.currentPlaylist);
}
}
openItem(item: any) {
const type = item.type === 'movie' ? 'vod' : item.type;
this.xtreamStore.setSelectedContentType(type);
this.router.navigate(['..', type, item.category_id, item.xtream_id], {
relativeTo: this.activatedRoute,
});
if (this.isGlobal) {
this.dialogRef?.close();
this.router.navigate([
'/xtreams',
item.playlist_id,
type,
item.category_id,
item.xtream_id,
]);
} else {
this.router.navigate(
['..', type, item.category_id, item.xtream_id],
{
relativeTo: this.activatedRoute,
}
);
}
}
removeItem(event: Event, itemId: number) {
event.stopPropagation();
this.xtreamStore.removeRecentItem({
itemId,
playlistId: this.currentPlaylist().id
playlistId: this.currentPlaylist().id,
});
}
getGroupedItems() {
const items = this.recentItems();
if (!this.isGlobal) return { default: items };
const grouped = groupBy(items, 'playlist_name');
return grouped;
}
}
@@ -1,6 +1,11 @@
<div class="search-page">
<div class="header">
<h2>Search</h2>
@if (isGlobalSearch) {
<button mat-icon-button (click)="dialogRef.close()">
<mat-icon>close</mat-icon>
</button>
}
</div>
<div class="search-container">
<mat-form-field appearance="outline" class="search-field">
@@ -37,7 +42,7 @@
</mat-checkbox>
</div>
@if (xtreamStore.searchResults().length > 0) {
@if (!isGlobalSearch && xtreamStore.searchResults().length > 0) {
<div class="results-count">
Found {{ xtreamStore.searchResults().length }} results
</div>
@@ -46,36 +51,132 @@
<div class="results-container">
@if (xtreamStore.searchResults().length > 0) {
<div class="results-grid">
@for (item of xtreamStore.searchResults(); track item.id) {
<mat-card (click)="selectItem(item)">
<mat-card-content>
@if (item.poster_url) {
<img
[src]="item.poster_url"
[alt]="item.title"
(error)="
$event.target.src =
'./assets/images/default-poster.png'
"
class="poster"
/>
}
@if (!item.poster_url) {
<div class="poster-placeholder">
<mat-icon>movie</mat-icon>
</div>
}
<h3>{{ item.title }}</h3>
<p>{{ item.description }}</p>
<div class="type-badge" [class]="item.type">
{{ item.type }}
@if (isGlobalSearch) {
<!-- Global Search Results -->
<div class="playlist-section">
<h2 class="section-title">
Found {{ xtreamStore.searchResults().length }} items
across
{{ (getGroupedResults() | keyvalue).length }} playlists
</h2>
@for (
group of getGroupedResults() | keyvalue;
track group.key
) {
<div class="playlist-group">
<h3 class="playlist-title">
<mat-icon>playlist_play</mat-icon>
{{ group.key }}
<span class="item-count"
>({{
$any(group).value.length
}}
items)</span
>
</h3>
<div class="results-grid">
@for (
item of $any(group).value;
track item.id
) {
<mat-card (click)="selectItem(item)">
<mat-card-content>
@if (item.poster_url) {
<img
[src]="item.poster_url"
[alt]="item.title"
(error)="
$event.target.src =
'./assets/images/default-poster.png'
"
class="poster"
/>
}
@if (!item.poster_url) {
<div class="poster-placeholder">
<mat-icon>movie</mat-icon>
</div>
}
<h3>{{ item.title }}</h3>
<p>{{ item.description }}</p>
<div
class="type-badge"
[class]="item.type"
>
{{ item.type }}
</div>
@if (
item.playlist_id &&
isGlobalSearch
) {
<div class="playlist-badge">
{{ item.playlist_name }}
</div>
}
@if (
isGlobalSearch &&
item.playlist_name
) {
<div class="playlist-badge">
<mat-icon
>playlist_play</mat-icon
>
<span>{{
item.playlist_name
}}</span>
</div>
}
</mat-card-content>
</mat-card>
}
</div>
</mat-card-content>
</mat-card>
}
</div>
} @else if (searchTerm) {
</div>
}
</div>
} @else {
<!-- Playlist-level Search Results -->
<div class="results-grid">
@for (item of xtreamStore.searchResults(); track item.id) {
<mat-card (click)="selectItem(item)">
<mat-card-content>
@if (item.poster_url) {
<img
[src]="item.poster_url"
[alt]="item.title"
(error)="
$event.target.src =
'./assets/images/default-poster.png'
"
class="poster"
/>
}
@if (!item.poster_url) {
<div class="poster-placeholder">
<mat-icon>movie</mat-icon>
</div>
}
<h3>{{ item.title }}</h3>
<p>{{ item.description }}</p>
<div class="type-badge" [class]="item.type">
{{ item.type }}
</div>
@if (item.playlist_id && isGlobalSearch) {
<div class="playlist-badge">
{{ item.playlist_name }}
</div>
}
@if (isGlobalSearch && item.playlist_name) {
<div class="playlist-badge">
<mat-icon>playlist_play</mat-icon>
<span>{{ item.playlist_name }}</span>
</div>
}
</mat-card-content>
</mat-card>
}
</div>
}
} @else if (searchTerm && searchTerm.length >= 3) {
<div class="no-items">
<mat-icon>search_off</mat-icon>
<p>No results found for "{{ searchTerm }}"</p>
@@ -25,14 +25,12 @@
}
.type-filters {
margin-top: 1rem;
mat-checkbox {
margin-right: 1rem;
}
}
.results-count {
margin-top: 1rem;
font-size: 0.9rem;
}
}
@@ -40,7 +38,6 @@
.results-container {
flex: 1;
overflow-y: auto;
padding: 0 1rem;
.results-grid {
display: grid;
@@ -125,4 +122,153 @@
font-size: 1.1rem;
margin: 0;
}
}
:host-context(.global-search-overlay) {
.search-page {
background: var(--background);
height: 100vh;
}
.results-grid {
mat-card {
position: relative;
.poster,
.poster-placeholder {
margin-top: 24px; // Add space for the playlist badge
}
.playlist-badge {
position: absolute;
top: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.7);
padding: 6px 8px;
font-size: 12px;
color: white;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
border-top-left-radius: inherit;
border-top-right-radius: inherit;
backdrop-filter: blur(5px);
display: flex;
align-items: center;
gap: 4px;
mat-icon {
font-size: 14px;
width: 14px;
height: 14px;
flex-shrink: 0;
}
}
}
}
}
.playlist-group {
margin-bottom: 2rem;
.playlist-title {
display: flex;
align-items: center;
gap: 8px;
margin: 0 0 1rem 0;
padding: 8px;
background: rgba(0, 0, 0, 0.05);
border-radius: 4px;
font-size: 1.1rem;
font-weight: 500;
mat-icon {
opacity: 0.7;
}
.item-count {
margin-left: auto;
font-size: 0.9rem;
opacity: 0.7;
}
}
.results-grid {
margin-bottom: 0;
}
}
:host-context(.global-search-overlay) {
.search-page {
background: var(--background);
height: 100vh;
}
.results-grid {
mat-card {
position: relative;
.poster,
.poster-placeholder {
margin-top: 24px;
}
.playlist-badge {
position: absolute;
top: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.7);
padding: 6px 8px;
font-size: 12px;
color: white;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
border-top-left-radius: inherit;
border-top-right-radius: inherit;
backdrop-filter: blur(5px);
display: flex;
align-items: center;
gap: 4px;
mat-icon {
font-size: 14px;
width: 14px;
height: 14px;
flex-shrink: 0;
}
}
}
}
.playlist-group {
.playlist-title {
background: var(--surface);
}
}
.results-grid {
mat-card {
.playlist-badge {
display: none;
}
.poster,
.poster-placeholder {
margin-top: 0;
}
}
}
}
.playlist-section {
.section-title {
margin: 0 0 1.5rem;
font-size: 1.2rem;
font-weight: normal;
color: var(--text-color-secondary);
padding: 0 8px;
}
}
@@ -1,45 +1,83 @@
import { KeyValuePipe } from '@angular/common';
import {
AfterViewInit,
Component,
ElementRef,
inject,
Inject,
OnDestroy,
Optional,
ViewChild,
} from '@angular/core';
import { FormsModule } from '@angular/forms';
import { MatIconButton } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
import { MatCheckboxModule } from '@angular/material/checkbox';
import {
MAT_DIALOG_DATA,
MatDialogModule,
MatDialogRef,
} from '@angular/material/dialog';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatIconModule } from '@angular/material/icon';
import { MatIcon } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';
import { ActivatedRoute, Router } from '@angular/router';
import groupBy from 'lodash/groupBy';
import { debounceTime, Subject } from 'rxjs';
import { XtreamItem } from '../../../../shared/xtream-item.interface';
import { DatabaseService } from '../../services/database.service';
import { XtreamStore } from '../xtream.store';
interface SearchResultsData {
isGlobalSearch: boolean;
}
@Component({
selector: 'app-search-results',
standalone: true,
imports: [
MatIconButton,
MatCardModule,
MatFormFieldModule,
MatInputModule,
MatIconModule,
MatIcon,
MatCheckboxModule,
FormsModule,
MatDialogModule,
KeyValuePipe,
],
providers: [],
templateUrl: './search-results.component.html',
styleUrls: ['./search-results.component.scss'],
})
export class SearchResultsComponent implements AfterViewInit {
export class SearchResultsComponent implements AfterViewInit, OnDestroy {
@ViewChild('searchInput') searchInput!: ElementRef;
readonly xtreamStore = inject(XtreamStore);
readonly router = inject(Router);
readonly activatedRoute = inject(ActivatedRoute);
readonly databaseService = inject(DatabaseService);
searchTerm = '';
filters = {
live: true,
movie: true,
series: true,
};
isGlobalSearch = false;
private searchSubject = new Subject<string>();
private readonly DEBOUNCE_TIME = 300;
constructor(
@Optional() @Inject(MAT_DIALOG_DATA) private data: SearchResultsData,
@Optional() public dialogRef: MatDialogRef<SearchResultsComponent>
) {
this.isGlobalSearch = data?.isGlobalSearch || false;
this.searchSubject
.pipe(debounceTime(this.DEBOUNCE_TIME))
.subscribe(() => {
this.executeSearch();
});
}
ngAfterViewInit() {
this.xtreamStore.setSelectedContentType(undefined);
@@ -50,30 +88,75 @@ export class SearchResultsComponent implements AfterViewInit {
onSearch() {
if (this.searchTerm.length >= 3) {
const types = Object.entries(this.filters)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
.filter(([_, enabled]) => enabled)
.map(([type]) => type);
this.xtreamStore.searchContent({ term: this.searchTerm, types });
this.searchSubject.next(this.searchTerm);
} else {
this.xtreamStore.resetSearchResults();
}
}
selectItem(item: XtreamItem) {
const type = item.type === 'movie' ? 'vod' : item.type;
this.xtreamStore.resetSearchResults();
this.xtreamStore.setSelectedContentType(type);
private executeSearch() {
const types = Object.entries(this.filters)
.filter(([_, enabled]) => enabled)
.map(([type]) => type);
if (item.type === 'live') {
this.router.navigate(['..', type, item.category_id], {
relativeTo: this.activatedRoute,
});
if (this.isGlobalSearch) {
this.searchGlobal(this.searchTerm, types);
} else {
this.xtreamStore.searchContent({
term: this.searchTerm,
types,
});
}
}
async searchGlobal(term: string, types: string[]) {
try {
const results = await this.databaseService.globalSearchContent(
term,
types
);
if (results && Array.isArray(results)) {
this.xtreamStore.setGlobalSearchResults(results);
}
} catch (error) {
console.error('Error in global search:', error);
this.xtreamStore.resetSearchResults();
}
}
ngOnDestroy() {
this.searchSubject.complete();
}
selectItem(
item: XtreamItem & { playlist_id?: string; playlist_name?: string }
) {
if (this.isGlobalSearch && item.playlist_id) {
this.dialogRef?.close();
const type = item.type === 'movie' ? 'vod' : item.type;
this.router.navigate([
'/xtreams',
item.playlist_id,
type,
item.category_id,
item.xtream_id,
]);
} else {
const type = item.type === 'movie' ? 'vod' : item.type;
this.xtreamStore.resetSearchResults();
this.xtreamStore.setSelectedContentType(type);
this.router.navigate(
['..', type, item.category_id, item.xtream_id],
{
relativeTo: this.activatedRoute,
}
item.type === 'live'
? ['..', type, item.category_id]
: ['..', type, item.category_id, item.xtream_id],
{ relativeTo: this.activatedRoute }
);
}
}
getGroupedResults() {
const results = this.xtreamStore.searchResults();
if (!this.isGlobalSearch) return { default: results };
return groupBy(results, 'playlist_name');
}
}