aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSyndamia <kamen.d.mladenov@protonmail.com>2021-03-14 08:45:45 +0200
committerSyndamia <kamen.d.mladenov@protonmail.com>2021-03-14 08:45:45 +0200
commita643d5ca122b2546a02ec06e355c0d42661fdf24 (patch)
treea1a20d5cc4f0e3172660bda8729cd564e44eb26e /src
parent065bfead76fc9e94c8344d812ee7f5b214c74321 (diff)
downloadDevHive-Angular-a643d5ca122b2546a02ec06e355c0d42661fdf24.tar
DevHive-Angular-a643d5ca122b2546a02ec06e355c0d42661fdf24.tar.gz
DevHive-Angular-a643d5ca122b2546a02ec06e355c0d42661fdf24.zip
Updated profile and profile-setting's subscriptions to use an observer object
Diffstat (limited to 'src')
-rw-r--r--src/app/components/profile-settings/profile-settings.component.ts58
-rw-r--r--src/app/components/profile/profile.component.ts38
2 files changed, 49 insertions, 47 deletions
diff --git a/src/app/components/profile-settings/profile-settings.component.ts b/src/app/components/profile-settings/profile-settings.component.ts
index f3cd4c1..ba1fbb6 100644
--- a/src/app/components/profile-settings/profile-settings.component.ts
+++ b/src/app/components/profile-settings/profile-settings.component.ts
@@ -50,35 +50,35 @@ export class ProfileSettingsComponent implements OnInit {
this.availableTechnologies = [];
this.newProfilePicture = new File([], '');
- this._userService.getUserByUsernameRequest(this._urlUsername).subscribe(
- (res: object) => {
+ this._userService.getUserByUsernameRequest(this._urlUsername).subscribe({
+ next: (res: object) => {
Object.assign(this.user, res);
this.isAdminUser = this.user.roles.map(x => x.name).includes(AppConstants.ADMIN_ROLE_NAME);
this.finishUserLoading();
},
- () => {
+ error: () => {
this._router.navigate(['/not-found']);
}
- );
+ });
- this._languageService.getAllLanguagesWithSessionStorageRequest().subscribe(
- (result: object) => {
+ this._languageService.getAllLanguagesWithSessionStorageRequest().subscribe({
+ next: (result: object) => {
this.availableLanguages = result as Language[];
}
- );
- this._technologyService.getAllTechnologiesWithSessionStorageRequest().subscribe(
- (result: object) => {
+ });
+ this._technologyService.getAllTechnologiesWithSessionStorageRequest().subscribe({
+ next: (result: object) => {
this.availableTechnologies = result as Technology[];
}
- );
+ });
}
private finishUserLoading(): void {
if (sessionStorage.getItem('UserCred')) {
const userFromToken: User = this._userService.getDefaultUser();
- this._userService.getUserFromSessionStorageRequest().subscribe(
- (tokenRes: object) => {
+ this._userService.getUserFromSessionStorageRequest().subscribe({
+ next: (tokenRes: object) => {
Object.assign(userFromToken, tokenRes);
if (userFromToken.userName === this._urlUsername) {
@@ -89,10 +89,10 @@ export class ProfileSettingsComponent implements OnInit {
this.goToProfile();
}
},
- () => {
+ error: () => {
this.logout();
}
- );
+ });
}
else {
this.goToProfile();
@@ -147,9 +147,11 @@ export class ProfileSettingsComponent implements OnInit {
fileUpload: new FormControl('')
});
- this.updateUserFormGroup.valueChanges.subscribe(() => {
- this._successBar?.hideMsg();
- this._errorBar?.hideError();
+ this.updateUserFormGroup.valueChanges.subscribe({
+ next: () => {
+ this._successBar?.hideMsg();
+ this._errorBar?.hideError();
+ }
});
}
@@ -180,11 +182,11 @@ export class ProfileSettingsComponent implements OnInit {
return;
}
- this._userService.putProfilePictureFromSessionStorageRequest(this.newProfilePicture).subscribe(
- () => {
+ this._userService.putProfilePictureFromSessionStorageRequest(this.newProfilePicture).subscribe({
+ next: () => {
this.reloadPage();
}
- );
+ });
this.dataArrived = false;
}
@@ -195,14 +197,14 @@ export class ProfileSettingsComponent implements OnInit {
this.patchLanguagesControl();
this.patchTechnologiesControl();
- this._userService.putUserFromSessionStorageRequest(this.updateUserFormGroup, this.user.roles, this.user.friends).subscribe(
- () => {
+ this._userService.putUserFromSessionStorageRequest(this.updateUserFormGroup, this.user.roles, this.user.friends).subscribe({
+ next: () => {
this._successBar.showMsg('Profile updated successfully!');
},
- (err: HttpErrorResponse) => {
+ error: (err: HttpErrorResponse) => {
this._errorBar.showError(err);
}
- );
+ });
}
private patchLanguagesControl(): void {
@@ -284,14 +286,14 @@ export class ProfileSettingsComponent implements OnInit {
deleteAccount(): void {
if (this.deleteAccountConfirm) {
- this._userService.deleteUserFromSessionStorageRequest().subscribe(
- () => {
+ this._userService.deleteUserFromSessionStorageRequest().subscribe({
+ next: () => {
this.logout();
},
- (err: HttpErrorResponse) => {
+ error: (err: HttpErrorResponse) => {
this._errorBar.showError(err);
}
- );
+ });
this.dataArrived = false;
}
else {
diff --git a/src/app/components/profile/profile.component.ts b/src/app/components/profile/profile.component.ts
index eaa1bec..429b9b8 100644
--- a/src/app/components/profile/profile.component.ts
+++ b/src/app/components/profile/profile.component.ts
@@ -52,16 +52,16 @@ export class ProfileComponent implements OnInit {
password: new FormControl('')
});
- this._userService.getUserByUsernameRequest(this._urlUsername).subscribe(
- (res: object) => {
+ this._userService.getUserByUsernameRequest(this._urlUsername).subscribe({
+ next: (res: object) => {
Object.assign(this.user, res);
this.isAdminUser = this.user.roles.map(x => x.name).includes(AppConstants.ADMIN_ROLE_NAME);
this.loadLanguages();
},
- () => {
+ error: () => {
this._router.navigate(['/not-found']);
}
- );
+ });
}
private loadLanguages(): void {
@@ -91,17 +91,17 @@ export class ProfileComponent implements OnInit {
}
private loadPosts(): void {
- this._feedService.getUserPostsRequest(this.user.userName, this._currentPage++, this._timeLoaded, AppConstants.PAGE_SIZE).subscribe(
- (result: object) => {
+ this._feedService.getUserPostsRequest(this.user.userName, this._currentPage++, this._timeLoaded, AppConstants.PAGE_SIZE).subscribe({
+ next: (result: object) => {
const resultArr: Post[] = Object.values(result)[0];
this.userPosts.push(...resultArr);
this.finishUserLoading();
},
- () => {
+ error: () => {
this._currentPage = -1;
this.finishUserLoading();
}
- );
+ });
}
private finishUserLoading(): void {
@@ -109,8 +109,8 @@ export class ProfileComponent implements OnInit {
this.isUserLoggedIn = true;
const userFromToken: User = this._userService.getDefaultUser();
- this._userService.getUserFromSessionStorageRequest().subscribe(
- (tokenRes: object) => {
+ this._userService.getUserFromSessionStorageRequest().subscribe({
+ next: (tokenRes: object) => {
Object.assign(userFromToken, tokenRes);
if (userFromToken.friends.map(x => x.userName).includes(this._urlUsername)) {
@@ -121,10 +121,10 @@ export class ProfileComponent implements OnInit {
}
this.dataArrived = true;
},
- () => {
+ error: () => {
this.logout();
}
- );
+ });
}
else {
this.dataArrived = true;
@@ -156,8 +156,8 @@ export class ProfileComponent implements OnInit {
if (this.updatingFriendship) {
this.dataArrived = false;
- this._userService.getUserFromSessionStorageRequest().subscribe(
- (result: object) => {
+ this._userService.getUserFromSessionStorageRequest().subscribe({
+ next: (result: object) => {
const loggedInUser: User = result as User;
if (this.friendOfUser) {
@@ -169,16 +169,16 @@ export class ProfileComponent implements OnInit {
loggedInUser.friends.push(newFriend);
}
- this._userService.putBareUserFromSessionStorageRequest(loggedInUser, this.updateFrienship.get('password')?.value).subscribe(
- () => {
+ this._userService.putBareUserFromSessionStorageRequest(loggedInUser, this.updateFrienship.get('password')?.value).subscribe({
+ next: () => {
this.reloadPage();
},
- () => {
+ error: () => {
this._router.navigate(['/']);
}
- );
+ });
}
- );
+ });
}
this.updatingFriendship = !this.updatingFriendship;
}