Use input signal for recipe-card.
This commit is contained in:
parent
80752f7513
commit
855acfddb9
@ -1,3 +1,4 @@
|
|||||||
|
@let recipe = this.recipe();
|
||||||
<article>
|
<article>
|
||||||
<a [routerLink]="recipePageLink()">
|
<a [routerLink]="recipePageLink()">
|
||||||
@if (mainImage.isSuccess()) {
|
@if (mainImage.isSuccess()) {
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { Component, computed, inject, Input } from '@angular/core';
|
import { Component, computed, inject, input } from '@angular/core';
|
||||||
import { Recipe } from '../../model/Recipe.model';
|
import { Recipe } from '../../model/Recipe.model';
|
||||||
import { RouterLink } from '@angular/router';
|
import { RouterLink } from '@angular/router';
|
||||||
import { injectQuery } from '@tanstack/angular-query-experimental';
|
import { injectQuery } from '@tanstack/angular-query-experimental';
|
||||||
@ -13,14 +13,12 @@ import { FaIconComponent } from '@fortawesome/angular-fontawesome';
|
|||||||
styleUrl: './recipe-card.css',
|
styleUrl: './recipe-card.css',
|
||||||
})
|
})
|
||||||
export class RecipeCard {
|
export class RecipeCard {
|
||||||
@Input({ required: true })
|
public recipe = input.required<Recipe>();
|
||||||
public recipe!: Recipe;
|
|
||||||
|
|
||||||
protected readonly recipePageLink = computed(() => [
|
protected readonly recipePageLink = computed(() => {
|
||||||
'/recipes',
|
const recipe = this.recipe();
|
||||||
this.recipe.owner.username,
|
return ['/recipes', recipe.owner.username, recipe.slug];
|
||||||
this.recipe.slug,
|
});
|
||||||
]);
|
|
||||||
|
|
||||||
protected readonly faGlobe = faGlobe;
|
protected readonly faGlobe = faGlobe;
|
||||||
protected readonly faLock = faLock;
|
protected readonly faLock = faLock;
|
||||||
@ -29,8 +27,11 @@ export class RecipeCard {
|
|||||||
|
|
||||||
private readonly imageService = inject(ImageService);
|
private readonly imageService = inject(ImageService);
|
||||||
|
|
||||||
protected mainImage = injectQuery(() => ({
|
protected readonly mainImage = injectQuery(() => {
|
||||||
queryKey: ['images', this.recipe.mainImage.owner.username, this.recipe.mainImage.filename],
|
const recipe = this.recipe();
|
||||||
queryFn: () => this.imageService.getImage(this.recipe.mainImage.url),
|
return {
|
||||||
}));
|
queryKey: ['images', recipe.mainImage.owner.username, recipe.mainImage.filename],
|
||||||
|
queryFn: () => this.imageService.getImage(recipe.mainImage.url),
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user