[PIE-28] Switch to type-safe API #12

Merged
breadone merged 9 commits from PIE-28-2 into main 2025-08-16 13:17:10 +12:00
4 changed files with 6 additions and 14 deletions
Showing only changes of commit ba237d645e - Show all commits

View File

@ -4,8 +4,7 @@ import TagRow from "./TagRow.astro"
const { recipe } = Astro.props; const { recipe } = Astro.props;
const headerImage = await client.collection("images").getOne(recipe.images[0]) const image = (await client.getRecipeImages(recipe.id))[0]
const image = await client.files.getRelativeURL(headerImage, headerImage.image)
--- ---
<div class="relative z-0 flex h-50"> <div class="relative z-0 flex h-50">
@ -19,7 +18,7 @@ const image = await client.files.getRelativeURL(headerImage, headerImage.image)
<!-- <p id="recipe-desc" class="text-white text-[10pt]"> {recipe.description} </p> --> <!-- <p id="recipe-desc" class="text-white text-[10pt]"> {recipe.description} </p> -->
<div id="tag-row" class=""> <div id="tag-row" class="">
<TagRow tagIds={recipe.tags}/> <TagRow tags={recipe.expand.tags}/>
</div> </div>
</div> </div>

View File

@ -1,17 +1,10 @@
--- ---
import client from "../../data/pocketbase"
interface Props {
tags: string[]
}
const { tags } = Astro.props const { tags } = Astro.props
--- ---
<div class=""> <div class="">
{ {
tags.map(tag => ( (tags ?? []).map(tag => (
<a <a
href={`/tag/${tag.id}`} href={`/tag/${tag.id}`}
class="text-white bg-white/20 px-2 mr-2 mt-2 rounded-md inline-block hover:bg-white/30" class="text-white bg-white/20 px-2 mr-2 mt-2 rounded-md inline-block hover:bg-white/30"

View File

@ -31,7 +31,7 @@ class APIClient {
} }
async getAllRecipes() { async getAllRecipes() {
return await this.client.collection<Recipe>(Collection.RECIPES).getFullList({ expand: "steps,ingredients,tags" }) return await this.client.collection<Recipe>(Collection.RECIPES).getFullList({ expand: 'ingredients,tags,steps,images,steps.ingredients' })
} }
async getRecipe(id: string) { async getRecipe(id: string) {

View File

@ -3,7 +3,7 @@ import PageLayout from "@/layouts/base"
import client from "@/data/pocketbase" import client from "@/data/pocketbase"
import OverviewCard from "@/components/Card/OverviewCard" import OverviewCard from "@/components/Card/OverviewCard"
const recipies = await client.collection("recipes").getFullList() const recipes = await client.getAllRecipes()
--- ---
<PageLayout> <PageLayout>
@ -11,7 +11,7 @@ const recipies = await client.collection("recipes").getFullList()
<div class="grid md:gap-2 gap-3 grid-cols-2 md:grid-cols-2 lg:grid-cols-4 xl:grid-cols-8"> <div class="grid md:gap-2 gap-3 grid-cols-2 md:grid-cols-2 lg:grid-cols-4 xl:grid-cols-8">
{ {
recipies.map(r => ( recipes.map(r => (
<OverviewCard recipe={r} /> <OverviewCard recipe={r} />
)) ))
} }