Automatic feed refresh after vote or post

master
lampe_n1 5 years ago
parent 9d22c717de
commit 1aa5832a25

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

@ -37,17 +37,27 @@ export class FeedComponent implements OnInit {
}
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.viewMostLiked = false
this.parentSelectedPostList = this.feedNew
}
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.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 { 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 {
@Input() childPostList: Array<Post>
@Output() voteEvent = new EventEmitter<boolean>()
selectedPost: Post
constructor(private feedService: FeedService) { }
@ -19,18 +20,12 @@ export class PostlistComponent implements OnInit {
voteUp(pPost: Post){
this.feedService.upvote(pPost.id)
this.refresh()
this.voteEvent.emit(true)
}
voteDown(pPost: Post){
this.feedService.downvote(pPost.id)
this.refresh()
}
refresh() {
this.feedService.getAllPostsRaw().subscribe(response => {
this.childPostList = this.feedService.renderAllPosts(response.json())
})
this.voteEvent.emit(true)
}
}

Loading…
Cancel
Save