diff options
23 files changed, 208 insertions, 224 deletions
diff --git a/src/app/components/admin-panel-page/admin-panel-page.component.ts b/src/app/components/admin-panel-page/admin-panel-page.component.ts index 95d69d3..9beb8bc 100644 --- a/src/app/components/admin-panel-page/admin-panel-page.component.ts +++ b/src/app/components/admin-panel-page/admin-panel-page.component.ts @@ -11,9 +11,9 @@ import { PostService } from 'src/app/services/post.service'; import { TechnologyService } from 'src/app/services/technology.service'; import { TokenService } from 'src/app/services/token.service'; import { UserService } from 'src/app/services/user.service'; -import { User } from 'src/models/identity/user'; -import { Language } from 'src/models/language'; -import { Technology } from 'src/models/technology'; +import { User } from 'src/models/identity/user.model'; +import { Language } from 'src/models/language.model'; +import { Technology } from 'src/models/technology.model'; import { ErrorBarComponent } from '../error-bar/error-bar.component'; import { SuccessBarComponent } from '../success-bar/success-bar.component'; @@ -46,17 +46,17 @@ export class AdminPanelPageComponent implements OnInit { return; } - this._userService.getUserFromSessionStorageRequest().subscribe( - (result: object) => { + this._userService.getUserFromSessionStorageRequest().subscribe({ + next: (result: object) => { const user = result as User; if (!user.roles.map(x => x.name).includes(AppConstants.ADMIN_ROLE_NAME)) { this._router.navigate(['/login']); } }, - () => { + error: () => { this._router.navigate(['/login']); } - ); + }); this.languageForm = this._fb.group({ languageCreate: new FormControl(''), @@ -65,9 +65,11 @@ export class AdminPanelPageComponent implements OnInit { deleteLanguageName: new FormControl('') }); - this.languageForm.valueChanges.subscribe(() => { - this._successBar?.hideMsg(); - this._errorBar?.hideError(); + this.languageForm.valueChanges.subscribe({ + next: () => { + this._successBar?.hideMsg(); + this._errorBar?.hideError(); + } }); this.technologyForm = this._fb.group({ @@ -77,9 +79,11 @@ export class AdminPanelPageComponent implements OnInit { deleteTechnologyName: new FormControl('') }); - this.technologyForm.valueChanges.subscribe(() => { - this._successBar?.hideMsg(); - this._errorBar?.hideError(); + this.technologyForm.valueChanges.subscribe({ + next: () => { + this._successBar?.hideMsg(); + this._errorBar?.hideError(); + } }); this.deleteForm = this._fb.group({ @@ -88,9 +92,11 @@ export class AdminPanelPageComponent implements OnInit { deleteComment: new FormControl('') }); - this.deleteForm.valueChanges.subscribe(() => { - this._successBar?.hideMsg(); - this._errorBar?.hideError(); + this.deleteForm.valueChanges.subscribe({ + next: () => { + this._successBar?.hideMsg(); + this._errorBar?.hideError(); + } }); this.loadAvailableLanguages(); @@ -128,14 +134,14 @@ export class AdminPanelPageComponent implements OnInit { const languageCreate: string = this.languageForm.get('languageCreate')?.value; if (languageCreate !== '' && languageCreate !== null) { - this._languageService.createLanguageWithSessionStorageRequest(languageCreate.trim()).subscribe( - () => { + this._languageService.createLanguageWithSessionStorageRequest(languageCreate.trim()).subscribe({ + next: () => { this.languageModifiedSuccess('Successfully updated languages!'); }, - (err: HttpErrorResponse) => { + error: (err: HttpErrorResponse) => { this._errorBar.showError(err); } - ); + }); } } @@ -146,14 +152,14 @@ export class AdminPanelPageComponent implements OnInit { if (updateLanguageOldName !== '' && updateLanguageOldName !== null && updateLanguageNewName !== '' && updateLanguageNewName !== null) { const langId = this.availableLanguages.filter(x => x.name === updateLanguageOldName.trim())[0].id; - this._languageService.putLanguageWithSessionStorageRequest(langId, updateLanguageNewName.trim()).subscribe( - () => { + this._languageService.putLanguageWithSessionStorageRequest(langId, updateLanguageNewName.trim()).subscribe({ + next: () => { this.languageModifiedSuccess('Successfully updated languages!'); }, - (err: HttpErrorResponse) => { + error: (err: HttpErrorResponse) => { this._errorBar.showError(err); } - ); + }); } } @@ -163,14 +169,14 @@ export class AdminPanelPageComponent implements OnInit { if (deleteLanguageName !== '' && deleteLanguageName !== null) { const langId = this.availableLanguages.filter(x => x.name === deleteLanguageName.trim())[0].id; - this._languageService.deleteLanguageWithSessionStorageRequest(langId).subscribe( - () => { + this._languageService.deleteLanguageWithSessionStorageRequest(langId).subscribe({ + next: () => { this.languageModifiedSuccess('Successfully deleted language!'); }, - (err: HttpErrorResponse) => { + error: (err: HttpErrorResponse) => { this._errorBar.showError(err); } - ); + }); } } @@ -181,11 +187,11 @@ export class AdminPanelPageComponent implements OnInit { } private loadAvailableLanguages(): void { - this._languageService.getAllLanguagesWithSessionStorageRequest().subscribe( - (result: object) => { + this._languageService.getAllLanguagesWithSessionStorageRequest().subscribe({ + next: (result: object) => { this.availableLanguages = result as Language[]; } - ); + }); } // Technology modifying @@ -204,14 +210,14 @@ export class AdminPanelPageComponent implements OnInit { const technologyCreate: string = this.technologyForm.get('technologyCreate')?.value; if (technologyCreate !== '' && technologyCreate !== null) { - this._technologyService.createTechnologyWithSessionStorageRequest(technologyCreate.trim()).subscribe( - () => { + this._technologyService.createTechnologyWithSessionStorageRequest(technologyCreate.trim()).subscribe({ + next: () => { this.technologyModifiedSuccess('Successfully updated technologies!'); }, - (err: HttpErrorResponse) => { + error: (err: HttpErrorResponse) => { this._errorBar.showError(err); } - ); + }); } } @@ -222,14 +228,14 @@ export class AdminPanelPageComponent implements OnInit { if (updateTechnologyOldName !== '' && updateTechnologyOldName !== null && updateTechnologyNewName !== '' && updateTechnologyNewName !== null) { const techId = this.availableTechnologies.filter(x => x.name === updateTechnologyOldName.trim())[0].id; - this._technologyService.putTechnologyWithSessionStorageRequest(techId, updateTechnologyNewName.trim()).subscribe( - () => { + this._technologyService.putTechnologyWithSessionStorageRequest(techId, updateTechnologyNewName.trim()).subscribe({ + next: () => { this.technologyModifiedSuccess('Successfully updated technologies!'); }, - (err: HttpErrorResponse) => { + error: (err: HttpErrorResponse) => { this._errorBar.showError(err); } - ); + }); } } @@ -239,14 +245,14 @@ export class AdminPanelPageComponent implements OnInit { if (deleteTechnologyName !== '' && deleteTechnologyName !== null) { const techId = this.availableTechnologies.filter(x => x.name === deleteTechnologyName.trim())[0].id; - this._technologyService.deleteTechnologyWithSessionStorageRequest(techId).subscribe( - () => { + this._technologyService.deleteTechnologyWithSessionStorageRequest(techId).subscribe({ + next: () => { this.technologyModifiedSuccess('Successfully deleted technology!'); }, - (err: HttpErrorResponse) => { + error: (err: HttpErrorResponse) => { this._errorBar.showError(err); } - ); + }); } } @@ -257,11 +263,11 @@ export class AdminPanelPageComponent implements OnInit { } private loadAvailableTechnologies(): void { - this._technologyService.getAllTechnologiesWithSessionStorageRequest().subscribe( - (result: object) => { + this._technologyService.getAllTechnologiesWithSessionStorageRequest().subscribe({ + next: (result: object) => { this.availableTechnologies = result as Technology[]; } - ); + }); } // Deletions @@ -282,14 +288,14 @@ export class AdminPanelPageComponent implements OnInit { if (deleteUser !== '' && deleteUser !== null) { const userId: Guid = Guid.parse(deleteUser); - this._userService.deleteUserRequest(userId, this._tokenService.getTokenFromSessionStorage()).subscribe( - () => { + this._userService.deleteUserRequest(userId, this._tokenService.getTokenFromSessionStorage()).subscribe({ + next: () => { this.deletionSuccess('Successfully deleted user!'); }, - (err: HttpErrorResponse) => { + error: (err: HttpErrorResponse) => { this._errorBar.showError(err); } - ); + }); } } @@ -299,14 +305,14 @@ export class AdminPanelPageComponent implements OnInit { if (deletePost !== '' && deletePost !== null) { const postId: Guid = Guid.parse(deletePost); - this._postService.deletePostRequest(postId, this._tokenService.getTokenFromSessionStorage()).subscribe( - () => { + this._postService.deletePostRequest(postId, this._tokenService.getTokenFromSessionStorage()).subscribe({ + next: () => { this.deletionSuccess('Successfully deleted user!'); }, - (err: HttpErrorResponse) => { + error: (err: HttpErrorResponse) => { this._errorBar.showError(err); } - ); + }); } } @@ -316,14 +322,14 @@ export class AdminPanelPageComponent implements OnInit { if (deleteComment !== '' && deleteComment !== null) { const commentId: Guid = Guid.parse(deleteComment); - this._commentService.deleteCommentWithSessionStorage(commentId).subscribe( - () => { + this._commentService.deleteCommentWithSessionStorage(commentId).subscribe({ + next: () => { this.deletionSuccess('Successfully deleted comment!'); }, - (err: HttpErrorResponse) => { + error: (err: HttpErrorResponse) => { this._errorBar.showError(err); } - ); + }); } } diff --git a/src/app/components/comment-page/comment-page.component.ts b/src/app/components/comment-page/comment-page.component.ts index 413436e..5d256bf 100644 --- a/src/app/components/comment-page/comment-page.component.ts +++ b/src/app/components/comment-page/comment-page.component.ts @@ -5,7 +5,7 @@ import { Router } from '@angular/router'; import { Guid } from 'guid-typescript'; import { CommentService } from 'src/app/services/comment.service'; import { TokenService } from 'src/app/services/token.service'; -import { Comment } from 'src/models/comment'; +import { Comment } from 'src/models/comment.model'; @Component({ selector: 'app-comment-page', @@ -32,8 +32,8 @@ export class CommentPageComponent implements OnInit { // Gets the post and the logged in user and compares them, // to determine if the current post is made by the user - this._commentService.getCommentRequest(this.commentId).subscribe( - (result: object) => { + this._commentService.getCommentRequest(this.commentId).subscribe({ + next: (result: object) => { this.comment = result as Comment; if (this.loggedIn) { this.editable = this.comment.issuerUsername === this._tokenService.getUsernameFromSessionStorageToken(); @@ -41,10 +41,10 @@ export class CommentPageComponent implements OnInit { } this.loaded = true; }, - () => { + error: () => { this._router.navigate(['/not-found']); } - ); + }); this.editCommentFormGroup = this._fb.group({ newCommentMessage: new FormControl('') @@ -66,22 +66,22 @@ export class CommentPageComponent implements OnInit { if (newMessage !== '' && newMessage !== this.comment.message) { console.log(this.commentId); - this._commentService.putCommentWithSessionStorageRequest(this.commentId, this.comment.postId, newMessage).subscribe( - () => { + this._commentService.putCommentWithSessionStorageRequest(this.commentId, this.comment.postId, newMessage).subscribe({ + next: () => { this.reloadPage(); } - ); + }); } } this.editingComment = !this.editingComment; } deleteComment(): void { - this._commentService.deleteCommentWithSessionStorage(this.commentId).subscribe( - () => { + this._commentService.deleteCommentWithSessionStorage(this.commentId).subscribe({ + next: () => { this.toPost(); } - ); + }); } private reloadPage(): void { diff --git a/src/app/components/comment/comment.component.ts b/src/app/components/comment/comment.component.ts index 5076769..7da896d 100644 --- a/src/app/components/comment/comment.component.ts +++ b/src/app/components/comment/comment.component.ts @@ -3,8 +3,8 @@ import { Router } from '@angular/router'; import { Guid } from 'guid-typescript'; import { CommentService } from 'src/app/services/comment.service'; import { UserService } from 'src/app/services/user.service'; -import { Comment } from 'src/models/comment'; -import { User } from 'src/models/identity/user'; +import { Comment } from 'src/models/comment.model'; +import { User } from 'src/models/identity/user.model'; @Component({ selector: 'app-comment', @@ -25,23 +25,23 @@ export class CommentComponent implements OnInit { this.comment = this._commentService.getDefaultComment(); this.user = this._userService.getDefaultUser(); - this._commentService.getCommentRequest(Guid.parse(this.paramId)).subscribe( - (result: object) => { + this._commentService.getCommentRequest(Guid.parse(this.paramId)).subscribe({ + next: (result: object) => { Object.assign(this.comment, result); this.timeCreated = new Date(this.comment.timeCreated).toLocaleString('en-GB'); this.loadUser(); } - ); + }); } private loadUser(): void { - this._userService.getUserByUsernameRequest(this.comment.issuerUsername).subscribe( - (result: object) => { + this._userService.getUserByUsernameRequest(this.comment.issuerUsername).subscribe({ + next: (result: object) => { Object.assign(this.user, result); this.loaded = true; } - ); + }); } goToAuthorProfile(): void { diff --git a/src/app/components/feed/feed.component.ts b/src/app/components/feed/feed.component.ts index eaa0ef1..895bf76 100644 --- a/src/app/components/feed/feed.component.ts +++ b/src/app/components/feed/feed.component.ts @@ -1,11 +1,11 @@ import { Component, OnInit } from '@angular/core'; import { Title } from '@angular/platform-browser'; import { Router } from '@angular/router'; -import { User } from 'src/models/identity/user'; +import { User } from 'src/models/identity/user.model'; import { UserService } from '../../services/user.service'; import { AppConstants } from 'src/app/app-constants.module'; import { FeedService } from 'src/app/services/feed.service'; -import { Post } from 'src/models/post'; +import { Post } from 'src/models/post.model'; import { FormBuilder, FormControl, FormGroup } from '@angular/forms'; import { PostService } from 'src/app/services/post.service'; import { TokenService } from 'src/app/services/token.service'; @@ -49,27 +49,27 @@ export class FeedComponent implements OnInit { fileUpload: new FormControl('') }); - this._userService.getUserFromSessionStorageRequest().subscribe( - (res: object) => { + this._userService.getUserFromSessionStorageRequest().subscribe({ + next: (res: object) => { Object.assign(this.user, res); this.loadFeed(); }, - () => { + error: () => { this.logout(); } - ); + }); } private loadFeed(): void { - this._feedService.getUserFeedFromSessionStorageRequest(this._currentPage++, this._timeLoaded, AppConstants.PAGE_SIZE).subscribe( - (result: object) => { + this._feedService.getUserFeedFromSessionStorageRequest(this._currentPage++, this._timeLoaded, AppConstants.PAGE_SIZE).subscribe({ + next: (result: object) => { this.posts.push(...Object.values(result)[0]); this.finishUserLoading(); }, - () => { + error: () => { this.finishUserLoading(); } - ); + }); } private finishUserLoading(): void { @@ -102,14 +102,14 @@ export class FeedComponent implements OnInit { const postMessage = this.createPostFormGroup.get('newPostMessage')?.value; this.dataArrived = false; - this._postService.createPostWithSessionStorageRequest(postMessage, this.files).subscribe( - () => { + this._postService.createPostWithSessionStorageRequest(postMessage, this.files).subscribe({ + next: () => { this.goToProfile(); }, - () => { + error: () => { this.dataArrived = true; } - ); + }); } onScroll(event: any): void { diff --git a/src/app/components/login/login.component.ts b/src/app/components/login/login.component.ts index c3fb79c..edbc461 100644 --- a/src/app/components/login/login.component.ts +++ b/src/app/components/login/login.component.ts @@ -1,5 +1,5 @@ import { Component, OnInit, ViewChild } from '@angular/core'; -import { FormGroup, FormBuilder, Validators, FormControl, AbstractControl } from '@angular/forms'; +import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms'; import { Router } from '@angular/router'; import { Title } from '@angular/platform-browser'; import { UserService } from 'src/app/services/user.service'; @@ -34,26 +34,18 @@ export class LoginComponent implements OnInit { onSubmit(): void { this._errorBar.hideError(); - this._userService.loginUserRequest(this.loginUserFormGroup).subscribe( - (res: object) => { + this._userService.loginUserRequest(this.loginUserFormGroup).subscribe({ + next: (res: object) => { this._tokenService.setUserTokenToSessionStorage(res); this._router.navigate(['/']); }, - (err: HttpErrorResponse) => { + error: (err: HttpErrorResponse) => { this._errorBar.showError(err); } - ); + }); } onRedirectRegister(): void { this._router.navigate(['/register']); } - - get username(): AbstractControl | null { - return this.loginUserFormGroup.get('username'); - } - - get password(): AbstractControl | null { - return this.loginUserFormGroup.get('password'); - } } diff --git a/src/app/components/post-page/post-page.component.ts b/src/app/components/post-page/post-page.component.ts index 1ac89f4..a60f4da 100644 --- a/src/app/components/post-page/post-page.component.ts +++ b/src/app/components/post-page/post-page.component.ts @@ -6,7 +6,7 @@ import { Guid } from 'guid-typescript'; import { CommentService } from 'src/app/services/comment.service'; import { PostService } from 'src/app/services/post.service'; import { TokenService } from 'src/app/services/token.service'; -import { Post } from 'src/models/post'; +import { Post } from 'src/models/post.model'; import { CloudinaryService } from 'src/app/services/cloudinary.service'; @Component({ @@ -37,8 +37,8 @@ export class PostPageComponent implements OnInit { // Gets the post and the logged in user and compares them, // to determine if the current post is made by the user - this._postService.getPostRequest(this.postId).subscribe( - (result: object) => { + this._postService.getPostRequest(this.postId).subscribe({ + next: (result: object) => { this.post = result as Post; this.post.fileURLs = Object.values(result)[7]; if (this.loggedIn) { @@ -52,10 +52,10 @@ export class PostPageComponent implements OnInit { this.dataArrived = true; } }, - () => { + error: () => { this._router.navigate(['/not-found']); } - ); + }); this.editPostFormGroup = this._fb.group({ newPostMessage: new FormControl(''), @@ -69,8 +69,8 @@ export class PostPageComponent implements OnInit { private loadFiles(): void { for (const fileURL of this.post.fileURLs) { - this._cloudinaryService.getFileRequest(fileURL).subscribe( - (result: object) => { + this._cloudinaryService.getFileRequest(fileURL).subscribe({ + next: (result: object) => { const file = result as File; const tmp = { name: fileURL.match('(?<=\/)(?:.(?!\/))+$')?.pop() ?? 'Attachment' @@ -83,7 +83,7 @@ export class PostPageComponent implements OnInit { this.dataArrived = true; } } - ); + }); } } @@ -118,11 +118,11 @@ export class PostPageComponent implements OnInit { const newMessage = this.editPostFormGroup.get('newPostMessage')?.value; if (newMessage === '' && newMessage !== this.post.message) { - this._postService.putPostWithSessionStorageRequest(this.postId, newMessage, this.files).subscribe( - () => { + this._postService.putPostWithSessionStorageRequest(this.postId, newMessage, this.files).subscribe({ + next: () => { this.reloadPage(); } - ); + }); this.dataArrived = false; } } @@ -137,21 +137,21 @@ export class PostPageComponent implements OnInit { const newComment = this.addCommentFormGroup.get('newComment')?.value; if (newComment !== '' && newComment !== null) { - this._commentService.createCommentWithSessionStorageRequest(this.postId, newComment).subscribe( - () => { + this._commentService.createCommentWithSessionStorageRequest(this.postId, newComment).subscribe({ + next: () => { this.editPostFormGroup.reset(); this.reloadPage(); } - ); + }); } } deletePost(): void { - this._postService.deletePostWithSessionStorage(this.postId).subscribe( - () => { + this._postService.deletePostWithSessionStorage(this.postId).subscribe({ + next: () => { this._router.navigate(['/profile/' + this._tokenService.getUsernameFromSessionStorageToken()]); } - ); + }); } private reloadPage(): void { diff --git a/src/app/components/post/post.component.ts b/src/app/components/post/post.component.ts index 387f56f..fa5ac2f 100644 --- a/src/app/components/post/post.component.ts +++ b/src/app/components/post/post.component.ts @@ -3,8 +3,8 @@ import { Router } from '@angular/router'; import { Guid } from 'guid-typescript'; import { PostService } from 'src/app/services/post.service'; import { UserService } from 'src/app/services/user.service'; -import { User } from 'src/models/identity/user'; -import { Post } from 'src/models/post'; +import { User } from 'src/models/identity/user.model'; +import { Post } from 'src/models/post.model'; @Component({ selector: 'app-post', @@ -26,8 +26,8 @@ export class PostComponent implements OnInit { this.post = this._postService.getDefaultPost(); this.user = this._userService.getDefaultUser(); - this._postService.getPostRequest(Guid.parse(this.paramId)).subscribe( - (result: object) => { + this._postService.getPostRequest(Guid.parse(this.paramId)).subscribe({ + next: (result: object) => { Object.assign(this.post, result); this.post.fileURLs = Object.values(result)[7]; this.votesNumber = 23; @@ -35,16 +35,16 @@ export class PostComponent implements OnInit { this.timeCreated = new Date(this.post.timeCreated).toLocaleString('en-GB'); this.loadUser(); } - ); + }); } private loadUser(): void { - this._userService.getUserByUsernameRequest(this.post.creatorUsername).subscribe( - (result: object) => { + this._userService.getUserByUsernameRequest(this.post.creatorUsername).subscribe({ + next: (result: object) => { Object.assign(this.user, result); this.loaded = true; } - ); + }); } goToAuthorProfile(): void { diff --git a/src/app/components/profile-settings/profile-settings.component.ts b/src/app/components/profile-settings/profile-settings.component.ts index f3cd4c1..b856bef 100644 --- a/src/app/components/profile-settings/profile-settings.component.ts +++ b/src/app/components/profile-settings/profile-settings.component.ts @@ -6,11 +6,11 @@ import { Router } from '@angular/router'; import { LanguageService } from 'src/app/services/language.service'; import { UserService } from 'src/app/services/user.service'; import { TechnologyService } from 'src/app/services/technology.service'; -import { User } from 'src/models/identity/user'; +import { User } from 'src/models/identity/user.model'; import { ErrorBarComponent } from '../error-bar/error-bar.component'; import { SuccessBarComponent } from '../success-bar/success-bar.component'; -import { Language } from 'src/models/language'; -import { Technology } from 'src/models/technology'; +import { Language } from 'src/models/language.model'; +import { Technology } from 'src/models/technology.model'; import { TokenService } from 'src/app/services/token.service'; import { Title } from '@angular/platform-browser'; import { AppConstants } from 'src/app/app-constants.module'; @@ -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..ed17f33 100644 --- a/src/app/components/profile/profile.component.ts +++ b/src/app/components/profile/profile.component.ts @@ -1,16 +1,16 @@ import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; import { UserService } from 'src/app/services/user.service'; -import { User } from 'src/models/identity/user'; +import { User } from 'src/models/identity/user.model'; import { AppConstants } from 'src/app/app-constants.module'; import { Location } from '@angular/common'; import { LanguageService } from 'src/app/services/language.service'; import { TechnologyService } from 'src/app/services/technology.service'; -import { Post } from 'src/models/post'; +import { Post } from 'src/models/post.model'; import { FeedService } from 'src/app/services/feed.service'; import { TokenService } from 'src/app/services/token.service'; import { Title } from '@angular/platform-browser'; -import { Friend } from 'src/models/identity/friend'; +import { Friend } from 'src/models/identity/friend.model'; import { FormBuilder, FormControl, FormGroup } from '@angular/forms'; @Component({ @@ -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,20 +169,24 @@ export class ProfileComponent implements OnInit { loggedInUser.friends.push(newFriend); } - this._userService.putBareUserFromSessionStorageRequest(loggedInUser, this.updateFrienship.get('password')?.value).subscribe( - () => { - this.reloadPage(); - }, - () => { - this._router.navigate(['/']); - } - ); + this.updateUserWithNewFriends(loggedInUser); } - ); + }); } this.updatingFriendship = !this.updatingFriendship; } + private updateUserWithNewFriends(loggedInUser: User): void { + this._userService.putBareUserFromSessionStorageRequest(loggedInUser, this.updateFrienship.get('password')?.value).subscribe({ + next: () => { + this.reloadPage(); + }, + error: () => { + this._router.navigate(['/']); + } + }); + } + onScroll(event: any): void { // Detects when the element has reached the bottom, thx https://stackoverflow.com/a/50038429/12036073 if (event.target.offsetHeight + event.target.scrollTop >= event.target.scrollHeight && this._currentPage > 0) { diff --git a/src/app/components/register/register.component.ts b/src/app/components/register/register.component.ts index 36eaa55..07b8976 100644 --- a/src/app/components/register/register.component.ts +++ b/src/app/components/register/register.component.ts @@ -1,6 +1,6 @@ import { HttpErrorResponse } from '@angular/common/http'; import { Component, OnInit, ViewChild } from '@angular/core'; -import { AbstractControl, FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; +import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; import { Title } from '@angular/platform-browser'; import { Router } from '@angular/router'; import { TokenService } from 'src/app/services/token.service'; @@ -50,37 +50,17 @@ export class RegisterComponent implements OnInit { } onSubmit(): void { - this._userService.registerUserRequest(this.registerUserFormGroup).subscribe( - res => { + this._userService.registerUserRequest(this.registerUserFormGroup).subscribe({ + next: (res: object) => { this._tokenService.setUserTokenToSessionStorage(res); this._router.navigate(['/']); }, - (err: HttpErrorResponse) => { + error: (err: HttpErrorResponse) => { this._errorBar.showError(err); } - ); + }); } onRedirectLogin(): void { this._router.navigate(['/login']); } - - get firstName(): AbstractControl | null { - return this.registerUserFormGroup.get('firstName'); - } - - get lastName(): AbstractControl | null { - return this.registerUserFormGroup.get('lastName'); - } - - get username(): AbstractControl | null { - return this.registerUserFormGroup.get('username'); - } - - get email(): AbstractControl | null { - return this.registerUserFormGroup.get('email'); - } - - get password(): AbstractControl | null { - return this.registerUserFormGroup.get('password'); - } } diff --git a/src/app/services/comment.service.ts b/src/app/services/comment.service.ts index c9dbf35..29707ab 100644 --- a/src/app/services/comment.service.ts +++ b/src/app/services/comment.service.ts @@ -2,7 +2,7 @@ import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Guid } from 'guid-typescript'; import { Observable } from 'rxjs'; -import { Comment } from 'src/models/comment'; +import { Comment } from 'src/models/comment.model'; import { AppConstants } from '../app-constants.module'; import { TokenService } from './token.service'; diff --git a/src/app/services/language.service.ts b/src/app/services/language.service.ts index 15e241f..5846dd6 100644 --- a/src/app/services/language.service.ts +++ b/src/app/services/language.service.ts @@ -2,7 +2,7 @@ import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Guid } from 'guid-typescript'; import { Observable } from 'rxjs'; -import { Language } from 'src/models/language'; +import { Language } from 'src/models/language.model'; import { AppConstants } from '../app-constants.module'; import { TokenService } from './token.service'; diff --git a/src/app/services/post.service.ts b/src/app/services/post.service.ts index 7b2a539..eb613a6 100644 --- a/src/app/services/post.service.ts +++ b/src/app/services/post.service.ts @@ -3,7 +3,7 @@ import { Injectable } from '@angular/core'; import * as FormData from 'form-data'; import { Guid } from 'guid-typescript'; import { Observable } from 'rxjs'; -import { Post } from 'src/models/post'; +import { Post } from 'src/models/post.model'; import { AppConstants } from '../app-constants.module'; import { TokenService } from './token.service'; diff --git a/src/app/services/technology.service.ts b/src/app/services/technology.service.ts index dbdc039..fcc3d4c 100644 --- a/src/app/services/technology.service.ts +++ b/src/app/services/technology.service.ts @@ -2,7 +2,7 @@ import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Guid } from 'guid-typescript'; import { Observable } from 'rxjs'; -import { Technology } from 'src/models/technology'; +import { Technology } from 'src/models/technology.model'; import { AppConstants } from '../app-constants.module'; import { TokenService } from './token.service'; diff --git a/src/app/services/user.service.ts b/src/app/services/user.service.ts index 31862c4..f22952e 100644 --- a/src/app/services/user.service.ts +++ b/src/app/services/user.service.ts @@ -1,12 +1,12 @@ import { Injectable } from '@angular/core'; import { Guid } from 'guid-typescript'; -import { User } from '../../models/identity/user'; +import { User } from '../../models/identity/user.model'; import { FormGroup } from '@angular/forms'; import { AppConstants } from 'src/app/app-constants.module'; import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { Observable } from 'rxjs'; -import { Role } from 'src/models/identity/role'; -import { Friend } from 'src/models/identity/friend'; +import { Role } from 'src/models/identity/role.model'; +import { Friend } from 'src/models/identity/friend.model'; import { TokenService } from './token.service'; @Injectable({ diff --git a/src/models/comment.ts b/src/models/comment.model.ts index 0d1755f..0d1755f 100644 --- a/src/models/comment.ts +++ b/src/models/comment.model.ts diff --git a/src/models/identity/friend.ts b/src/models/identity/friend.model.ts index 22290cd..22290cd 100644 --- a/src/models/identity/friend.ts +++ b/src/models/identity/friend.model.ts diff --git a/src/models/identity/role.ts b/src/models/identity/role.model.ts index 132b0b0..132b0b0 100644 --- a/src/models/identity/role.ts +++ b/src/models/identity/role.model.ts diff --git a/src/models/identity/user.ts b/src/models/identity/user.model.ts index e0038e0..e2f54a4 100644 --- a/src/models/identity/user.ts +++ b/src/models/identity/user.model.ts @@ -1,8 +1,8 @@ import { Guid } from 'guid-typescript'; -import { Language } from '../language'; -import { Technology } from '../technology'; -import { Friend } from './friend'; -import { Role } from './role'; +import { Language } from '../language.model'; +import { Technology } from '../technology.model'; +import { Friend } from './friend.model'; +import { Role } from './role.model'; export class User { private _id : Guid; diff --git a/src/models/language.ts b/src/models/language.model.ts index e3aa61e..e3aa61e 100644 --- a/src/models/language.ts +++ b/src/models/language.model.ts diff --git a/src/models/post-comment.ts b/src/models/post-comment.model.ts index 5d1e346..5d1e346 100644 --- a/src/models/post-comment.ts +++ b/src/models/post-comment.model.ts diff --git a/src/models/post.ts b/src/models/post.model.ts index 8e58bea..e0fcd5b 100644 --- a/src/models/post.ts +++ b/src/models/post.model.ts @@ -1,6 +1,6 @@ import { Guid } from 'guid-typescript'; -import { Comment } from './comment'; -import { PostComment } from './post-comment'; +import { Comment } from './comment.model'; +import { PostComment } from './post-comment.model'; export class Post { private _postId: Guid; diff --git a/src/models/technology.ts b/src/models/technology.model.ts index 1869d14..1869d14 100644 --- a/src/models/technology.ts +++ b/src/models/technology.model.ts |
