From c075b7dd679081bc2101c3bb9de2fc5982606545 Mon Sep 17 00:00:00 2001
From: Hugo SUBTIL <ext.sopra.husubtil@grandlyon.com>
Date: Mon, 7 Feb 2022 14:10:46 +0000
Subject: [PATCH] fix(news): issue on news display

---
 .gitlab-ci.yml                                | 10 +++++++++
 .../post-list/post-list.component.ts          | 22 ++++++++++++++-----
 2 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 83fc5a0b6..4fce8137e 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -3,6 +3,16 @@ stages:
   - build
   - deploy
 
+build_branch:
+  image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/docker:18.09
+  services:
+    - docker:18.09-dind
+  stage: build
+  script:
+    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
+    - docker build --pull -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" --build-arg conf=prod .
+    - docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG"
+
 build:
   image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/docker:18.09
   services:
diff --git a/src/app/post/components/post-list/post-list.component.ts b/src/app/post/components/post-list/post-list.component.ts
index 77a3b17da..e0e7f0e46 100644
--- a/src/app/post/components/post-list/post-list.component.ts
+++ b/src/app/post/components/post-list/post-list.component.ts
@@ -60,15 +60,24 @@ export class PostListComponent implements OnInit {
         this.getPosts(this.filters);
       } else {
         // Init default news list
+        this.allPosts = [];
         this.postService.getPosts(1).subscribe((news) => {
-          this.setNews(news);
-          const headLineTag = this.allPosts.find((post: Post) => post.tags.some((tag) => tag.slug === TagEnum.aLaUne));
-          this.allPosts.unshift(headLineTag);
+          this.fillArticles(news);
         });
       }
     });
   }
 
+  public fillArticles(news: PostWithMeta): void {
+    this.setNews(news);
+    const headLineTag = this.allPosts.filter((post: Post) => post.tags.some((tag) => tag.slug === TagEnum.aLaUne));
+
+    const headIndex = this.allPosts.findIndex((post) => post.id === headLineTag[0].id);
+    this.allPosts.splice(headIndex, 1);
+
+    this.allPosts = [...headLineTag, ...this.allPosts];
+  }
+
   public getPosts(filters?: Tag[]): void {
     // Parse filter
     let parsedFilters = null;
@@ -87,7 +96,7 @@ export class PostListComponent implements OnInit {
 
     this.isLoading = true;
     this.postService.getPosts(1, parsedFilters).subscribe((news) => {
-      this.setNews(news);
+      this.fillArticles(news);
     });
   }
 
@@ -121,7 +130,7 @@ export class PostListComponent implements OnInit {
     if (this.pagination && this.pagination.page < this.pagination.pages) {
       this.isLoading = true;
       this.postService.getPosts(this.pagination.next).subscribe((news) => {
-        this.setNews(news);
+        this.fillArticles(news);
       });
     }
   }
@@ -130,11 +139,12 @@ export class PostListComponent implements OnInit {
   private setNews(news: PostWithMeta): void {
     this.pagination = news.meta.pagination;
     const customIndex = this.allPosts.length; // For scroll loading, start with previous index.
-    this.allPosts = news.posts.map((val, index) => {
+    const newPosts = news.posts.map((val, index) => {
       val = this.addAuthorToPost(val);
       index += customIndex;
       return val;
     });
+    this.allPosts = [...this.allPosts, ...newPosts];
     this.isLoading = false;
   }
 
-- 
GitLab