Skip to content

Commit edb817e

Browse files
authored
fix(blog): hide in-depth category in polish version (#399)
1 parent b7d73f4 commit edb817e

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,52 @@
1+
import { computed, inject } from '@angular/core';
2+
import { toSignal } from '@angular/core/rxjs-interop';
3+
import { TranslocoService } from '@jsverse/transloco';
4+
import { distinctUntilChanged } from 'rxjs';
5+
16
export const CATEGORIES_LIST = [
27
{
38
name: 'All',
49
link: 'latest',
510
slug: null,
611
translationPath: 'categories.all',
12+
langs: ['pl', 'en'],
713
},
814
{
915
name: 'Guides',
1016
link: 'guides',
1117
slug: 'guides',
1218
translationPath: 'categories.guides',
19+
langs: ['pl', 'en'],
1320
},
1421
{
1522
name: 'News',
1623
link: 'news',
1724
slug: 'news',
1825
translationPath: 'categories.news',
26+
langs: ['pl', 'en'],
1927
},
2028
{
2129
name: 'In-Depth',
2230
link: 'angular-in-depth',
2331
slug: 'angular-in-depth',
2432
translationPath: 'categories.inDepth',
33+
langs: ['en'],
2534
},
2635
] as const;
2736

2837
export type CategoryListItem = (typeof CATEGORIES_LIST)[number];
38+
39+
export function injectCategories() {
40+
const transloco = inject(TranslocoService);
41+
const activeLang = toSignal(
42+
transloco.langChanges$.pipe(distinctUntilChanged()),
43+
{ initialValue: transloco.getActiveLang() },
44+
);
45+
46+
return computed(() => {
47+
const lang = activeLang();
48+
return CATEGORIES_LIST.filter((category) =>
49+
(category.langs as readonly string[]).includes(lang),
50+
);
51+
});
52+
}

libs/blog/articles/feature-latest-articles/src/lib/feature-latest-articles/feature-latest-articles.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<ng-container *transloco="let t; read: 'homePage'">
22
<section class="flex justify-center gap-3">
3-
@for (category of categories; track $index) {
3+
@for (category of categories(); track $index) {
44
<button
55
alPill
66
[variant]="category.name === selected().name ? 'flat' : 'outline'"

libs/blog/articles/feature-latest-articles/src/lib/feature-latest-articles/feature-latest-articles.component.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
Component,
55
computed,
66
inject,
7-
signal,
7+
linkedSignal,
88
} from '@angular/core';
99
import { RouterLink } from '@angular/router';
1010
import { TranslocoDirective } from '@jsverse/transloco';
@@ -24,7 +24,7 @@ import { PillDirective } from '@angular-love/blog/shared/ui-pill';
2424
import { ArticleCategory } from '@angular-love/contracts/articles';
2525
import { RepeatDirective } from '@angular-love/utils';
2626

27-
import { CATEGORIES_LIST, CategoryListItem } from './categories.const';
27+
import { CategoryListItem, injectCategories } from './categories.const';
2828

2929
@Component({
3030
selector: 'al-latest-articles',
@@ -50,11 +50,14 @@ import { CATEGORIES_LIST, CategoryListItem } from './categories.const';
5050
providers: [ArticleListStore],
5151
})
5252
export class FeatureLatestArticlesComponent {
53-
readonly selected = signal<CategoryListItem>(CATEGORIES_LIST[0]);
5453
readonly selectedCategorySlug = computed<ArticleCategory | null>(
5554
() => this.selected().slug,
5655
);
57-
readonly categories = CATEGORIES_LIST;
56+
readonly categories = injectCategories();
57+
readonly selected = linkedSignal<CategoryListItem>(
58+
() => this.categories()[0],
59+
);
60+
5861
readonly take = 8;
5962

6063
private readonly _articleListStore = inject(ArticleListStore);

0 commit comments

Comments
 (0)