mirror of
https://github.com/BrenBroZAYT/gameyfin.git
synced 2026-06-15 08:15:37 +00:00
Implemented filter
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {GamesApi} from "../api/GamesApi";
|
||||
import {HttpClient} from "@angular/common/http";
|
||||
import {map, Observable} from "rxjs";
|
||||
import {distinct, map, Observable} from "rxjs";
|
||||
import {DetectedGameDto} from "../models/dtos/DetectedGameDto";
|
||||
import {GameOverviewDto} from "../models/dtos/GameOverviewDto";
|
||||
import {GenreDto} from "../models/dtos/GenreDto";
|
||||
import {ThemeDto} from "../models/dtos/ThemeDto";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -42,6 +44,34 @@ export class GamesService implements GamesApi {
|
||||
return this.http.get<DetectedGameDto>(`${this.apiPath}/game/${slug}`);
|
||||
}
|
||||
|
||||
// TODO: This method of removing duplicates is most certainly an anti-pattern in RxJS
|
||||
// TODO: However, I did not get the 'distinct()' pipe to work properly, so I have to take another look in the future
|
||||
getAvailableGenres(): Observable<GenreDto[]> {
|
||||
return this.getAllGames().pipe(
|
||||
map<DetectedGameDto[], GenreDto[]>(
|
||||
games => {
|
||||
let availableGenresMap: Map<string, GenreDto> = new Map<string, GenreDto>;
|
||||
games.map(game => game.genres === undefined ? [] : game.genres).flat().forEach(genre => availableGenresMap.set(genre.slug, genre));
|
||||
return Array.from(availableGenresMap.values()).sort((g1, g2) => g1.name.localeCompare(g2.name));
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: This method of removing duplicates is most certainly an anti-pattern in RxJS
|
||||
// TODO: However, I did not get the 'distinct()' pipe to work properly, so I have to take another look in the future
|
||||
getAvailableThemes(): Observable<ThemeDto[]> {
|
||||
return this.getAllGames().pipe(
|
||||
map<DetectedGameDto[], ThemeDto[]>(
|
||||
games => {
|
||||
let availableThemesMap: Map<string, ThemeDto> = new Map<string, GenreDto>;
|
||||
games.map(game => game.themes === undefined ? [] : game.themes).flat().forEach(theme => availableThemesMap.set(theme.slug, theme));
|
||||
return Array.from(availableThemesMap.values()).sort((t1, t2) => t1.name.localeCompare(t2.name));
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
downloadGame(slug: String): void {
|
||||
window.open(`v1${this.apiPath}/game/${slug}/download`, '_top');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user