Hello World! :D
March 7, 2022 • 32 views
Updated at March 23, 2024
Lorem ipsum
Dolor sit amet
Vivamus lacinia
import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';
import { first, map, Observable, of } from 'rxjs';
import { BlogPost, BlogPostUserData } from '../../blog.datatypes';
import { BlogService } from '../../services/blog.service';
@Component({
selector: 'app-blog-sidebar',
templateUrl: './blog-sidebar.component.html',
styleUrls: ['./blog-sidebar.component.css']
})
export class BlogSidebarComponent implements OnChanges {
@Input() blogPost!: BlogPost;
@Input() userData!: BlogPostUserData;
recommendedBlogPosts$: Observable<BlogPost[]> = of([]);
constructor(private blogService: BlogService) { }
ngOnChanges(changes: SimpleChanges): void {
if (!this.blogPost) {
return;
}
this.loadRecommendedPosts();
}
loadRecommendedPosts(): void {
this.recommendedBlogPosts$ = this.blogService
.getPage(3, 'created_at', this.blogPost?.keywords?.[0] ?? null)
.pipe(
map(resp => resp.filter(x => x.id !== this.blogPost.id)));
}
}