2

Now I have a feature where user can create new data and save it , if the data is existing a modal will pop up like enter image description here

Now after the user clicks the save button it will be submitted and while the request is still pending or loading there is a tendency that the user will click again on the button and the "Data already exists wanna proceed on saving?" will pop up again which I dont want to.

So as you can see on the screenshot below, the request is still pending and loading so if user clicks that again that pop up will again show . How do we solve that using angular ? Any good idea that might help ? Thanks.

enter image description here

#Save data snippet

listenToSaveEvent(): void {
    this.saveSubject
      .asObservable()
      .pipe(
        filter((v) => !!v),
        debounceTime(1e3)
      )
      .subscribe(() => {
 
        if (this.respondents.length === 1) {
          return this.checkExistingData();

#CODE THAT CHECKS EXISTING DATA

checkExistingData(): void {
    const test = this.formService.checkExisting(this.form)
    .subscribe(res => {
      if (res ) {
        const createExistingSub = this.confirmDialogService.open(
          ERROR_MESSAGES."Data already exists wanna proceed on saving?"
        )
          .componentInstance
          .confirmed
          .subscribe((confirmed) => {
            if (confirmed) {
              return this.createDATA();
            }

            createExistingSub.unsubscribe();
      });
      } else {
          return this.createDATA();
      }
  });
2
  • 2
    you can disable to button on click and enable back inside subscribe of api. Commented Jun 21, 2020 at 17:25
  • simple solution: disable button or make it disappear when you press it. done. Commented Jun 21, 2020 at 19:57

2 Answers 2

2

You might want to disable your button while processing the request and\or put a loader on it. That way the user will see its still processing and you wont have that problem anymore, better from User Experience perspective.

Sign up to request clarification or add additional context in comments.

Comments

1

Add some flag that will switch before and after upload

`listenToSaveEvent(): void {
    if (this.isUploading) { return;}  // do nothing while uploading
    this.isUploading = true;
    this.saveSubject
      .asObservable()
      .pipe(
        filter((v) => !!v),
        debounceTime(1e3),
        finally(() => this.isUploading === false)   // no matter if it's success or error
      )
      .subscribe(() => {
 
        if (this.respondents.length === 1) {
          return this.checkExistingData();`

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.