diff --git a/src/app/pages/post/components/comment-tree/comment-tree.component.html b/src/app/pages/post/components/comment-tree/comment-tree.component.html index 595fb35..d145cb6 100644 --- a/src/app/pages/post/components/comment-tree/comment-tree.component.html +++ b/src/app/pages/post/components/comment-tree/comment-tree.component.html @@ -7,11 +7,14 @@ {{ item.user.name }} - > + + + + Submit + diff --git a/src/app/pages/post/components/comment-tree/comment-tree.component.ts b/src/app/pages/post/components/comment-tree/comment-tree.component.ts index d1fe0b5..345b815 100644 --- a/src/app/pages/post/components/comment-tree/comment-tree.component.ts +++ b/src/app/pages/post/components/comment-tree/comment-tree.component.ts @@ -1,16 +1,24 @@ -import { Component, Input, OnInit } from "@angular/core"; +import { Component, EventEmitter, Input, OnInit, Output } from "@angular/core"; import { CommentDetail } from "src/app/api/types/comment-detail"; @Component({ selector: "app-comment-tree", templateUrl: "./comment-tree.component.html", - styleUrls: ["./comment-tree.component.scss"] + styleUrls: ["./comment-tree.component.scss"], }) export class CommentTreeComponent implements OnInit { @Input() comments: CommentDetail[]; // @Input() depth = 0; + @Output() addComment: EventEmitter = new EventEmitter(); + + newComment = ""; constructor() {} ngOnInit() {} + + add() { + this.addComment.emit(this.newComment); + this.newComment = ""; + } } diff --git a/src/app/pages/post/components/stats/stats.component.html b/src/app/pages/post/components/stats/stats.component.html index f8b0614..748604e 100644 --- a/src/app/pages/post/components/stats/stats.component.html +++ b/src/app/pages/post/components/stats/stats.component.html @@ -1,11 +1,11 @@
- {{ stats.upvotes }} - {{ stats.downvotes }} - + > -->
diff --git a/src/app/pages/post/components/stats/stats.component.ts b/src/app/pages/post/components/stats/stats.component.ts index 04d3e6b..4b3794b 100644 --- a/src/app/pages/post/components/stats/stats.component.ts +++ b/src/app/pages/post/components/stats/stats.component.ts @@ -12,10 +12,18 @@ export class StatsComponent implements OnInit { @Input() size = "default"; @Input() fill = "solid"; - @Output() upvoteCallback: EventEmitter; - @Output() downvoteCallback: EventEmitter; + @Output() upvoteCallback: EventEmitter = new EventEmitter(); + @Output() downvoteCallback: EventEmitter = new EventEmitter(); constructor() {} ngOnInit() {} + + upvote() { + this.upvoteCallback.emit(); + } + + downvote() { + this.downvoteCallback.emit(); + } } diff --git a/src/app/pages/post/post-detail/post-detail.component.html b/src/app/pages/post/post-detail/post-detail.component.html index 9851601..3b81434 100644 --- a/src/app/pages/post/post-detail/post-detail.component.html +++ b/src/app/pages/post/post-detail/post-detail.component.html @@ -10,8 +10,16 @@ - - + + Comments: + diff --git a/src/app/pages/post/post-detail/post-detail.component.ts b/src/app/pages/post/post-detail/post-detail.component.ts index b3c5d97..b945c11 100644 --- a/src/app/pages/post/post-detail/post-detail.component.ts +++ b/src/app/pages/post/post-detail/post-detail.component.ts @@ -17,4 +17,34 @@ export class PostDetailComponent implements OnInit { ngOnInit() { this.item = this.activatedRoute.snapshot.data.post; } + + upvote(event) { + if (this.item["alreadyUpvoted"] === true) { + } else { + this.service + .upvote(this.item.id) + .toPromise() + .then((post) => { + this.item.stats = post.stats; + this.item["alreadyUpvoted"] = true; + }); + } + } + + downvote(event) { + if (this.item["alreadyDownvoted"] === true) { + } else { + this.service + .downvote(this.item.id) + .toPromise() + .then((post) => { + this.item.stats = post.stats; + this.item["alreadyDownvoted"] = true; + }); + } + } + + addComment(event) { + this.service.addComment(this.item.id, event); + } } diff --git a/src/app/pages/post/post-overview/post-overview.component.html b/src/app/pages/post/post-overview/post-overview.component.html index 0598313..f1c90a3 100644 --- a/src/app/pages/post/post-overview/post-overview.component.html +++ b/src/app/pages/post/post-overview/post-overview.component.html @@ -1,6 +1,6 @@ - + - + diff --git a/src/app/pages/post/post-overview/post-overview.component.ts b/src/app/pages/post/post-overview/post-overview.component.ts index 7e089f4..f908034 100644 --- a/src/app/pages/post/post-overview/post-overview.component.ts +++ b/src/app/pages/post/post-overview/post-overview.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit, ViewChild } from "@angular/core"; import { ActivatedRoute } from "@angular/router"; -import { IonInfiniteScroll, IonVirtualScroll } from "@ionic/angular"; +import { IonInfiniteScroll, IonVirtualScroll, Platform } from "@ionic/angular"; import { PostApiService } from "../../../api/apis/posts.api"; import { PostDetail } from "../../../api/types/post-detail"; @@ -16,9 +16,16 @@ export class PostOverviewComponent implements OnInit { items: PostDetail[] = []; - constructor(private service: PostApiService, private activatedRoute: ActivatedRoute) {} + constructor( + private service: PostApiService, + private activatedRoute: ActivatedRoute, + private platform: Platform + ) {} ngOnInit() { + // this.platform.backButton.subscribe(() => { + // navigator["app"].exitApp(); + // }); this.items = this.activatedRoute.snapshot.data.initialPosts; } @@ -37,6 +44,34 @@ export class PostOverviewComponent implements OnInit { }, 2000); } + upvote(event, id) { + const item = this.items.find((x) => x.id === id); + if (item["alreadyUpvoted"] === true) { + } else { + this.service + .upvote(id) + .toPromise() + .then((post) => { + item.stats = post.stats; + item["alreadyUpvoted"] = true; + }); + } + } + + downvote(event, id) { + const item = this.items.find((x) => x.id === id); + if (item["alreadyDownvoted"] === true) { + } else { + this.service + .downvote(id) + .toPromise() + .then((post) => { + item.stats = post.stats; + item["alreadyDownvoted"] = true; + }); + } + } + trackByFn(index, item) { if (!!item) { return item.id; diff --git a/src/app/shared/upload/upload.component.html b/src/app/shared/upload/upload.component.html index ee7f5ca..b5ab041 100644 --- a/src/app/shared/upload/upload.component.html +++ b/src/app/shared/upload/upload.component.html @@ -27,7 +27,11 @@ --> - Submit diff --git a/src/app/shared/upload/upload.component.ts b/src/app/shared/upload/upload.component.ts index 71eb06e..7719d95 100644 --- a/src/app/shared/upload/upload.component.ts +++ b/src/app/shared/upload/upload.component.ts @@ -1,5 +1,6 @@ import { Component, OnInit } from "@angular/core"; import { DomSanitizer } from "@angular/platform-browser"; +import { Router } from "@angular/router"; import { PostApiService } from "./../../api/apis/posts.api"; import { CameraService } from "./../services/camera.service"; @@ -16,7 +17,8 @@ export class UploadComponent implements OnInit { constructor( private cameraService: CameraService, private sanitizer: DomSanitizer, - private postService: PostApiService + private postService: PostApiService, + private route: Router ) {} ngOnInit() {} @@ -41,9 +43,12 @@ export class UploadComponent implements OnInit { } upload() { - this.postService.upload({ - title: this.title, - path: this.uploadedImage, - }); + if (!!this.title && !!this.uploadedImage) { + const id = this.postService.upload({ + title: this.title, + path: this.uploadedImage, + }); + this.route.navigate(["posts", id]); + } } }