aboutsummaryrefslogtreecommitdiff
path: root/src/app/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/components')
-rw-r--r--src/app/components/comment-page/comment-page.component.css26
-rw-r--r--src/app/components/comment-page/comment-page.component.html18
-rw-r--r--src/app/components/comment-page/comment-page.component.ts92
-rw-r--r--src/app/components/comment/comment.component.ts4
4 files changed, 0 insertions, 140 deletions
diff --git a/src/app/components/comment-page/comment-page.component.css b/src/app/components/comment-page/comment-page.component.css
deleted file mode 100644
index f9dc390..0000000
--- a/src/app/components/comment-page/comment-page.component.css
+++ /dev/null
@@ -1,26 +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 {
- 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
deleted file mode 100644
index 553b545..0000000
--- a/src/app/components/comment-page/comment-page.component.html
+++ /dev/null
@@ -1,18 +0,0 @@
-<app-navbar></app-navbar>
-
-<app-loading *ngIf="!loaded"></app-loading>
-
-<main id="content" class="scroll-standalone under-navbar" *ngIf="loaded">
- <nav>
- <button class="submit-btn" type="submit" (click)="toPost()">ᐊ Back to post</button>
- </nav>
- <app-comment [paramId]="commentId.toString()"></app-comment>
- <nav 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>
- </nav>
- <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>
-</main>
diff --git a/src/app/components/comment-page/comment-page.component.ts b/src/app/components/comment-page/comment-page.component.ts
deleted file mode 100644
index 5d256bf..0000000
--- a/src/app/components/comment-page/comment-page.component.ts
+++ /dev/null
@@ -1,92 +0,0 @@
-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.model';
-
-@Component({
- selector: 'app-comment-page',
- templateUrl: './comment-page.component.html',
- styleUrls: ['./comment-page.component.css']
-})
-export class CommentPageComponent implements OnInit {
- private _title = 'Comment';
- public loaded = false;
- public loggedIn = false;
- public editable = false;
- public editingComment = false;
- 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){
- this._titleService.setTitle(this._title);
- }
-
- ngOnInit(): void {
- this.loggedIn = this._tokenService.getTokenFromSessionStorage() !== '';
- this.commentId = Guid.parse(this._router.url.substring(9));
-
- // 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({
- next: (result: object) => {
- this.comment = result as Comment;
- if (this.loggedIn) {
- this.editable = this.comment.issuerUsername === this._tokenService.getUsernameFromSessionStorageToken();
- this.editCommentFormGroup.get('newCommentMessage')?.setValue(this.comment.message);
- }
- this.loaded = true;
- },
- 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 !== '' && newMessage !== this.comment.message) {
- console.log(this.commentId);
- 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({
- next: () => {
- this.toPost();
- }
- });
- }
-
- private reloadPage(): void {
- this._router.routeReuseStrategy.shouldReuseRoute = () => false;
- this._router.onSameUrlNavigation = 'reload';
- this._router.navigate([this._router.url]);
- }
-}
diff --git a/src/app/components/comment/comment.component.ts b/src/app/components/comment/comment.component.ts
index 7da896d..693fd43 100644
--- a/src/app/components/comment/comment.component.ts
+++ b/src/app/components/comment/comment.component.ts
@@ -47,8 +47,4 @@ export class CommentComponent implements OnInit {
goToAuthorProfile(): void {
this._router.navigate(['/profile/' + this.comment.issuerUsername]);
}
-
- goToCommentPage(): void {
- this._router.navigate(['/comment/' + this.comment.commentId]);
- }
}