Skip to content

Commit

Permalink
Communication: Add loading indicator when adding users to channel (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
PaRangger authored Dec 24, 2024
1 parent 8ace45f commit 0f1bf00
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { GroupChatService } from 'app/shared/metis/conversations/group-chat.serv
import { ConversationDTO } from 'app/entities/metis/conversation/conversation.model';
import { Course } from 'app/entities/course.model';
import { generateExampleChannelDTO, generateExampleGroupChatDTO } from '../../helpers/conversationExampleModels';
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { Component, EventEmitter, Input, Output, input } from '@angular/core';
import { AddUsersFormData } from 'app/overview/course-conversations/dialogs/conversation-add-users-dialog/add-users-form/conversation-add-users-form.component';
import { initializeDialog } from '../dialog-test-helpers';
import { ArtemisTranslatePipe } from 'app/shared/pipes/artemis-translate.pipe';
Expand All @@ -29,6 +29,8 @@ class ConversationAddUsersFormStubComponent {
@Input() courseId: number;
@Input() maxSelectable?: number = undefined;

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

@Input()
activeConversation: ConversationDTO;
}
Expand Down

0 comments on commit 0f1bf00

Please sign in to comment.