memorium/routes/recipes/index.tsx

37 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-07-26 13:47:01 +02:00
import { Handlers, PageProps } from "$fresh/server.ts";
2023-07-27 15:28:50 +02:00
import { RecipeCard } from "@components/RecipeCard.tsx";
import { MainLayout } from "@components/layouts/main.tsx";
import { Recipe } from "@lib/recipes.ts";
2023-07-26 13:47:01 +02:00
import { getRecipes } from "../api/recipes/index.ts";
import IconArrowLeft from "https://deno.land/x/tabler_icons_tsx@0.0.3/tsx/arrow-left.tsx";
2023-07-30 23:55:51 +02:00
2023-07-26 13:47:01 +02:00
export const handler: Handlers<Recipe[] | null> = {
async GET(_, ctx) {
const recipes = await getRecipes();
return ctx.render(recipes);
},
};
export default function Greet(props: PageProps<Recipe[] | null>) {
return (
2023-07-30 21:43:09 +02:00
<MainLayout url={props.url}>
<header class="flex gap-4 items-center mb-5 md:hidden">
<a
class="px-4 ml-4 py-2 bg-gray-300 text-gray-800 rounded-lg flex items-center gap-1"
href="/"
>
<IconArrowLeft class="w-5 h-5" />
Back
</a>
2023-07-30 23:55:51 +02:00
<h3 class="text-2xl text-white font-light">🍽 Recipes</h3>
</header>
2023-07-30 21:43:09 +02:00
<div class="flex flex-wrap items-center gap-4 px-4">
2023-07-26 13:47:01 +02:00
{props.data?.map((doc) => {
return <RecipeCard recipe={doc} />;
})}
</div>
</MainLayout>
);
}