From e080afe05aec1456cfd54cdac8cdcac48080fd39 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Wed, 25 Mar 2020 22:14:45 +0000 Subject: [PATCH] Added the ability for the discover options to stay/stick --- .../components/discover/discover.component.ts | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/Ombi/ClientApp/src/app/discover/components/discover/discover.component.ts b/src/Ombi/ClientApp/src/app/discover/components/discover/discover.component.ts index 47695073b..aaa44171e 100644 --- a/src/Ombi/ClientApp/src/app/discover/components/discover/discover.component.ts +++ b/src/Ombi/ClientApp/src/app/discover/components/discover/discover.component.ts @@ -3,6 +3,7 @@ import { SearchV2Service } from "../../../services"; import { ISearchMovieResult, ISearchTvResult, RequestType } from "../../../interfaces"; import { IDiscoverCardResult, DiscoverOption } from "../../interfaces"; import { trigger, transition, style, animate } from "@angular/animations"; +import { StorageService } from "../../../shared/storage/storage-service"; @Component({ templateUrl: "./discover.component.html", @@ -21,13 +22,13 @@ export class DiscoverComponent implements OnInit { public discoverResults: IDiscoverCardResult[] = []; public movies: ISearchMovieResult[] = []; public tvShows: ISearchTvResult[] = []; - + public discoverOptions: DiscoverOption = DiscoverOption.Combined; public DiscoverOption = DiscoverOption; public defaultTvPoster: string; - public popularActive: boolean = true; + public popularActive: boolean; public trendingActive: boolean; public upcomingActive: boolean; @@ -36,22 +37,28 @@ export class DiscoverComponent implements OnInit { private contentLoaded: number; private isScrolling: boolean = false; + private mediaTypeStorageKey = "DiscoverOptions"; - constructor(private searchService: SearchV2Service) { } + constructor(private searchService: SearchV2Service, + private storageService: StorageService) { } public async ngOnInit() { this.loading() + const localDiscoverOptions = +this.storageService.get(this.mediaTypeStorageKey); + if (localDiscoverOptions) { + this.discoverOptions = DiscoverOption[DiscoverOption[localDiscoverOptions]]; + } this.scrollDisabled = true; switch (this.discoverOptions) { case DiscoverOption.Combined: - this.movies = await this.searchService.popularMoviesByPage(0,12); - this.tvShows = await this.searchService.popularTvByPage(0,12); + this.movies = await this.searchService.popularMoviesByPage(0, 12); + this.tvShows = await this.searchService.popularTvByPage(0, 12); break; case DiscoverOption.Movie: - this.movies = await this.searchService.popularMoviesByPage(0,12); + this.movies = await this.searchService.popularMoviesByPage(0, 12); break; case DiscoverOption.Tv: - this.tvShows = await this.searchService.popularTvByPage(0,12); + this.tvShows = await this.searchService.popularTvByPage(0, 12); break; } @@ -108,7 +115,7 @@ export class DiscoverComponent implements OnInit { case DiscoverOption.Tv: this.tvShows = await this.searchService.anticipatedTvByPage(this.contentLoaded, 12); break; - } + } } this.contentLoaded += 12; @@ -199,7 +206,8 @@ export class DiscoverComponent implements OnInit { public async switchDiscoverMode(newMode: DiscoverOption) { this.loading(); this.clear(); - this.discoverOptions = newMode; + this.discoverOptions = newMode; + this.storageService.save(this.mediaTypeStorageKey, newMode.toString()); await this.ngOnInit(); this.finishLoading(); }