From dc0c1cf440a9d7e0b525b903e4b7c01269dd7691 Mon Sep 17 00:00:00 2001 From: Joachim Nielandt Date: Sun, 25 Mar 2018 20:36:43 +0200 Subject: [PATCH] Added sorting to the posts (order by date, descending) --- src/app/components/posts/posts.component.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/app/components/posts/posts.component.ts b/src/app/components/posts/posts.component.ts index 45c9258..5bbb5f2 100644 --- a/src/app/components/posts/posts.component.ts +++ b/src/app/components/posts/posts.component.ts @@ -54,7 +54,7 @@ export class PostsComponent implements OnInit, OnDestroy { console.log('PostsComponent ngOnInit() is done'); //we start listening to language changes - this.stateService.getLanguageObservable().subscribe(language=>{ + this.stateService.getLanguageObservable().subscribe(language => { console.log('posts component needs to switch languages!'); this.updateFilteredPosts(language); }); @@ -71,7 +71,7 @@ export class PostsComponent implements OnInit, OnDestroy { * @returns {Post[]} */ updateFilteredPosts(language: string) { - console.log('updating filtered posts for language '+language); + console.log('updating filtered posts for language ' + language); const res = new Array(); if (this.allPosts == null) { return res; @@ -89,6 +89,9 @@ export class PostsComponent implements OnInit, OnDestroy { // console.log('we should not display this'); } } + // sort the posts + res.sort((p1, p2) => p2.created_timestamp.getMilliseconds() - p1.created_timestamp.getMilliseconds()); + this.filteredPosts = res; }