Skip to content

Commit f46652c

Browse files
committed
update image flow modified
1 parent b89528d commit f46652c

4 files changed

Lines changed: 28 additions & 50 deletions

File tree

MangoAPI.Client/src/app/components/chats/chats.component.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { DeleteMessageNotification } from '../../types/models/DeleteMessageNotif
1818
import { firstValueFrom, Subject, takeUntil } from 'rxjs';
1919
import { DisplayNameColours } from 'src/app/types/enums/DisplayNameColours';
2020
import { DeleteMessageCommand } from 'src/app/types/requests/DeleteMessageCommand';
21-
import { DocumentsService } from 'src/app/services/api/documents.service';
2221
import ApiBaseService from 'src/app/services/api/apiBase.service';
2322
import { SendMessageResponse } from '../../types/responses/SendMessageResponse';
2423

@@ -36,7 +35,6 @@ export class ChatsComponent implements OnInit, OnDestroy {
3635
private _errorNotificationService: ErrorNotificationService,
3736
private _router: Router,
3837
private _validationService: ValidationService,
39-
private _documentsService: DocumentsService,
4038
private _apiBaseService: ApiBaseService,
4139
public _modalWindowStateService: ModalWindowStateService
4240
) {}

MangoAPI.Client/src/app/components/settings/settings.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ <h5 class="mb-2">Avatar</h5>
314314
<span class="text-light-gray">Update profile picture</span>
315315
</div>
316316
<div class="profile-form-content">
317-
<input type="file" id="File" (change)="onUpdateProfilePictureChange($event)" />
317+
<input type="file" id="ProfilePicture" (change)="onUpdateProfilePictureChange($event)" />
318318
</div>
319319
<div class="profile-form-footer gap-fix">
320320
<button class="button-dark" (click)="clearProfilePictureFile()">Reset</button>

MangoAPI.Client/src/app/components/settings/settings.component.ts

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ import { ValidationService } from '../../services/messenger/validation.service';
1111
import { UpdateAccountInformationCommand } from '../../types/requests/UpdateAccountInformationCommand';
1212
import { SessionService } from '../../services/api/session.service';
1313
import { Event, Router } from '@angular/router';
14-
import { Subject, takeUntil } from 'rxjs';
14+
import { firstValueFrom, Subject, takeUntil } from 'rxjs';
1515
import { RoutingConstants } from 'src/app/types/constants/RoutingConstants';
1616
import { AppInfoService } from 'src/app/services/api/app-info.service';
1717
import { ModalWindowStateService } from 'src/app/services/states/modalWindowState.service';
18+
import { UpdateProfilePictureResponse } from '../../types/responses/UpdateProfilePictureResponse';
1819

1920
@Component({
2021
selector: 'app-settings',
@@ -81,7 +82,7 @@ export class SettingsComponent implements OnInit, OnDestroy {
8182
next: (response) => {
8283
this.currentUser = response.user;
8384

84-
if (response.user.userNameChanged === false) {
85+
if (!response.user.userNameChanged) {
8586
this.currentUser.username = '';
8687
}
8788
},
@@ -108,13 +109,13 @@ export class SettingsComponent implements OnInit, OnDestroy {
108109
}
109110

110111
onOpenAvatarClick(): void {
111-
this._modalWindowStateService.setIsModalWindowShowing(true)
112-
this._modalWindowStateService.setPicture(this.currentUser.pictureUrl)
112+
this._modalWindowStateService.setIsModalWindowShowing(true);
113+
this._modalWindowStateService.setPicture(this.currentUser.pictureUrl);
113114
}
114115

115116
closeModalWindowClick(): void {
116-
this._modalWindowStateService.setIsModalWindowShowing(false)
117-
this._modalWindowStateService.setPictureNull()
117+
this._modalWindowStateService.setIsModalWindowShowing(false);
118+
this._modalWindowStateService.setPictureNull();
118119
}
119120

120121
onLogoutClick(): void {
@@ -187,7 +188,7 @@ export class SettingsComponent implements OnInit, OnDestroy {
187188
}
188189
}
189190

190-
onSaveChangesUpdateProfilePictureClick(): void {
191+
async onSaveChangesUpdateProfilePictureClick() {
191192
const formData = new FormData();
192193
const validationResult = this._validationService.validatePictureFileName(this.fileName);
193194

@@ -198,19 +199,17 @@ export class SettingsComponent implements OnInit, OnDestroy {
198199
const file = this.file as File;
199200
formData.append('pictureFile', file);
200201

201-
this._usersService
202-
.updateProfilePicture(formData)
203-
.pipe(takeUntil(this.componentDestroyed$))
204-
.subscribe({
205-
next: (response) => {
206-
this.clearProfilePictureFile();
207-
alert(response.message);
208-
this.currentUser.pictureUrl = response.newUserPictureUrl;
209-
},
210-
error: (error) => {
211-
this._errorNotificationService.notifyOnError(error);
212-
}
213-
});
202+
const updateProfileImage$ = this._usersService.updateProfilePicture(formData);
203+
204+
try {
205+
const result = await firstValueFrom<UpdateProfilePictureResponse>(updateProfileImage$);
206+
alert(result.message);
207+
this.currentUser.pictureUrl = result.newUserPictureUrl;
208+
} catch (e: any) {
209+
alert(e.error.errorMessage);
210+
}
211+
212+
this.clearProfilePictureFile();
214213
}
215214

216215
onSaveChangesChangePasswordClick(): void {
@@ -279,7 +278,14 @@ export class SettingsComponent implements OnInit, OnDestroy {
279278
};
280279
}
281280

282-
clearProfilePictureFile(): void {
281+
clearProfilePictureFile() {
282+
const fileInput = document.getElementById('ProfilePicture') as HTMLInputElement;
283+
284+
if (!fileInput) {
285+
return;
286+
}
287+
288+
fileInput.value = '';
283289
this.file = null;
284290
this.fileName = '';
285291
}

MangoAPI.Client/src/app/services/api/documents.service.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)