diff options
| author | Kamen Mladenov <kamen.d.mladenov@protonmail.com> | 2021-04-09 19:55:59 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-09 19:55:59 +0300 |
| commit | f849e37ccdd6fd48f83119a3b3b65cdd8b765dc3 (patch) | |
| tree | 83b88a773bb7dc053bb3aced35bce302264ec925 /src/app/components/comment-page | |
| parent | bcd88af53b1a920d728ec98b45daa9ac2e2c0917 (diff) | |
| parent | c13889759d70687de6833c505221c203f65fedb8 (diff) | |
| download | DevHive-Angular-f849e37ccdd6fd48f83119a3b3b65cdd8b765dc3.tar DevHive-Angular-f849e37ccdd6fd48f83119a3b3b65cdd8b765dc3.tar.gz DevHive-Angular-f849e37ccdd6fd48f83119a3b3b65cdd8b765dc3.zip | |
Second Stage: Complete
Diffstat (limited to 'src/app/components/comment-page')
3 files changed, 28 insertions, 101 deletions
diff --git a/src/app/components/comment-page/comment-page.component.css b/src/app/components/comment-page/comment-page.component.css index b886bc1..e69de29 100644 --- a/src/app/components/comment-page/comment-page.component.css +++ b/src/app/components/comment-page/comment-page.component.css @@ -1,27 +0,0 @@ -#content { - justify-content: flex-start !important; -} - -#content > * { - width: 100%; -} - -.many-buttons { - width: 100%; - display: flex; -} - -.many-buttons > * { - flex: 1; - margin-right: .3em; -} - -.many-buttons > *:last-of-type { - margin-right: 0; -} - -.submit-btn { - max-width: 98%; - margin: 0 auto; - margin-bottom: .5em; -} diff --git a/src/app/components/comment-page/comment-page.component.html b/src/app/components/comment-page/comment-page.component.html index 2d110d6..8a2ffe1 100644 --- a/src/app/components/comment-page/comment-page.component.html +++ b/src/app/components/comment-page/comment-page.component.html @@ -1,14 +1,18 @@ -<app-loading *ngIf="!loaded"></app-loading> +<app-navbar></app-navbar> -<div id="content" *ngIf="loaded"> - <button class="submit-btn" type="submit" (click)="toPost()">ᐊ Back to post</button> - <app-comment [paramId]="commentId.toString()"></app-comment> - <div class="many-buttons" *ngIf="editable"> - <button class="submit-btn" (click)="editComment()">Edit comment</button> - <button class="submit-btn delete-btn" (click)="deleteComment()">Delete comment</button> +<app-loading *ngIf="!dataArrived"></app-loading> + +<main class="centered-content scroll-standalone under-navbar flex-col" *ngIf="dataArrived"> + <app-post [paramId]="postId.toString()"></app-post> + <hr class="card-hr"> + <section class="card flex-col width-full margin-0-top"> + <button class="fg-focus border-faded-slim padding-dot2 lighter-hover click-effect border-radius-dot3" (click)="goToPostPage()"> + Show all comments + </button> + </section> + <div class="text-centered"> + ... </div> - <form [formGroup]="editCommentFormGroup" (ngSubmit)="editComment()"> - <input type="text" *ngIf="editingComment" placeholder="New comment message" class="input-field" formControlName="newCommentMessage"> - <input type="submit" style="display: none" /> - </form> -<div> + + <app-comment [paramId]="commentId.toString()"></app-comment> +</main> diff --git a/src/app/components/comment-page/comment-page.component.ts b/src/app/components/comment-page/comment-page.component.ts index bd4cfe5..4281e1c 100644 --- a/src/app/components/comment-page/comment-page.component.ts +++ b/src/app/components/comment-page/comment-page.component.ts @@ -1,12 +1,8 @@ -import { HttpErrorResponse } from '@angular/common/http'; import { Component, OnInit } from '@angular/core'; -import { FormBuilder, FormControl, FormGroup } from '@angular/forms'; import { Title } from '@angular/platform-browser'; 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'; @Component({ selector: 'app-comment-page', @@ -15,77 +11,31 @@ import { Comment } from 'src/models/comment'; }) export class CommentPageComponent implements OnInit { private _title = 'Comment'; - public loaded = false; - public loggedIn = false; - public editable = false; - public editingComment = false; + public dataArrived = false; + public postId: Guid; public commentId: Guid; - public comment: Comment; - public editCommentFormGroup: FormGroup; - constructor(private _titleService: Title, private _router: Router, private _fb: FormBuilder, private _tokenService: TokenService, private _commentService: CommentService){ + constructor(private _titleService: Title, private _router: Router, private _commentService: CommentService) { this._titleService.setTitle(this._title); } ngOnInit(): void { - this.loggedIn = this._tokenService.getTokenFromSessionStorage() !== ''; this.commentId = Guid.parse(this._router.url.substring(9)); + this.postId = Guid.createEmpty(); - // 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.comment = result as Comment; - if (this.loggedIn) { - this.editable = this.comment.issuerUsername === this._tokenService.getUsernameFromSessionStorageToken(); - } - this.loaded = true; + this._commentService.getCommentRequest(this.commentId).subscribe({ + next: (result: object) => { + this.postId = Object.values(result)[1]; + + this.dataArrived = true; }, - (err: HttpErrorResponse) => { + error: () => { this._router.navigate(['/not-found']); } - ); - - this.editCommentFormGroup = this._fb.group({ - newCommentMessage: new FormControl('') }); } - toPost(): void { - this._router.navigate(['/post/' + this.comment.postId]); - } - - editComment(): void { - if (this._tokenService.getTokenFromSessionStorage() === '') { - this._router.navigate(['/login']); - return; - } - - if (this.editingComment) { - const newMessage = this.editCommentFormGroup.get('newCommentMessage')?.value; - if (newMessage !== '') { - console.log(this.commentId); - this._commentService.putCommentWithSessionStorageRequest(this.commentId, this.comment.postId, newMessage).subscribe( - (result: object) => { - this.reloadPage(); - } - ); - } - } - this.editingComment = !this.editingComment; - } - - deleteComment(): void { - this._commentService.deleteCommentWithSessionStorage(this.commentId).subscribe( - (result: object) => { - this.toPost(); - } - ); - } - - private reloadPage(): void { - this._router.routeReuseStrategy.shouldReuseRoute = () => false; - this._router.onSameUrlNavigation = 'reload'; - this._router.navigate([this._router.url]); + goToPostPage(): void { + this._router.navigate(['/post/' + this.postId]); } } |
