diff --git a/src/app/components/feed/feed.component.html b/src/app/components/feed/feed.component.html
index 4d2ac35..f8e49a9 100644
--- a/src/app/components/feed/feed.component.html
+++ b/src/app/components/feed/feed.component.html
@@ -49,7 +49,10 @@ infinite-scroll
\ No newline at end of file
diff --git a/src/app/components/feed/feed.component.ts b/src/app/components/feed/feed.component.ts
index 71d542c..d09566c 100644
--- a/src/app/components/feed/feed.component.ts
+++ b/src/app/components/feed/feed.component.ts
@@ -12,7 +12,8 @@ import { User } from 'src/app/models/user';
styleUrls: ['./feed.component.sass']
})
export class FeedComponent implements OnInit {
- loading = true;
+ loadingNew = true;
+ loadingMostLiked = true;
checked = false; // if the "I protected the environment."-box is checked
view = 'new';
@@ -48,6 +49,13 @@ export class FeedComponent implements OnInit {
}
this.parentSelectedPostList = response;
});
+ this.feedService.newPostsAvailable.subscribe(response => {
+ this.loadingNew = response;
+ });
+ this.feedService.topPostsAvailable.subscribe(response => {
+ console.log(response);
+ this.loadingMostLiked = response;
+ });
}
createPost(pElement, activityId: string) {
@@ -74,6 +82,7 @@ export class FeedComponent implements OnInit {
}
showMostLiked() {
+ this.view = 'mostLiked';
this.feedService.getPosts('TOP');
}
}
diff --git a/src/app/services/feed/feed.service.ts b/src/app/services/feed/feed.service.ts
index aa776de..45f8c85 100644
--- a/src/app/services/feed/feed.service.ts
+++ b/src/app/services/feed/feed.service.ts
@@ -12,6 +12,8 @@ import { User } from 'src/app/models/user';
})
export class FeedService {
+ public newPostsAvailable = new BehaviorSubject(true);
+ public topPostsAvailable = new BehaviorSubject(true);
public posts: BehaviorSubject = new BehaviorSubject(new Array());
public newPosts: BehaviorSubject = new BehaviorSubject(new Array());
public mostLikedPosts: BehaviorSubject = new BehaviorSubject(new Array());
@@ -153,7 +155,7 @@ export class FeedService {
}
public getNextPosts() {
- if (this.activePostList === 'NEW') {
+ if (this.activePostList === 'NEW' && this.newPostsAvailable) {
this.newOffset += 10;
const headers = new Headers();
headers.set('Content-Type', 'application/json');
@@ -161,10 +163,13 @@ export class FeedService {
.subscribe(response => {
let updatedposts = this.newPosts.getValue();
updatedposts = updatedposts.concat(this.renderAllPosts(response.json()));
+ if (this.renderAllPosts(response.json()).length < 1) {
+ this.newPostsAvailable.next(false);
+ }
this.newPosts.next(updatedposts);
this.setPost('NEW');
});
- } else if (this.activePostList === 'TOP') {
+ } else if (this.activePostList === 'TOP' && this.topPostsAvailable) {
this.mostLikedOffset += 10;
const headers = new Headers();
headers.set('Content-Type', 'application/json');
@@ -172,6 +177,9 @@ export class FeedService {
.subscribe(response => {
let updatedposts = this.mostLikedPosts.getValue();
updatedposts = updatedposts.concat(this.renderAllPosts(response.json()));
+ if (this.renderAllPosts(response.json()).length < 1) {
+ this.topPostsAvailable.next(false);
+ }
this.mostLikedPosts.next(updatedposts);
this.setPost('TOP');
});