This commit is contained in:
jliddev
2022-02-18 08:48:11 -06:00
parent ab8c871f81
commit e18882a975
3 changed files with 29 additions and 16 deletions

View File

@@ -485,7 +485,6 @@ export class CurseAddonV2Provider extends AddonProvider {
): Promise<AddonSearchResult[]> {
const searchResults: AddonSearchResult[] = [];
const gameVersionType = this.getGameVersionTypeId(installation.clientType);
const response = await this.getSearchResults(query, installation.clientType);
await this.removeBlockedItems(response);
@@ -614,7 +613,7 @@ export class CurseAddonV2Provider extends AddonProvider {
return from(this.getClient()).pipe(
switchMap((client) =>
from(
this._circuitBreaker.fire(() => client.getModFile(parseInt(addonId as any, 10), parseInt(fileId as any, 10)))
this._circuitBreaker.fire(() => client.getModFile(parseInt(`${addonId}`, 10), parseInt(`${fileId}`, 10)))
)
),
map((response) => response.data.data)
@@ -1037,7 +1036,7 @@ export class CurseAddonV2Provider extends AddonProvider {
case WowClientGroup.Retail:
return CF2WowGameVersionType.Retail;
default:
throw new Error(`invalid game type: ${clientGroup}`);
throw new Error(`invalid game type: ${clientGroup as string}`);
}
}

View File

@@ -1,4 +1,4 @@
import { BehaviorSubject, combineLatest, Observable, of, Subject } from "rxjs";
import { BehaviorSubject, combineLatest, Observable, Subject } from "rxjs";
import { map, takeUntil } from "rxjs/operators";
import { Component, OnDestroy, OnInit } from "@angular/core";

View File

@@ -1,9 +1,9 @@
import { Component, OnInit } from "@angular/core";
import { Component, OnDestroy, OnInit } from "@angular/core";
import { AddonProviderState } from "../../../models/wowup/addon-provider-state";
import { MatSelectionListChange } from "@angular/material/list";
import { AddonProviderFactory } from "../../../services/addons/addon.provider.factory";
import { AddonProviderType } from "../../../addon-providers/addon-provider";
import { BehaviorSubject, catchError, debounceTime, first, from, map, of } from "rxjs";
import { BehaviorSubject, catchError, debounceTime, first, from, map, of, Subject, switchMap, takeUntil } from "rxjs";
import { PreferenceStorageService } from "../../../services/storage/preference-storage.service";
import { PREF_CF2_API_KEY } from "../../../../common/constants";
import { FormControl, FormGroup } from "@angular/forms";
@@ -18,7 +18,9 @@ interface AddonProviderStateModel extends AddonProviderState {
templateUrl: "./options-addon-section.component.html",
styleUrls: ["./options-addon-section.component.scss"],
})
export class OptionsAddonSectionComponent implements OnInit {
export class OptionsAddonSectionComponent implements OnInit, OnDestroy {
private destroy$: Subject<boolean> = new Subject<boolean>();
public addonProviderStates$ = new BehaviorSubject<AddonProviderStateModel[]>([]);
public preferenceForm = new FormGroup({
@@ -33,15 +35,22 @@ export class OptionsAddonSectionComponent implements OnInit {
this.loadProviderStates();
});
this.preferenceForm.valueChanges.pipe(debounceTime(300)).subscribe(async (ch) => {
try {
if (ch.cfV2ApiKey) {
this._preferenceStorageService.setAsync(PREF_CF2_API_KEY, ch.cfV2ApiKey);
}
} catch (e) {
console.error(e);
}
});
this.preferenceForm.valueChanges
.pipe(
takeUntil(this.destroy$),
debounceTime(300),
switchMap((ch) => {
if (ch.cfV2ApiKey) {
return from(this._preferenceStorageService.setAsync(PREF_CF2_API_KEY, ch.cfV2ApiKey));
}
return of(undefined);
}),
catchError((e) => {
console.error(e);
return of(undefined);
})
)
.subscribe();
}
public ngOnInit(): void {
@@ -49,6 +58,11 @@ export class OptionsAddonSectionComponent implements OnInit {
this.loadCfV2ApiKey();
}
public ngOnDestroy(): void {
this.destroy$.next(true);
this.destroy$.unsubscribe();
}
public async onProviderStateSelectionChange(event: MatSelectionListChange): Promise<void> {
for (const option of event.options) {
const providerName: AddonProviderType = option.value;