+
+
+
+
+
+
{{post.author.name}}
@@ -47,4 +57,5 @@
{{post.downvotes}}
-
\ No newline at end of file
+
+
diff --git a/src/app/components/feed/postlist/postlist.component.sass b/src/app/components/feed/postlist/postlist.component.sass
index 650a8bc..e9b0e0b 100644
--- a/src/app/components/feed/postlist/postlist.component.sass
+++ b/src/app/components/feed/postlist/postlist.component.sass
@@ -13,5 +13,7 @@
display: contents
a:hover
cursor: pointer
-
+ #button-box
+ text-align: right
+ margin-left: auto
diff --git a/src/app/components/feed/postlist/postlist.component.ts b/src/app/components/feed/postlist/postlist.component.ts
index 8d5acfd..c5e4f52 100644
--- a/src/app/components/feed/postlist/postlist.component.ts
+++ b/src/app/components/feed/postlist/postlist.component.ts
@@ -29,6 +29,17 @@ export class PostlistComponent implements OnInit {
this.voteEvent.emit(true); });
}
+ deletePost(pPost: Post) {
+ this.feedService.deletePost(pPost.id).subscribe(response => {
+ for (let i = 0; i < this.childPostList.length; i++) {
+ if (this.childPostList[i].id === pPost.id) {
+ this.childPostList.splice(i, 1);
+ return;
+ }
+ }
+ });
+ }
+
public showUserProfile(post: any) {
this.router.navigate(['profile/' + post.author.id]);
}
diff --git a/src/app/models/post.ts b/src/app/models/post.ts
index 583935c..b0d6818 100644
--- a/src/app/models/post.ts
+++ b/src/app/models/post.ts
@@ -8,6 +8,7 @@ export class Post {
upvotes: number;
downvotes: number;
userVote: string;
+ deletable: boolean;
author: Author;
// TODO: constructor properties need normal names
@@ -18,6 +19,7 @@ export class Post {
pUpvotes: number,
pDownvotes: number,
pUserVote: string,
+ pDeletable: boolean,
pDate: string,
pAuthor: Author
) {
@@ -27,6 +29,7 @@ export class Post {
this.upvotes = pUpvotes;
this.downvotes = pDownvotes;
this.userVote = pUserVote;
+ this.deletable = pDeletable;
this.date = pDate;
this.author = pAuthor;
}
diff --git a/src/app/services/feed/feed.service.ts b/src/app/services/feed/feed.service.ts
index 3cd3adb..c558f0a 100644
--- a/src/app/services/feed/feed.service.ts
+++ b/src/app/services/feed/feed.service.ts
@@ -28,28 +28,29 @@ export class FeedService {
console.log(response.text()); });
}
- public createPost2(pContent: String) {
+ public upvote(pPostID: number): any {
const url = environment.graphQLUrl;
const headers = new Headers();
headers.set('Content-Type', 'application/json');
- const body = {query: `query{
- getSelf {name}
- }`};
+ const body = {query: `mutation($postId: ID!) {
+ vote(postId: $postId, type: UPVOTE)
+ }`, variables: {
+ postId: pPostID
+ }};
- this.http.post(url, body).subscribe(response => {
- console.log(response.text()); });
+ return this.http.post(url, body);
}
- public upvote(pPostID: number): any {
+ public downvote(pPostID: number): any {
const url = environment.graphQLUrl;
const headers = new Headers();
headers.set('Content-Type', 'application/json');
const body = {query: `mutation($postId: ID!) {
- vote(postId: $postId, type: UPVOTE)
+ vote(postId: $postId, type: DOWNVOTE)
}`, variables: {
postId: pPostID
}};
@@ -57,19 +58,17 @@ export class FeedService {
return this.http.post(url, body);
}
- public downvote(pPostID: number): any {
- const url = environment.graphQLUrl;
-
+ public deletePost(pPostID: number): any {
const headers = new Headers();
headers.set('Content-Type', 'application/json');
const body = {query: `mutation($postId: ID!) {
- vote(postId: $postId, type: DOWNVOTE)
+ deletePost(postId: $postId)
}`, variables: {
postId: pPostID
}};
- return this.http.post(url, body);
+ return this.http.post(environment.graphQLUrl, body);
}
public getAllPosts(): Array