diff --git a/src/data/pocketbase.ts b/src/data/pocketbase.ts index 1bae413..acb07d9 100644 --- a/src/data/pocketbase.ts +++ b/src/data/pocketbase.ts @@ -26,7 +26,7 @@ class APIClient { this.client.autoCancellation(false) } - async getRecipes(page: number, perPage: number = 20, options: RecordListOptions) { + async getRecipesPaginated(page: number, perPage: number = 30, options: RecordListOptions) { return await this.client.collection(Collection.RECIPES).getList(page, perPage, options) } @@ -35,7 +35,7 @@ class APIClient { } async getRecipe(id: string) { - return await this.client.collection(Collection.RECIPES).getOne(id, { expand: 'ingredients,tags,steps', }) + return await this.client.collection(Collection.RECIPES).getOne(id, { expand: 'ingredients,tags,steps' }) } } diff --git a/src/data/schema.ts b/src/data/schema.ts index 88c76e5..efaab1c 100644 --- a/src/data/schema.ts +++ b/src/data/schema.ts @@ -24,7 +24,7 @@ export interface Tag extends BaseRecord { // not sure Image is the best type cos it might be quite heavy to get all the fields every time but // it is here in case it is (a good idea) export interface Image extends BaseRecord { - url: string + id: string } export interface Recipe extends BaseRecord { @@ -32,8 +32,16 @@ export interface Recipe extends BaseRecord { description?: string, servings?: number, images?: string[], // image IDs - steps: Step[], - tags?: Tag[] + ingredients: string[] + steps: string[], + tags?: string[] + + expand: { + images?: Image[], // image IDs, + ingredients: Ingredient[] + steps: Step[], + tags?: Tag[] + } } export const Collection = { diff --git a/src/pages/recipe/[recipeid].astro b/src/pages/recipe/[recipeid].astro index 892ccf2..d422845 100644 --- a/src/pages/recipe/[recipeid].astro +++ b/src/pages/recipe/[recipeid].astro @@ -9,26 +9,7 @@ import InfoView from "@/components/Detail/InfoView"; const { recipeid } = Astro.params; -const re2 = await client2.getRecipe(recipeid as string) -console.log(re2) - -const re = await client.collection("recipes").getOne(recipeid ?? "0"); - -const stepIds = re.steps - -let steps = await Promise.all( - stepIds.map(async s => - await client.collection("steps").getOne(s) - ) -) - -steps = steps.sort((a, b) => a.index - b.index); - -const ingredients = await Promise.all( - re.ingredients.map(async s => - await client.collection("ingredients").getOne(s) - ) -) +const re = await client2.getRecipe(recipeid as string) --- @@ -41,12 +22,12 @@ const ingredients = await Promise.all(

Ingredients

- +
- +