diff --git a/src/app/app.component.html b/src/app/app.component.html index aa331e09ed89df3e4e5049eaa2a392e6d8d06e35..5ed476324c6bde79bdb697cd0cbdc3559c9416b3 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1,6 +1,6 @@ <div class="app-container"> <app-header></app-header> - <div (scroll)="onScrollDown($event)" class="app-body"> + <div class="app-body"> <router-outlet></router-outlet> <router-outlet name="print"></router-outlet> <app-footer></app-footer> diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 86273beab844acdfb875abef1bb5d8f8e198f206..18b020c871714621fe5a113e798f8d958c594bd1 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -5,7 +5,6 @@ import { AuthService } from './services/auth.service'; import { RouterListenerService } from './services/routerListener.service'; import { UpdateService } from './services/update.service'; import { PrintService } from './shared/service/print.service'; -import { WindowScrollService } from './shared/service/windowScroll.service'; @Component({ selector: 'app-root', @@ -19,7 +18,6 @@ export class AppComponent implements OnInit { public printService: PrintService, private authService: AuthService, private profilService: ProfileService, - private windowScrollService: WindowScrollService, private routerListener: RouterListenerService, private updateService: UpdateService, private router: Router @@ -52,7 +50,4 @@ export class AppComponent implements OnInit { const vh = window.innerHeight * 0.01; document.documentElement.style.setProperty('--vh', `${vh}px`); } - public onScrollDown(event): void { - this.windowScrollService.scrollY.next(event); - } } 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 38cad37daf6d207eb936368d670172180e72a887..41a5304991057e8762d1ad7fcf9eb4bfb1eaa7ec 100644 --- a/src/app/post/components/post-list/post-list.component.ts +++ b/src/app/post/components/post-list/post-list.component.ts @@ -1,5 +1,4 @@ import { Component, OnInit } from '@angular/core'; -import { WindowScrollService } from '../../../shared/service/windowScroll.service'; import { TagEnum } from '../../enum/tag.enum'; import { Pagination } from '../../models/pagination.model'; import { Post } from '../../models/post.model'; @@ -24,21 +23,9 @@ export class PostListComponent implements OnInit { public pagination: Pagination; public isLoading = false; public isPublishMode = false; + public lastPage: boolean; - constructor( - private postService: PostService, - private windowScrollService: WindowScrollService, - private route: ActivatedRoute, - private router: Router - ) { - this.windowScrollService.scrollY$.subscribe((evt: any) => { - if (evt && evt.target.offsetHeight + evt.target.scrollTop >= evt.target.scrollHeight - 200) { - if (!this.isLoading) { - this.loadMore(); - } - } - }); - } + constructor(private postService: PostService, private route: ActivatedRoute, private router: Router) {} ngOnInit(): void { this.isLoading = true; @@ -74,6 +61,7 @@ export class PostListComponent implements OnInit { */ public fillArticles(news: PostWithMeta): void { this.setNews(news); + news.meta.pagination.pages > news.meta.pagination.page ? (this.lastPage = false) : (this.lastPage = true); const headLineTag = this.allPosts.filter((post: Post) => post.tags.some((tag) => tag && tag.slug === TagEnum.aLaUne) ); @@ -132,7 +120,7 @@ export class PostListComponent implements OnInit { } // Load more news on scroll event. - private loadMore(): void { + public loadMore(): void { if (this.pagination && this.pagination.page < this.pagination.pages) { this.isLoading = true; this.postService.getPosts(this.pagination.next).subscribe((news) => { diff --git a/src/app/post/services/post.service.ts b/src/app/post/services/post.service.ts index 89020397d8274a59afb75c72d212dd211ba20f0d..ffc0dec46a8fccd3c1b12a3492b43653f37e9297 100644 --- a/src/app/post/services/post.service.ts +++ b/src/app/post/services/post.service.ts @@ -22,10 +22,14 @@ export class PostService { ); } - public getPosts(page: number, tags?: string[]): Observable<PostWithMeta> { + public getPosts(page: number, tags?: string[], limit?: string): Observable<PostWithMeta> { + if (!limit) { + // 16 posts to fit new design (1 + 3 + 2 + 1 + 3 + 2 + 1 + 3) + limit = '16'; + } if (!tags) { return this.http - .get<PostWithMeta>(`${this.baseUrl}?page=${page}&include=tags,authors`) + .get<PostWithMeta>(`${this.baseUrl}?page=${page}&include=tags,authors&limit=${limit}`) .pipe(map((item: PostWithMeta) => new PostWithMeta(item))); } let tagsString = ''; @@ -37,7 +41,9 @@ export class PostService { } }); return this.http - .get<PostWithMeta>(`${this.baseUrl}?include=tags,authors&filter=tags:${encodeURIComponent(tagsString)}`) + .get<PostWithMeta>( + `${this.baseUrl}?include=tags,authors&filter=tags:${encodeURIComponent(tagsString)}&limit=${limit}` + ) .pipe(map((item: PostWithMeta) => new PostWithMeta(item))); } diff --git a/src/app/shared/service/windowScroll.service.ts b/src/app/shared/service/windowScroll.service.ts deleted file mode 100644 index ebdf325b8451d76da2c2750878956c9ad5d15b2d..0000000000000000000000000000000000000000 --- a/src/app/shared/service/windowScroll.service.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { Injectable } from '@angular/core'; -import { BehaviorSubject } from 'rxjs'; - -@Injectable({ - providedIn: 'root', -}) -export class WindowScrollService { - scrollY = new BehaviorSubject(null); - scrollY$ = this.scrollY.asObservable(); - - constructor() {} - - public updateScrollY(value: Event): void { - this.scrollY.next(value); - } -}