From bf291c4e649be20fc55125ad4f3a13d863d8e397 Mon Sep 17 00:00:00 2001 From: cyprain-okeke <108260115+cyprain-okeke@users.noreply.github.com> Date: Mon, 25 Jul 2022 10:05:41 +0100 Subject: [PATCH] Ps 693/fix localhost exclude domain bug 2 (#3140) * modify the submit function to validate only the newly/modified domains * changes after running prettier Co-authored-by: dynwee --- .../settings/excluded-domains.component.ts | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/apps/browser/src/popup/settings/excluded-domains.component.ts b/apps/browser/src/popup/settings/excluded-domains.component.ts index 18b1bec4ff..77d0e90fb1 100644 --- a/apps/browser/src/popup/settings/excluded-domains.component.ts +++ b/apps/browser/src/popup/settings/excluded-domains.component.ts @@ -22,6 +22,7 @@ const BroadcasterSubscriptionId = "excludedDomains"; }) export class ExcludedDomainsComponent implements OnInit, OnDestroy { excludedDomains: ExcludedDomain[] = []; + existingExcludedDomains: ExcludedDomain[] = []; currentUris: string[]; loadCurrentUrisTimeout: number; @@ -39,6 +40,7 @@ export class ExcludedDomainsComponent implements OnInit, OnDestroy { if (savedDomains) { for (const uri of Object.keys(savedDomains)) { this.excludedDomains.push({ uri: uri, showCurrentUris: false }); + this.existingExcludedDomains.push({ uri: uri, showCurrentUris: false }); } } @@ -78,20 +80,27 @@ export class ExcludedDomainsComponent implements OnInit, OnDestroy { async submit() { const savedDomains: { [name: string]: null } = {}; + const newExcludedDomains = this.getNewlyAddedDomians(this.excludedDomains); for (const domain of this.excludedDomains) { - if (domain.uri && domain.uri !== "") { - const validDomain = Utils.getHostname(domain.uri); - if (!validDomain) { - this.platformUtilsService.showToast( - "error", - null, - this.i18nService.t("excludedDomainsInvalidDomain", domain.uri) - ); - return; + const resp = newExcludedDomains.filter((e) => e.uri === domain.uri); + if (resp.length === 0) { + savedDomains[domain.uri] = null; + } else { + if (domain.uri && domain.uri !== "") { + const validDomain = Utils.getHostname(domain.uri); + if (!validDomain) { + this.platformUtilsService.showToast( + "error", + null, + this.i18nService.t("excludedDomainsInvalidDomain", domain.uri) + ); + return; + } + savedDomains[validDomain] = null; } - savedDomains[validDomain] = null; } } + await this.stateService.setNeverDomains(savedDomains); this.router.navigate(["/tabs/settings"]); } @@ -100,6 +109,14 @@ export class ExcludedDomainsComponent implements OnInit, OnDestroy { return index; } + getNewlyAddedDomians(domain: ExcludedDomain[]): ExcludedDomain[] { + const result = this.excludedDomains.filter( + (newDomain) => + !this.existingExcludedDomains.some((oldDomain) => newDomain.uri === oldDomain.uri) + ); + return result; + } + toggleUriInput(domain: ExcludedDomain) { domain.showCurrentUris = !domain.showCurrentUris; }