Prevent duplicate requests in checkPunishment and sendForm by adding loading state guards.

This commit is contained in:
akastijn 2025-11-24 01:54:18 +01:00
parent 186a26fae1
commit beb5cd496a

View File

@ -13,6 +13,7 @@ import {MatIconModule} from '@angular/material/icon';
import {VerifyMailDialogComponent} from '@pages/forms/verify-mail-dialog/verify-mail-dialog.component';
import {MatDialog} from '@angular/material/dialog';
import {Router} from '@angular/router';
import {finalize} from 'rxjs';
@Component({
selector: 'app-discord-appeal',
@ -131,7 +132,12 @@ export class DiscordAppealComponent implements OnInit {
return this.currentPageIndex === this.totalPages.length - 1;
}
private punishmentLoading: boolean = false;
protected checkPunishment() {
if (this.punishmentLoading) {
return;
}
if (window.location.hostname === 'localhost') {
this.bannedUser = {
isBanned: false,
@ -146,6 +152,9 @@ export class DiscordAppealComponent implements OnInit {
return
}
this.appealService.getBannedUser(this.discordId)
.pipe(
finalize(() => this.punishmentLoading = false)
)
.subscribe(user => {
this.bannedUser = user
this.nextPage();
@ -171,7 +180,12 @@ export class DiscordAppealComponent implements OnInit {
}
}
private formSubmitting: boolean = false;
private sendForm() {
if (this.formSubmitting) {
return;
}
const rawValue = this.form.getRawValue();
const uuid = this.authService.getUuid();
if (uuid === null) {
@ -182,14 +196,18 @@ export class DiscordAppealComponent implements OnInit {
appeal: rawValue.appeal,
email: rawValue.email,
}
this.appealService.submitDiscordAppeal(appeal).subscribe((result) => {
if (!result.verified_mail) {
throw new Error('Mail not verified');
}
this.router.navigate(['/forms/sent'], {
state: {message: result.message}
}).then();
})
this.appealService.submitDiscordAppeal(appeal)
.pipe(
finalize(() => this.formSubmitting = false)
)
.subscribe((result) => {
if (!result.verified_mail) {
throw new Error('Mail not verified');
}
this.router.navigate(['/forms/sent'], {
state: {message: result.message}
}).then();
})
}
}