Automatic feed refresh after vote or post

master
lampe_n1 5 years ago
parent 9d22c717de
commit 1aa5832a25

@ -10,10 +10,10 @@
</div> </div>
<div id="feedlist"> <div id="feedlist">
<div *ngIf = "viewNew"> <div *ngIf = "viewNew">
<feed-postlist [childPostList]="parentSelectedPostList"></feed-postlist> <feed-postlist (voteEvent)="refresh($event)" [childPostList]="parentSelectedPostList"></feed-postlist>
</div> </div>
<div *ngIf = "viewMostLiked"> <div *ngIf = "viewMostLiked">
<feed-postlist [childPostList]="parentSelectedPostList"></feed-postlist> <feed-postlist (voteEvent)="refresh($event)" [childPostList]="parentSelectedPostList"></feed-postlist>
</div> </div>
<!-- <!--
<div class="feeditem"> <div class="feeditem">

@ -37,17 +37,27 @@ export class FeedComponent implements OnInit {
} }
showNew() { showNew() {
this.feedNew = this.feedService.getAllPosts() this.feedService.getAllPostsRaw().subscribe(response => {
this.feedNew = this.feedService.renderAllPosts(response.json())
this.parentSelectedPostList = this.feedNew})
this.viewNew = true this.viewNew = true
this.viewMostLiked = false this.viewMostLiked = false
this.parentSelectedPostList = this.feedNew
} }
showMostLiked() { showMostLiked() {
this.feedMostLiked = this.feedService.getAllPosts() this.feedService.getAllPostsRaw().subscribe(response => {
this.feedMostLiked = this.feedService.renderAllPosts(response.json())
this.parentSelectedPostList = this.feedMostLiked})
this.viewNew = false this.viewNew = false
this.viewMostLiked = true this.viewMostLiked = true
this.parentSelectedPostList = this.feedMostLiked }
refresh($event) {
this.feedService.getAllPostsRaw().subscribe(response => {
this.parentSelectedPostList = this.feedService.renderAllPosts(response.json())
console.log("Refresh")
})
} }
} }

@ -1,4 +1,4 @@
import { Component, OnInit, Input } from '@angular/core'; import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { Post } from 'src/app/models/post'; import { Post } from 'src/app/models/post';
import { FeedService } from 'src/app/services/feed/feed.service'; import { FeedService } from 'src/app/services/feed/feed.service';
@ -10,6 +10,7 @@ import { FeedService } from 'src/app/services/feed/feed.service';
export class PostlistComponent implements OnInit { export class PostlistComponent implements OnInit {
@Input() childPostList: Array<Post> @Input() childPostList: Array<Post>
@Output() voteEvent = new EventEmitter<boolean>()
selectedPost: Post selectedPost: Post
constructor(private feedService: FeedService) { } constructor(private feedService: FeedService) { }
@ -19,18 +20,12 @@ export class PostlistComponent implements OnInit {
voteUp(pPost: Post){ voteUp(pPost: Post){
this.feedService.upvote(pPost.id) this.feedService.upvote(pPost.id)
this.refresh() this.voteEvent.emit(true)
} }
voteDown(pPost: Post){ voteDown(pPost: Post){
this.feedService.downvote(pPost.id) this.feedService.downvote(pPost.id)
this.refresh() this.voteEvent.emit(true)
}
refresh() {
this.feedService.getAllPostsRaw().subscribe(response => {
this.childPostList = this.feedService.renderAllPosts(response.json())
})
} }
} }

Loading…
Cancel
Save