Skip to content

Commit

Permalink
news: fix order
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelCoding committed Aug 10, 2024
1 parent 9d91858 commit 5b51e6d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/app/pages/blog/blog-list/blog-list.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h1 i18n>News &amp; Events</h1>
</div>

<ul class="not news">
<li *ngFor="let entry of entries | async">
<li *ngFor="let entry of entries | async; trackBy trackBy">
<app-blog-card *ngIf="!isEvent(entry)" [post]="castPost(entry)" />
<app-event-card *ngIf="isEvent(entry)" [event]="castEvent(entry)" />
</li>
Expand Down
15 changes: 10 additions & 5 deletions src/app/pages/blog/blog-list/blog-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ export class BlogListComponent {
events: this.blogService.getEventPosts(),
posts: this.selectedKeywords.pipe(switchMap(keywords => this.blogService.getBlogPosts(keywords)))
})
.pipe(map(({ events, posts }) =>
([...events, ...posts].sort(eventOrPost => {
.pipe(map(({ events, posts }) => ([...events, ...posts].sort((a, b) => {
// @ts-expect-error union type
return Date.parse(eventOrPost.published ?? eventOrPost.start_time);
}))
));
const aDate = Date.parse(a.published ?? a.start_time);
// @ts-expect-error union type
const bDate = Date.parse(b.published ?? b.start_time);
return bDate - aDate;
}))));
protected readonly keywords = this.blogService.getBlogKeywords();

constructor(
Expand Down Expand Up @@ -72,4 +73,8 @@ export class BlogListComponent {
protected castPost(eventOrPost: SmallEvent | SmallBlogPost): SmallBlogPost {
return eventOrPost as SmallBlogPost;
}

protected trackBy(_idx: number, post: SmallEvent | SmallBlogPost): string {
return post.slug;
}
}

0 comments on commit 5b51e6d

Please sign in to comment.