chore: update Angular cache and TypeScript build info
This commit is contained in:
@@ -52,12 +52,6 @@
|
||||
<option value="views">Vues</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="flex items-center gap-2 justify-end">
|
||||
<button class="px-3 py-1 rounded bg-slate-700 hover:bg-slate-600 text-slate-100 disabled:opacity-50"
|
||||
(click)="prevPage()" [disabled]="!canPrev()">Précédent</button>
|
||||
<div class="text-sm text-slate-300">Page {{ pageParam() }}</div>
|
||||
<button class="px-3 py-1 rounded bg-slate-700 hover:bg-slate-600 text-slate-100" (click)="nextPage()">Suivant</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (error()) {
|
||||
@@ -68,5 +62,16 @@
|
||||
}
|
||||
|
||||
<app-search-result-grid [videos]="filteredResults()" [loading]="loading()"></app-search-result-grid>
|
||||
|
||||
<!-- Infinite scroll anchor & indicators -->
|
||||
<div class="flex flex-col items-center justify-center py-6">
|
||||
@if (loading()) {
|
||||
<div class="text-slate-400 text-sm">Chargement…</div>
|
||||
}
|
||||
@if (endReached()) {
|
||||
<div class="text-slate-500 text-xs">Fin des résultats</div>
|
||||
}
|
||||
</div>
|
||||
<div #infiniteScrollAnchor class="h-1 w-full"></div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ChangeDetectionStrategy, Component, computed, effect, inject, signal, ViewChild, ElementRef } from '@angular/core';
|
||||
import { ChangeDetectionStrategy, Component, computed, effect, inject, signal, ViewChild, ElementRef, AfterViewInit } from '@angular/core';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { ActivatedRoute, Router, ParamMap } from '@angular/router';
|
||||
@@ -21,7 +21,7 @@ import { Observable, Subscription } from 'rxjs';
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
imports: [CommonModule, TranslatePipe, SearchResultGridComponent]
|
||||
})
|
||||
export class SearchComponent {
|
||||
export class SearchComponent implements AfterViewInit {
|
||||
private route = inject(ActivatedRoute);
|
||||
private router = inject(Router);
|
||||
private api = inject(YoutubeApiService);
|
||||
@@ -43,9 +43,13 @@ export class SearchComponent {
|
||||
groups = signal<Record<string, any[]>>({});
|
||||
showUnified = signal<boolean>(false);
|
||||
error = signal<string | null>(null);
|
||||
endReached = signal<boolean>(false);
|
||||
|
||||
// Dedup key to avoid recording the same search multiple times
|
||||
private lastRecordedKey: string | null = null;
|
||||
// Signature to detect new searches (q + providers + sort); excludes page
|
||||
private lastSearchSignature: string | null = null;
|
||||
private io?: IntersectionObserver;
|
||||
|
||||
hasQuery = computed(() => this.q().length > 0);
|
||||
providerLabel = computed(() => {
|
||||
@@ -107,6 +111,43 @@ export class SearchComponent {
|
||||
}
|
||||
}
|
||||
|
||||
// Merge groups with dedup by id/videoId/url
|
||||
private mergeGroups(prev: Record<string, any[]>, incoming: Record<string, any[]>): Record<string, any[]> {
|
||||
const result: Record<string, any[]> = { ...(prev || {}) };
|
||||
const providers = new Set<string>([...Object.keys(prev || {}), ...Object.keys(incoming || {})]);
|
||||
providers.forEach(pid => {
|
||||
const a = Array.isArray(prev?.[pid]) ? prev[pid] : [];
|
||||
const b = Array.isArray(incoming?.[pid]) ? incoming[pid] : [];
|
||||
if (a.length === 0) { result[pid] = b.slice(); return; }
|
||||
if (b.length === 0) { result[pid] = a.slice(); return; }
|
||||
const seen = new Set<string>();
|
||||
const merged: any[] = [];
|
||||
const keyOf = (v: any) => String((v && (v.id || v.videoId || v.url)) ?? JSON.stringify(v));
|
||||
a.forEach(v => { const k = keyOf(v); if (!seen.has(k)) { seen.add(k); merged.push(v); } });
|
||||
b.forEach(v => { const k = keyOf(v); if (!seen.has(k)) { seen.add(k); merged.push(v); } });
|
||||
result[pid] = merged;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
// Set up IntersectionObserver for infinite scroll
|
||||
ngAfterViewInit(): void {
|
||||
const anchor = this.infiniteScrollAnchor?.nativeElement;
|
||||
if (!anchor) return;
|
||||
this.io = new IntersectionObserver((entries) => {
|
||||
const e = entries[0];
|
||||
if (e && e.isIntersecting) {
|
||||
this.loadNextPage();
|
||||
}
|
||||
}, { root: null, rootMargin: '200px 0px', threshold: 0 });
|
||||
this.io.observe(anchor);
|
||||
}
|
||||
|
||||
// Optional: clean up observer
|
||||
ngOnDestroy(): void {
|
||||
try { this.io?.disconnect(); } catch {}
|
||||
}
|
||||
|
||||
// Page title with search query
|
||||
pageHeading = computed(() => {
|
||||
const q = this.q();
|
||||
@@ -280,14 +321,28 @@ export class SearchComponent {
|
||||
.pipe(takeUntilDestroyed())
|
||||
.subscribe({
|
||||
next: (resp: any) => {
|
||||
// Convertir la réponse en un format compatible avec notre modèle
|
||||
const groups: Record<string, any[]> = {};
|
||||
// Convertir la réponse et concaténer si page > 1 (scroll infini)
|
||||
const incoming: Record<string, any[]> = {};
|
||||
if (resp.groups) {
|
||||
Object.entries(resp.groups).forEach(([key, value]) => {
|
||||
groups[key] = Array.isArray(value) ? value : [];
|
||||
incoming[key] = Array.isArray(value) ? value : [];
|
||||
});
|
||||
}
|
||||
this.groups.set(groups);
|
||||
|
||||
const currentPage = this.pageParam() || 1;
|
||||
const isContinuation = currentPage > 1 && this.lastSearchSignature != null;
|
||||
if (isContinuation) {
|
||||
const merged = this.mergeGroups(this.groups(), incoming);
|
||||
this.groups.set(merged);
|
||||
// If no new items were added, mark end reached
|
||||
const addedCount = Object.values(incoming).reduce((a: number, arr: any[]) => a + (arr?.length || 0), 0);
|
||||
if (addedCount === 0) this.endReached.set(true);
|
||||
} else {
|
||||
this.groups.set(incoming);
|
||||
// If first page is empty for all providers, end reached
|
||||
const total = Object.values(incoming).reduce((a: number, arr: any[]) => a + (arr?.length || 0), 0);
|
||||
this.endReached.set(total === 0);
|
||||
}
|
||||
this.loading.set(false);
|
||||
this.error.set(null);
|
||||
},
|
||||
@@ -338,6 +393,11 @@ export class SearchComponent {
|
||||
this.unified.setQuery(q);
|
||||
this.unified.setProviders(providersToUse);
|
||||
|
||||
// Determine if this is a new search (signature excludes page)
|
||||
const signature = `${q}|${Array.isArray(providersToUse) ? providersToUse.join(',') : String(providersToUse)}|${sortNorm}`;
|
||||
const isNewSearch = this.lastSearchSignature !== signature || pageNum === 1;
|
||||
this.lastSearchSignature = signature;
|
||||
|
||||
// Record this search once per unique (q, providers) combination
|
||||
try {
|
||||
const key = `${q}|${Array.isArray(providersToUse) ? providersToUse.join(',') : String(providersToUse)}`;
|
||||
@@ -355,13 +415,17 @@ export class SearchComponent {
|
||||
|
||||
this.showUnified.set(true);
|
||||
this.loading.set(true);
|
||||
this.groups.set({} as any); // Clear previous results
|
||||
if (isNewSearch) {
|
||||
this.groups.set({} as any); // Clear only for a new search
|
||||
this.endReached.set(false);
|
||||
}
|
||||
this.error.set(null);
|
||||
} else {
|
||||
this.loading.set(false);
|
||||
this.groups.set({} as any);
|
||||
this.showUnified.set(false);
|
||||
this.error.set(null);
|
||||
this.endReached.set(false);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -430,6 +494,7 @@ export class SearchComponent {
|
||||
}
|
||||
|
||||
@ViewChild('searchInput', { static: false }) searchInput?: ElementRef<HTMLInputElement>;
|
||||
@ViewChild('infiniteScrollAnchor', { static: false }) infiniteScrollAnchor?: ElementRef<HTMLDivElement>;
|
||||
|
||||
// Legacy input handlers removed; SearchBox handles keyboard and submit
|
||||
|
||||
@@ -452,6 +517,22 @@ export class SearchComponent {
|
||||
}
|
||||
|
||||
// Pagination controls
|
||||
private loadNextPage() {
|
||||
const current = this.pageParam() || 1;
|
||||
const next = current + 1;
|
||||
if (this.loading() || this.endReached()) return;
|
||||
const cleanParams = this.cleanUrlParams({
|
||||
...this.route.snapshot.queryParams,
|
||||
page: next
|
||||
});
|
||||
this.router.navigate([], {
|
||||
relativeTo: this.route,
|
||||
queryParams: cleanParams,
|
||||
queryParamsHandling: '',
|
||||
replaceUrl: true
|
||||
});
|
||||
}
|
||||
|
||||
nextPage() {
|
||||
const next = (this.pageParam() || 1) + 1;
|
||||
const cleanParams = this.cleanUrlParams({
|
||||
|
||||
@@ -104,8 +104,8 @@
|
||||
<a [routerLink]="['/watch', v.videoId]" [queryParams]="watchQueryParams(v)" [state]="{ video: v }" class="block bg-slate-800/50 rounded-lg overflow-hidden hover:bg-slate-700/50 transition-all duration-300 transform hover:-translate-y-1 shadow-lg hover:shadow-xl">
|
||||
<div class="relative">
|
||||
<img [src]="v.thumbnail" [alt]="v.title" loading="lazy" decoding="async" class="w-full aspect-video object-cover transition-transform duration-300 group-hover:scale-105">
|
||||
<div class="absolute bottom-2 right-2 bg-black/75 text-white text-xs px-2 py-1 rounded-md font-mono">
|
||||
{{ v.duration | number:'1.0-0' }}:{{ (v.duration % 60) | number:'2.0-0' }}
|
||||
<div *ngIf="v.duration && v.duration > 0" class="absolute bottom-2 right-2 bg-black/75 text-white text-xs px-2 py-1 rounded-md font-mono">
|
||||
{{ v.duration | duration }}
|
||||
</div>
|
||||
<div class="absolute top-2 left-2">
|
||||
<app-like-button [videoId]="v.videoId" [provider]="provider()" [title]="v.title" [thumbnail]="v.thumbnail"></app-like-button>
|
||||
|
||||
@@ -8,13 +8,42 @@ import { YoutubeApiService } from '../../services/youtube-api.service';
|
||||
import { Video } from '../../models/video.model';
|
||||
import { TranslatePipe } from '../../pipes/translate.pipe';
|
||||
import { LikeButtonComponent } from '../shared/components/like-button/like-button.component';
|
||||
import { DurationPipe } from '../../app/shared/pipes/duration.pipe';
|
||||
import { map, of, switchMap } from 'rxjs';
|
||||
|
||||
const TWITCH_THEME_KEYWORDS: Record<string, string[]> = {
|
||||
trending: ['just chatting', 'highlights'],
|
||||
live: ['live', 'stream'],
|
||||
gaming: ['gaming', 'playthrough'],
|
||||
sports: ['sports', 'esports'],
|
||||
'finance-crypto': ['finance', 'crypto'],
|
||||
business: ['business', 'entrepreneur'],
|
||||
tech: ['technology', 'coding'],
|
||||
science: ['science', 'space'],
|
||||
health: ['fitness', 'wellness'],
|
||||
music: ['music', 'performance'],
|
||||
podcasts: ['podcast', 'talk show'],
|
||||
'movies-tv': ['movie review', 'tv discussion'],
|
||||
education: ['education', 'tutorial'],
|
||||
travel: ['travel vlog'],
|
||||
food: ['cooking', 'food'],
|
||||
'diy-makers': ['diy', 'maker'],
|
||||
autos: ['car build', 'automotive'],
|
||||
'nature-animals': ['outdoors', 'wildlife'],
|
||||
comedy: ['comedy', 'standup'],
|
||||
'art-design': ['art stream', 'drawing'],
|
||||
vlogs: ['vlog', 'lifestyle'],
|
||||
reviews: ['tech review', 'unboxing'],
|
||||
documentary: ['history', 'documentary'],
|
||||
'family-kids': ['family', 'kids'],
|
||||
news: ['news', 'politics'],
|
||||
};
|
||||
@Component({
|
||||
selector: 'app-provider-theme',
|
||||
standalone: true,
|
||||
templateUrl: './provider-theme-page.component.html',
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
imports: [CommonModule, FormsModule, RouterLink, TranslatePipe, LikeButtonComponent]
|
||||
imports: [CommonModule, FormsModule, RouterLink, TranslatePipe, LikeButtonComponent, DurationPipe]
|
||||
})
|
||||
export class ProviderThemePageComponent implements OnDestroy {
|
||||
private route = inject(ActivatedRoute);
|
||||
@@ -76,9 +105,21 @@ export class ProviderThemePageComponent implements OnDestroy {
|
||||
this.loadMore();
|
||||
}
|
||||
|
||||
private buildQuery(): string {
|
||||
const tokens = this.themes.tokensFor(this.theme());
|
||||
return tokens.join(' ').trim();
|
||||
private buildQuery(provider: Provider): string {
|
||||
const slug = this.theme();
|
||||
const baseTokens = this.themes.tokensFor(slug);
|
||||
|
||||
if (provider === 'twitch') {
|
||||
const twitchTokens = TWITCH_THEME_KEYWORDS[slug] || [];
|
||||
const merged = [...new Set([...twitchTokens, ...baseTokens])];
|
||||
const value = merged.join(' ').trim();
|
||||
if (value) return value;
|
||||
if (twitchTokens.length) return twitchTokens.join(' ');
|
||||
return slug.replace(/-/g, ' ');
|
||||
}
|
||||
|
||||
const value = baseTokens.join(' ').trim();
|
||||
return value || slug.replace(/-/g, ' ');
|
||||
}
|
||||
|
||||
loadMore() {
|
||||
@@ -93,12 +134,33 @@ export class ProviderThemePageComponent implements OnDestroy {
|
||||
this.loading.set(true);
|
||||
this.error.set(null);
|
||||
const snapshotVersion = this.version;
|
||||
const query = this.buildQuery();
|
||||
const provider = this.provider();
|
||||
const query = this.buildQuery(provider);
|
||||
const cursor = this.nextCursor();
|
||||
const themeSlug = this.theme();
|
||||
const isLiveTheme = themeSlug === 'live';
|
||||
|
||||
const apiCall = query
|
||||
? this.api.searchVideosPage(query, this.nextCursor(), provider)
|
||||
: this.api.getTrendingPage(this.nextCursor(), provider);
|
||||
let apiCall;
|
||||
if (provider === 'twitch') {
|
||||
if (isLiveTheme) {
|
||||
apiCall = this.api.searchTwitchChannelsPage(query || 'live', cursor || undefined);
|
||||
} else {
|
||||
apiCall = this.api.searchTwitchVodsPage(query, cursor || undefined).pipe(
|
||||
switchMap((res) => {
|
||||
if ((res?.items?.length || 0) >= 8) {
|
||||
return of(res);
|
||||
}
|
||||
return this.api.searchTwitchClipsPage(query, cursor || undefined).pipe(
|
||||
map((clips) => ({ ...clips, items: [...(res?.items || []), ...(clips.items || [])] }))
|
||||
);
|
||||
})
|
||||
);
|
||||
}
|
||||
} else {
|
||||
apiCall = query
|
||||
? this.api.searchVideosPage(query, cursor, provider)
|
||||
: this.api.getTrendingPage(cursor, provider);
|
||||
}
|
||||
|
||||
apiCall.subscribe({
|
||||
next: (res) => {
|
||||
|
||||
Reference in New Issue
Block a user