memorium/routes/recipes/[name].tsx

55 lines
1.7 KiB
TypeScript
Raw Normal View History

2023-07-26 13:47:01 +02:00
import { Handlers, PageProps } from "$fresh/server.ts";
2023-07-30 19:40:39 +02:00
import { IngredientsList } from "@islands/IngredientsList.tsx";
2023-07-27 15:28:50 +02:00
import { RecipeHero } from "@components/RecipeHero.tsx";
import { MainLayout } from "@components/layouts/main.tsx";
2023-07-30 19:40:39 +02:00
import Counter from "@islands/Counter.tsx";
import { useSignal } from "@preact/signals";
2023-08-01 17:50:00 +02:00
import { getRecipe, Recipe } from "@lib/resource/recipes.ts";
2023-07-26 13:47:01 +02:00
export const handler: Handlers<Recipe | null> = {
async GET(_, ctx) {
const recipe = await getRecipe(ctx.params.name);
return ctx.render(recipe);
},
};
export default function Greet(props: PageProps<Recipe>) {
2023-07-30 19:40:39 +02:00
const recipe = props.data;
const portion = recipe.meta?.portion;
const amount = useSignal(portion || 1);
2023-08-04 23:36:35 +02:00
const subline = [
recipe?.meta?.time && `Duration ${recipe.meta.time}`,
].filter(Boolean);
2023-07-26 13:47:01 +02:00
return (
2023-08-04 22:38:09 +02:00
<MainLayout url={props.url} title={`Recipes > ${recipe.name}`}>
2023-08-04 23:36:35 +02:00
<RecipeHero
data={recipe}
backlink="/recipes"
editLink={`https://notes.max-richter.dev/Recipes/${recipe.id}`}
subline={subline}
/>
2023-07-26 15:48:03 +02:00
<div class="px-8 text-white mt-10">
2023-07-30 19:40:39 +02:00
<div class="flex items-center gap-8">
<h3 class="text-3xl my-5">Ingredients</h3>
{portion && <Counter count={amount} />}
</div>
<IngredientsList
ingredients={recipe.ingredients}
amount={amount}
portion={portion}
/>
2023-07-26 15:48:03 +02:00
<h3 class="text-3xl my-5">Preparation</h3>
2023-07-30 19:40:39 +02:00
<pre
class="whitespace-break-spaces"
dangerouslySetInnerHTML={{ __html: recipe.preparation || "" }}
>
{recipe.preparation}
</pre>
2023-07-26 13:47:01 +02:00
</div>
</MainLayout>
);
}