implemented advanced library filter

This commit is contained in:
X4Lo committed 2024-05-10 10:14:55 +01:00
1 parent 7fc1bdd875
commit ea5289dc67
5 files changed
+493 -125

No files matched your search

@@ -5,15 +5,13 @@ import { catchError, switchMap, tap } from 'rxjs/operators';
import { Entry } from '../../shared/models/entry.model';
import { EntryId } from '../../shared/models/entryId.model';
import { EntryRating } from '../../shared/models/entryRating.model';
// import { environment } from '../../../environments/environment';
@Injectable({
providedIn: 'root',
})
export class LibraryService implements OnInit {
// libraryEntries: Entry[] = [];
private libraryEntriesSubject = new ReplaySubject<Entry[]>(1);
private entriesLoaded = false; // Flag to track if the entries have been loaded
private entriesLoaded = false;
private backend_apiUrl = ' http://localhost:4000/api/v1';
@@ -27,28 +25,18 @@ export class LibraryService implements OnInit {
if (this.entriesLoaded && !forceFetch) {
return this.libraryEntriesSubject.asObservable();
} else {
// Note: This now properly chains the observable without directly subscribing here.
return this.fetchAllEntries(forceFetch);
}
}
// public refreshEntries(forceFetch: boolean = true): Observable<Entry[]> {
// return this.getAllEntries(forceFetch);
// }
public refrechEntries() {
return this.fetchAllEntries(true);
}
// private apiUrl = environment.apiBaseUrl;
/**
* Fetches data from the specified endpoint and returns an Observable.
* @param {string} endPoint The URL of the API endpoint to fetch data from.
* @param {Object} params Optional query parameters to append to the request URL.
* @returns {Observable<any>} An Observable that emits the fetched data.
*/
fetchData(
endPoint: string,
params?: { [param: string]: string | number }
): Observable<any> {
// Initialize HttpParams from the provided params object
let httpParams = new HttpParams();
if (params) {
Object.keys(params).forEach((key) => {
@@ -75,7 +63,6 @@ export class LibraryService implements OnInit {
this.entriesLoaded = true;
}),
catchError((error) => {
// Log and rethrow the error for the caller to handle.
console.error('Failed to fetch entries:', error);
this.entriesLoaded = false; // Allow for a retry on subsequent calls.
return throwError(() => new Error('Failed to fetch entries'));
@@ -84,36 +71,6 @@ export class LibraryService implements OnInit {
}
}
// /**
// * Fetches library data with page and pagesize and returns an Observable.
// * @param {string} endPoint The URL of the API endpoint to fetch data from.
// * @param {Object} params Optional query parameters to append to the request URL.
// * @returns {Observable<Entry[]>} An Observable that emits the fetched data.
// */
// getEntries(page: number, pageSize: number): Observable<Entry[]> {
// var endPoint = `${this.backend_apiUrl}/entries`;
// return this.fetchData(endPoint, { page: page, pageSize: pageSize }).pipe(
// map((response) =>
// response.results.map((movie: any) => this.mapMovieToEntry(movie))
// )
// );
// }
// /**
// * Retrieves a specific page of entries from the library.
// *
// * @param page The page number to retrieve.
// * @param pageSize Defines the number of entries on each page.
// * @returns An Observable emitting the requested page of entries.
// */
// getEntriesUsingEndPoint(endPoint: string): Observable<Entry[]> {
// return this.fetchData(endPoint).pipe(
// map((response) =>
// response.results.map((movie: any) => this.mapMovieToEntry(movie))
// )
// );
// }
addEntry(tmdb_id: string, is_tvserie: boolean): Observable<Entry | null> {
return this.getAllEntries().pipe(
switchMap((entries) => {