diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-02-02 09:58:35 +0200 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-02-02 09:58:35 +0200 |
| commit | 560944597073a3a1d56e2bb2f4d43a756b3dccc5 (patch) | |
| tree | 3dd5a7205070918c68bd6788bd13a007317c626b /src/DevHive.Angular | |
| parent | 5532ef67ba0f040ee943e3b59370c679403c587f (diff) | |
| download | DevHive-560944597073a3a1d56e2bb2f4d43a756b3dccc5.tar DevHive-560944597073a3a1d56e2bb2f4d43a756b3dccc5.tar.gz DevHive-560944597073a3a1d56e2bb2f4d43a756b3dccc5.zip | |
Improved how post page handles user that isn't logged in
Diffstat (limited to 'src/DevHive.Angular')
| -rw-r--r-- | src/DevHive.Angular/src/app/components/post-page/post-page.component.html | 3 | ||||
| -rw-r--r-- | src/DevHive.Angular/src/app/components/post-page/post-page.component.ts | 17 |
2 files changed, 17 insertions, 3 deletions
diff --git a/src/DevHive.Angular/src/app/components/post-page/post-page.component.html b/src/DevHive.Angular/src/app/components/post-page/post-page.component.html index f22646d..08e63f9 100644 --- a/src/DevHive.Angular/src/app/components/post-page/post-page.component.html +++ b/src/DevHive.Angular/src/app/components/post-page/post-page.component.html @@ -1,8 +1,9 @@ <div id="content"> - <div class="many-buttons"> + <div class="many-buttons" *ngIf="loggedIn"> <button class="submit-btn" type="submit" (click)="backToFeed()">ᐊ Back to feed</button> <button class="submit-btn" type="submit" (click)="backToProfile()">ᐊ Back to profile</button> </div> + <button class="submit-btn" type="submit" (click)="toLogin()" *ngIf="!loggedIn">Login</button> <app-post [paramId]="postId.toString()"></app-post> <div class="many-buttons" *ngIf="editable"> <button class="submit-btn" (click)="editPost()">Edit post</button> diff --git a/src/DevHive.Angular/src/app/components/post-page/post-page.component.ts b/src/DevHive.Angular/src/app/components/post-page/post-page.component.ts index a7843e3..95bf58f 100644 --- a/src/DevHive.Angular/src/app/components/post-page/post-page.component.ts +++ b/src/DevHive.Angular/src/app/components/post-page/post-page.component.ts @@ -16,6 +16,7 @@ import { Post } from 'src/models/post'; }) export class PostPageComponent implements OnInit { private _title = 'Post'; + public loggedIn = false; public editable = false; public editingPost = false; public postId: Guid; @@ -28,6 +29,7 @@ export class PostPageComponent implements OnInit { } ngOnInit(): void { + this.loggedIn = this._tokenService.getTokenFromSessionStorage() !== ''; this.postId = Guid.parse(this._router.url.substring(6)); // Gets the post and the logged in user and compares them, @@ -35,7 +37,9 @@ export class PostPageComponent implements OnInit { this._postService.getPostRequest(this.postId).subscribe( (result: object) => { this.post = result as Post; - this.editable = this.post.creatorUsername === this._tokenService.getUsernameFromSessionStorageToken(); + if (this.loggedIn) { + this.editable = this.post.creatorUsername === this._tokenService.getUsernameFromSessionStorageToken(); + } }, (err: HttpErrorResponse) => { this._router.navigate(['/not-found']); @@ -59,9 +63,13 @@ export class PostPageComponent implements OnInit { this._router.navigate(['/profile/' + this.post.creatorUsername]); } + toLogin(): void { + this._router.navigate(['/login']); + } + editPost(): void { if (this._tokenService.getTokenFromSessionStorage() === '') { - this._router.navigate(['/login']); + this.toLogin(); return; } @@ -79,6 +87,11 @@ export class PostPageComponent implements OnInit { } addComment(): void { + if (!this.loggedIn) { + this._router.navigate(['/login']); + return; + } + const newComment = this.addCommentFormGroup.get('newComment')?.value; if (newComment !== '' && newComment !== null) { this._commentService.createCommentWithSessionStorageRequest(this.postId, newComment).subscribe( |
