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 { export class ExcludedDomainsComponent implements OnInit, OnDestroy {
excludedDomains: ExcludedDomain[] = []; excludedDomains: ExcludedDomain[] = [];
existingExcludedDomains: ExcludedDomain[] = [];
currentUris: string[]; currentUris: string[];
loadCurrentUrisTimeout: number; loadCurrentUrisTimeout: number;
@ -39,6 +40,7 @@ export class ExcludedDomainsComponent implements OnInit, OnDestroy {
if (savedDomains) { if (savedDomains) {
for (const uri of Object.keys(savedDomains)) { for (const uri of Object.keys(savedDomains)) {
this.excludedDomains.push({ uri: uri, showCurrentUris: false }); this.excludedDomains.push({ uri: uri, showCurrentUris: false });
this.existingExcludedDomains.push({ uri: uri, showCurrentUris: false });
} }
} }
@ -78,7 +80,12 @@ export class ExcludedDomainsComponent implements OnInit, OnDestroy {
async submit() { async submit() {
const savedDomains: { [name: string]: null } = {}; const savedDomains: { [name: string]: null } = {};
const newExcludedDomains = this.getNewlyAddedDomians(this.excludedDomains);
for (const domain of this.excludedDomains) { for (const domain of this.excludedDomains) {
const resp = newExcludedDomains.filter((e) => e.uri === domain.uri);
if (resp.length === 0) {
savedDomains[domain.uri] = null;
} else {
if (domain.uri && domain.uri !== "") { if (domain.uri && domain.uri !== "") {
const validDomain = Utils.getHostname(domain.uri); const validDomain = Utils.getHostname(domain.uri);
if (!validDomain) { if (!validDomain) {
@ -92,6 +99,8 @@ export class ExcludedDomainsComponent implements OnInit, OnDestroy {
savedDomains[validDomain] = null; savedDomains[validDomain] = null;
} }
} }
}
await this.stateService.setNeverDomains(savedDomains); await this.stateService.setNeverDomains(savedDomains);
this.router.navigate(["/tabs/settings"]); this.router.navigate(["/tabs/settings"]);
} }
@ -100,6 +109,14 @@ export class ExcludedDomainsComponent implements OnInit, OnDestroy {
return index; 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) { toggleUriInput(domain: ExcludedDomain) {
domain.showCurrentUris = !domain.showCurrentUris; domain.showCurrentUris = !domain.showCurrentUris;
} }