Skip to content

Commit

Permalink
Add loading indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
PaRangger committed Dec 16, 2024
1 parent 5449cc4 commit 971584c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
<div class="col-12 text-end">
<button type="submit" id="submitButton" [disabled]="!isSubmitPossible" class="btn btn-primary">
<span jhiTranslate="artemisApp.dialogs.addUsers.addUsersForm.addUsersButton"></span>
@if (isLoading()) {
<fa-icon [icon]="faSpinner" animation="spin" class="ms-2" />
}
</button>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Component, EventEmitter, Input, OnChanges, OnInit, Output } from '@angular/core';
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, input } from '@angular/core';
import { UserPublicInfoDTO } from 'app/core/user/user.model';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { ConversationDTO } from 'app/entities/metis/conversation/conversation.model';
import { getAsChannelDTO } from 'app/entities/metis/conversation/channel.model';
import { faSpinner } from '@fortawesome/free-solid-svg-icons';

export interface AddUsersFormData {
selectedUsers?: UserPublicInfoDTO[];
Expand All @@ -24,8 +25,13 @@ export class ConversationAddUsersFormComponent implements OnInit, OnChanges {
@Input()
activeConversation: ConversationDTO;

protected readonly isLoading = input<boolean>(false);

form: FormGroup;

// Icons
protected readonly faSpinner = faSpinner;

getAsChannel = getAsChannelDTO;

mode: 'individual' | 'group' = 'individual';
Expand All @@ -37,8 +43,9 @@ export class ConversationAddUsersFormComponent implements OnInit, OnChanges {

get isSubmitPossible() {
return (
(this.mode === 'individual' && !this.form.invalid) ||
(this.mode === 'group' && (this.form.value?.addAllStudents || this.form.value?.addAllTutors || this.form.value?.addAllInstructors))
!this.isLoading() &&
((this.mode === 'individual' && !this.form.invalid) ||
(this.mode === 'group' && (this.form.value?.addAllStudents || this.form.value?.addAllTutors || this.form.value?.addAllInstructors)))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ <h4 class="modal-title">
</div>
<div class="modal-body">
<jhi-conversation-add-users-form
[isLoading]="isLoading"
[maxSelectable]="maxSelectable"
[courseId]="course.id!"
(formSubmitted)="onFormSubmitted($event)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class ConversationAddUsersDialogComponent extends AbstractDialogComponent

isInitialized = false;
maxSelectable: number | undefined;
protected isLoading: boolean = false;

initialize() {
super.initialize(['course', 'activeConversation']);
Expand Down Expand Up @@ -65,6 +66,8 @@ export class ConversationAddUsersDialogComponent extends AbstractDialogComponent
private addUsers(usersToAdd: UserPublicInfoDTO[], addAllStudents: boolean, addAllTutors: boolean, addAllInstructors: boolean) {
const userLogins = usersToAdd.map((user) => user.login!);

this.isLoading = true;

if (isChannelDTO(this.activeConversation)) {
this.channelService
.registerUsersToChannel(this.course.id!, this.activeConversation.id!, addAllStudents, addAllTutors, addAllInstructors, userLogins)
Expand All @@ -77,6 +80,9 @@ export class ConversationAddUsersDialogComponent extends AbstractDialogComponent
error: (errorResponse: HttpErrorResponse) => {
onError(this.alertService, errorResponse);
},
complete: () => {
this.isLoading = false;
},
});
} else if (isGroupChatDTO(this.activeConversation)) {
this.groupChatService
Expand All @@ -90,6 +96,9 @@ export class ConversationAddUsersDialogComponent extends AbstractDialogComponent
error: (errorResponse: HttpErrorResponse) => {
onError(this.alertService, errorResponse);
},
complete: () => {
this.isLoading = false;
},
});
} else {
throw new Error('Conversation type not supported');
Expand Down

0 comments on commit 971584c

Please sign in to comment.