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 <onwudiweokeke@gmail.com>
This commit is contained in:
cyprain-okeke 2022-07-25 10:05:41 +01:00 committed by GitHub
parent adbe0d58fa
commit bf291c4e64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 10 deletions

View File

@ -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;
}