From 12a02ef1f8540f45526b9ea9392a90ae894726a6 Mon Sep 17 00:00:00 2001 From: June Date: Tue, 19 Aug 2025 18:49:04 +1200 Subject: [PATCH 01/10] small design changes on /recipe/new --- src/pages/recipe/new.astro | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/pages/recipe/new.astro b/src/pages/recipe/new.astro index cf61601..ba5de1d 100644 --- a/src/pages/recipe/new.astro +++ b/src/pages/recipe/new.astro @@ -14,6 +14,17 @@ async function submitRecipe() {
+ +
+

New Recipe

+ +
+
-

Ingredients

+

Ingredients

@@ -104,7 +115,7 @@ async function submitRecipe() {
-
+
-- 2.47.2 From b3d36afdc7a460a50e41342bec03a6e19db92748 Mon Sep 17 00:00:00 2001 From: June Date: Tue, 19 Aug 2025 18:49:17 +1200 Subject: [PATCH 02/10] Add universal bottom padding --- src/layouts/base.astro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layouts/base.astro b/src/layouts/base.astro index f738f0a..c31b2d3 100644 --- a/src/layouts/base.astro +++ b/src/layouts/base.astro @@ -10,7 +10,7 @@ import Header from "@/components/Header";
-
+
-- 2.47.2 From 6d708d8fd461abe50f9db17a59f051be9cbbf26f Mon Sep 17 00:00:00 2001 From: June Date: Tue, 19 Aug 2025 18:54:30 +1200 Subject: [PATCH 03/10] padding changes --- src/pages/recipe/new.astro | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/recipe/new.astro b/src/pages/recipe/new.astro index ba5de1d..affa757 100644 --- a/src/pages/recipe/new.astro +++ b/src/pages/recipe/new.astro @@ -13,7 +13,7 @@ async function submitRecipe() {
-
+

New Recipe

@@ -115,7 +115,7 @@ async function submitRecipe() {
-
+
-- 2.47.2 From 7b98506ad5f6d13267e5882d6b5d684df6a5c97b Mon Sep 17 00:00:00 2001 From: June Date: Wed, 20 Aug 2025 10:49:42 +1200 Subject: [PATCH 04/10] var rename --- src/data/pocketbase.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/data/pocketbase.ts b/src/data/pocketbase.ts index 8684c0a..7e68b9d 100644 --- a/src/data/pocketbase.ts +++ b/src/data/pocketbase.ts @@ -8,29 +8,29 @@ import { } from './schema' class APIClient { - client: Pocketbase + pb: Pocketbase constructor() { - this.client = new Pocketbase("http://localhost:4321") - this.client.autoCancellation(false) + this.pb = new Pocketbase("http://localhost:4321") + this.pb.autoCancellation(false) } async getRecipesPage(page: number, perPage: number = 30, options: RecordListOptions) { - return await this.client.collection(Collection.RECIPES).getList(page, perPage, options) + return await this.pb.collection(Collection.RECIPES).getList(page, perPage, options) } async getAllRecipes() { - return await this.client.collection(Collection.RECIPES).getFullList({ expand: 'ingredients,tags,steps,images,steps.ingredients' }) + return await this.pb.collection(Collection.RECIPES).getFullList({ expand: 'ingredients,tags,steps,images,steps.ingredients' }) } async getRecipe(id: string) { - return await this.client.collection(Collection.RECIPES).getOne(id, { expand: 'ingredients,tags,steps,images,steps.ingredients' }) + return await this.pb.collection(Collection.RECIPES).getOne(id, { expand: 'ingredients,tags,steps,images,steps.ingredients' }) } // IMAGE async getImageURL(imgID: string, relative: boolean = true) { - const record = await this.client.collection(Collection.IMAGES).getOne(imgID) - const res = this.client.files.getURL(record, record.image) + const record = await this.pb.collection(Collection.IMAGES).getOne(imgID) + const res = this.pb.files.getURL(record, record.image) return relative ? res.substring(21) : res } @@ -45,11 +45,11 @@ class APIClient { } async getAllTags() { - return await this.client.collection(Collection.TAGS).getFullList() + return await this.pb.collection(Collection.TAGS).getFullList() } async getTag(name: string) { - return await this.client.collection(Collection.TAGS).getList(1, 50, { filter: `name = '${name}'` }) + return await this.pb.collection(Collection.TAGS).getList(1, 50, { filter: `name = '${name}'` }) } async getRecipesOfTag(tagName: string) { @@ -60,7 +60,7 @@ class APIClient { } const tag = tagResult.items[0] - return await this.client.collection(Collection.RECIPES).getFullList({ + return await this.pb.collection(Collection.RECIPES).getFullList({ filter: `tags ~ '${tag.id}'`, expand: 'ingredients,tags,steps,images,steps.ingredients' }) -- 2.47.2 From cd77cfdf66a2fb587fdcdb3dabd02a0fabe1921e Mon Sep 17 00:00:00 2001 From: June Date: Wed, 20 Aug 2025 17:48:26 +1200 Subject: [PATCH 05/10] i really hate cors --- astro.config.mjs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/astro.config.mjs b/astro.config.mjs index 58360f6..47cc0d6 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -7,8 +7,6 @@ import tailwindcss from '@tailwindcss/vite'; import { loadEnv } from "vite"; -const { PUBLIC_PB_URL } = loadEnv(process.env.NODE_ENV, process.cwd(), ""); - // https://astro.build/config export default defineConfig({ output: 'server', @@ -19,5 +17,8 @@ export default defineConfig({ vite: { plugins: [tailwindcss()], + server: { + cors: false + } } }); \ No newline at end of file -- 2.47.2 From 7c1cee2f3a44f500a4445332dfcfac873be4ed42 Mon Sep 17 00:00:00 2001 From: June Date: Wed, 20 Aug 2025 17:48:38 +1200 Subject: [PATCH 06/10] use minutes for time instead of seconds --- src/components/Detail/InfoView.astro | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/components/Detail/InfoView.astro b/src/components/Detail/InfoView.astro index 4bde49e..5da41b8 100644 --- a/src/components/Detail/InfoView.astro +++ b/src/components/Detail/InfoView.astro @@ -15,8 +15,19 @@ function formatTime(seconds) { return result; } -const workTime = formatTime(re.worktime) -const waitTime = formatTime(re.waittime) +function formatTimeMin(minutes) { + if (minutes === 0) return null + const h = Math.floor(minutes / 60); + const m = minutes % 60; + let result = ""; + if (h > 0) result += `${h}h`; + if (m > 0) result += `${m}m`; + if (result === "") result = "0m"; + return result; +} + +const workTime = formatTimeMin(re.worktime) +const waitTime = formatTimeMin(re.waittime) ---

{re.description}

-- 2.47.2 From 38560f744d1bd719fab638f96ed8e59594a52ec2 Mon Sep 17 00:00:00 2001 From: June Date: Wed, 20 Aug 2025 17:49:01 +1200 Subject: [PATCH 07/10] proxy fwd all request attrs --- src/pages/api/[...proxy].ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pages/api/[...proxy].ts b/src/pages/api/[...proxy].ts index 9574877..63b1d1a 100644 --- a/src/pages/api/[...proxy].ts +++ b/src/pages/api/[...proxy].ts @@ -11,5 +11,9 @@ const getProxyUrl = (request: Request) => { export const ALL: APIRoute = async ({ request }) => { const proxyUrl = getProxyUrl(request); const response = await fetch(proxyUrl.href, request); - return new Response(response.body); + return new Response(response.body, { + status: response.status, + statusText: response.statusText, + headers: response.headers + }); }; \ No newline at end of file -- 2.47.2 From 600c7b6d25130ee5036a5f9ac24aae9498d2474f Mon Sep 17 00:00:00 2001 From: June Date: Wed, 20 Aug 2025 17:49:13 +1200 Subject: [PATCH 08/10] button colour --- src/pages/recipe/new.astro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/recipe/new.astro b/src/pages/recipe/new.astro index affa757..9e2f890 100644 --- a/src/pages/recipe/new.astro +++ b/src/pages/recipe/new.astro @@ -19,7 +19,7 @@ async function submitRecipe() {

New Recipe

-- 2.47.2 From bfe9f12802a7511a26cfe6614e052cdbe4666208 Mon Sep 17 00:00:00 2001 From: June Date: Wed, 20 Aug 2025 17:49:35 +1200 Subject: [PATCH 09/10] this is getting messy time for a rethink --- src/script/newRecipe.ts | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/src/script/newRecipe.ts b/src/script/newRecipe.ts index ae08d43..0016b72 100644 --- a/src/script/newRecipe.ts +++ b/src/script/newRecipe.ts @@ -1,3 +1,5 @@ +import client from "@/data/pocketbase" + let ingredientFields: HTMLInputElement[] = [] let ingredientTable: HTMLTableSectionElement = document.querySelector('#ingredient-table')! let ingredientAddButton: HTMLButtonElement = document.querySelector('#add-ingredient-btn')! @@ -8,13 +10,26 @@ let stepList: HTMLUListElement = document.querySelector('#step-list')! let currentStepIndex = 0 // - VARS -let ingredients: {qty: string, unit: string, name: string}[] = [] +let ingredients: {quantity: string, unit: string, name: string}[] = [] let steps: { index: number, instruction: string, ingredients: string[], // IDs of ingredient fields }[] = [] +const formFields = () => { + return { + name: (document.querySelector("#rec-name") as HTMLTextAreaElement).value ?? "", + description: (document.querySelector("#rec-desc") as HTMLTextAreaElement).value ?? "", + servings: (document.querySelector("#rec-servings") as HTMLInputElement).value ?? "", + worktime: (document.querySelector("#rec-worktime") as HTMLInputElement).value ?? "", + waittime: (document.querySelector("#rec-waittime") as HTMLInputElement).value ?? "", + rating: (document.querySelector("#rec-rating") as HTMLInputElement).value ?? "", + ings: ingredients, + stepList: steps + } +} + // - INIT document.addEventListener('DOMContentLoaded', function() { @@ -25,6 +40,7 @@ document.addEventListener('DOMContentLoaded', function() { ) stepInput.addEventListener('input', showAddStepButton) + document.querySelector('#btn-save')?.addEventListener('click', addRecipe) // show plus button once the user types in the text fields ingredientFields.forEach(f => { @@ -60,9 +76,27 @@ document.addEventListener('DOMContentLoaded', function() { }); // - ADD +async function addRecipe() { + const comps = formFields() + console.log(comps.ings) + + const ingredientIDs = await Promise.all( + comps.ings.map(async it => (await client.pb.collection('ingredients').create({ + 'quantity': it.quantity, + 'name': it.name, + 'unit': it.name + })).id) // get the id of the returned record + ) + + const stepIds = await Promise.all( + + ) + +} + function addIngredient() { const ing = { - qty: ingredientFields[0].value, + quantity: ingredientFields[0].value, unit: ingredientFields[1].value, name: ingredientFields[2].value } @@ -71,7 +105,7 @@ function addIngredient() { const newRow = document.createElement('tr') newRow.innerHTML = ` - ${ing.qty} + ${ing.quantity} ${ing.unit} ${ing.name} ` -- 2.47.2 From 0be2aa31477f27158532f36bb9e398d145611a75 Mon Sep 17 00:00:00 2001 From: June Date: Fri, 22 Aug 2025 16:19:46 +1200 Subject: [PATCH 10/10] basic recipe creation works! --- src/script/newRecipe.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/script/newRecipe.ts b/src/script/newRecipe.ts index 0016b72..5b30a37 100644 --- a/src/script/newRecipe.ts +++ b/src/script/newRecipe.ts @@ -81,17 +81,25 @@ async function addRecipe() { console.log(comps.ings) const ingredientIDs = await Promise.all( - comps.ings.map(async it => (await client.pb.collection('ingredients').create({ - 'quantity': it.quantity, - 'name': it.name, - 'unit': it.name - })).id) // get the id of the returned record + comps.ings.map(async it => (await client.pb.collection('ingredients').create(it)).id) // get the id of the returned record ) - const stepIds = await Promise.all( - + const stepIDs = await Promise.all( + comps.stepList.map(async it => (await client.pb.collection('steps').create(it)).id) ) + const recipe = await client.pb.collection('recipes').create({ + name: comps.name, + description: comps.description, + servings: comps.servings, + worktime: comps.worktime, + waittime: comps.waittime, + rating: comps.rating, + ingredients: ingredientIDs, + steps: stepIDs + }) + + console.log(recipe) } function addIngredient() { -- 2.47.2