Compare commits

..

25 Commits

Author SHA1 Message Date
1841aa9cba Colour transition for button disabling 2025-08-15 15:55:29 +12:00
fbef074912 Keep focus on new step field when pressing add 2025-08-15 15:37:20 +12:00
a9e4d5fb50 Enter key navigation for ingredient fields, great for mobile 2025-08-15 15:21:48 +12:00
4dc45b4e70 Add step button which acts like a click 2025-08-15 15:11:36 +12:00
0e469e6024 Always show add ingredient button and alter disable value. Also much better handling of the state too 2025-08-15 14:58:55 +12:00
2604d438f7 ultra small but fixed padding issue on textbox 2025-08-15 14:48:12 +12:00
c420a63a2c Step re-ordering implemented but at what (technical) cost man... 2025-08-15 14:41:55 +12:00
5949c7e35c Fix shift+enter leaving a new line in input 2025-08-15 14:23:09 +12:00
8c22c92dee Initial implementation of adding new steps 2025-08-15 14:20:42 +12:00
691a340ad4 Refactored AddRecipe to its own script file, started implementing adding steps 2025-08-15 13:32:58 +12:00
c52d9f79bb Style add button to be presentable 2025-08-14 23:12:44 +12:00
dce5ba8990 Pressing enter/return clears the fields and returns the cursor to the Qty input 2025-08-14 18:48:03 +12:00
89c04bb909 Add ingredients as rows to the column, and reset the form 2025-08-14 18:29:39 +12:00
4dd50aae36 Starting to add script for adding ingredients 2025-08-14 18:04:21 +12:00
aa2409e591 Change leading in recipe title 2025-08-14 11:37:12 +12:00
7c87342dea name field expands when overflow 2025-08-14 11:31:09 +12:00
97cc5da5b8 Fix table rows being out of alignment 2025-08-14 11:23:51 +12:00
b9c665860f Use fixed table widths 2025-08-14 11:19:34 +12:00
5a171f0f0f Fix styling for new ingredient table 2025-08-14 11:08:25 +12:00
88f6628ee0 Change ratio and text size of step ingredient list 2025-08-14 11:08:25 +12:00
c92c754f5f Changed formatting to have title on left column at all times 2025-08-14 11:08:25 +12:00
672191cc5b fix edge-case layout bug 2025-08-14 11:08:25 +12:00
e487637600 Added basic new recipe page 2025-08-14 11:08:25 +12:00
d191c04bbf i keep getting distracted bruh 2025-08-14 11:08:25 +12:00
8cf8f50ff9 Add underline feedback for top bar 2025-08-14 11:08:25 +12:00
20 changed files with 91 additions and 322 deletions

View File

@@ -7,6 +7,8 @@ import tailwindcss from '@tailwindcss/vite';
import { loadEnv } from "vite"; import { loadEnv } from "vite";
const { PUBLIC_PB_URL } = loadEnv(process.env.NODE_ENV, process.cwd(), "");
// https://astro.build/config // https://astro.build/config
export default defineConfig({ export default defineConfig({
output: 'server', output: 'server',
@@ -17,8 +19,5 @@ export default defineConfig({
vite: { vite: {
plugins: [tailwindcss()], plugins: [tailwindcss()],
server: {
cors: false
}
} }
}); });

View File

@@ -4,7 +4,8 @@ import TagRow from "./TagRow.astro"
const { recipe } = Astro.props; const { recipe } = Astro.props;
const image = (await client.getRecipeImages(recipe.id))[0] const headerImage = await client.collection("images").getOne(recipe.images[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">
@@ -18,7 +19,7 @@ const image = (await client.getRecipeImages(recipe.id))[0]
<!-- <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 tags={recipe.expand.tags}/> <TagRow tagIds={recipe.tags}/>
</div> </div>
</div> </div>

View File

@@ -1,12 +1,29 @@
--- ---
const { tags } = Astro.props import client from "../../data/pocketbase"
interface Props {
tagIds: string[]
}
const { tagIds } = Astro.props
const tags = tagIds && tagIds.length > 0
? await Promise.all(tagIds.map(async (tagId: string) => {
try {
const tagData = await client.collection("tags").getOne(tagId)
return { name: tagData.name, id: tagId }
} catch (error) {
return null
}
}))
: []
--- ---
<div class=""> <div class="">
{ {
(tags ?? []).map(tag => ( tags.map(tag => (
<a <a
href={`/tags/${tag.name}`} 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"
> >
{tag.name} {tag.name}

View File

@@ -1,7 +1,17 @@
--- ---
import client from "@/data/pocketbase"; import client from "@/data/pocketbase";
const { class: className, recipe } = Astro.props const { class: className, recipe } = Astro.props
const links = await client.getRecipeImages(recipe as string)
async function getLink(img: string) {
const record = await client.collection("images").getOne(img)
const link = await client.files.getRelativeURL(record, record.image)
return link
}
// Use Promise.all to wait for all async operations to complete
const links = await Promise.all(
recipe.images.map((img: string) => getLink(img))
)
--- ---

View File

@@ -15,19 +15,8 @@ function formatTime(seconds) {
return result; return result;
} }
function formatTimeMin(minutes) { const workTime = formatTime(re.worktime)
if (minutes === 0) return null const waitTime = formatTime(re.waittime)
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)
--- ---
<p class="text-white/60 text-sm mt-1 italic">{re.description}</p> <p class="text-white/60 text-sm mt-1 italic">{re.description}</p>
@@ -37,4 +26,4 @@ const waitTime = formatTimeMin(re.waittime)
{waitTime && (<p class="border-r px-2">{waitTime} Wait</p>)} {waitTime && (<p class="border-r px-2">{waitTime} Wait</p>)}
{re.rating !== 0 && (<p class="pl-2">{re.rating}</p><p class="text-white/40 text-xs">/10</p>)} {re.rating !== 0 && (<p class="pl-2">{re.rating}</p><p class="text-white/40 text-xs">/10</p>)}
</div> </div>
<TagRow tags={re.expand.tags}/> <TagRow tagIds={re.tags}/>

View File

@@ -3,10 +3,13 @@ import client from "@/data/pocketbase";
const { ingredients, class: className } = Astro.props; const { ingredients, class: className } = Astro.props;
const ings = await Promise.all(
ingredients.map(async i => await client.collection("ingredients").getOne(i))
)
--- ---
<div class={className}> <div class={className}>
{ingredients.map(i => ( {ings.map(i => (
<div class="text-sm"> <div class="text-sm">
<p>• {i.quantity} {i.unit || " "} {i.name}</p> <p>• {i.quantity} {i.unit || " "} {i.name}</p>
</div> </div>

View File

@@ -16,7 +16,7 @@ const { steps, class: className } = Astro.props
<p class="w-full md:flex-2/3 pr-1 text-left">{s.instruction}</p> <p class="w-full md:flex-2/3 pr-1 text-left">{s.instruction}</p>
{s.ingredients && s.ingredients.length > 0 && ( {s.ingredients && s.ingredients.length > 0 && (
<div class="w-full md:w-auto md:flex-2/5 mt-2 md:mt-0 md:ml-2 md:pl-3 md:border-l text-white/70 border-white/70"> <div class="w-full md:w-auto md:flex-2/5 mt-2 md:mt-0 md:ml-2 md:pl-3 md:border-l text-white/70 border-white/70">
<StepIngredientSideView class="text-left" ingredients={s.expand.ingredients} /> <StepIngredientSideView class="text-left" ingredients={s.ingredients} />
</div> </div>
)} )}
</div> </div>

View File

@@ -8,8 +8,7 @@
<div class="ml-auto space-x-5"> <div class="ml-auto space-x-5">
<a class="hover:underline underline-offset-4 " href="/recipe/new">new</a> <a class="hover:underline underline-offset-4 " href="/recipe/new">new</a>
<a class="hover:underline underline-offset-4" href="/recipe/import">add</a> <a class="hover:underline underline-offset-4 " >tags</a>
<!-- <a class="hover:underline underline-offset-4" href="/tags">tags</a> -->
<a class="hover:underline underline-offset-4 " >search</a> <a class="hover:underline underline-offset-4 " >search</a>
</div> </div>
</div> </div>

View File

@@ -1,71 +1,12 @@
import Pocketbase, { type RecordListOptions } from "pocketbase" import Pocketbase from "pocketbase"
import {
type Recipe,
type Ingredient,
type Step,
type Tag,
Collection
} from './schema'
class APIClient { const client = new Pocketbase("http://localhost:4321")
pb: Pocketbase client.autoCancellation(false)
constructor() { // Return a relative url for file instead of full path including localhost, which breaks external access
this.pb = new Pocketbase("http://localhost:4321") client.files.getRelativeURL = (record: { [key: string]: any; }, filename: string, queryParams?: FileOptions | undefined) => {
this.pb.autoCancellation(false) const res = client.files.getURL(record, filename)
return res.substring(21)
} }
async getRecipesPage(page: number, perPage: number = 30, options: RecordListOptions) {
return await this.pb.collection<Recipe>(Collection.RECIPES).getList(page, perPage, options)
}
async getAllRecipes() {
return await this.pb.collection<Recipe>(Collection.RECIPES).getFullList({ expand: 'ingredients,tags,steps,images,steps.ingredients' })
}
async getRecipe(id: string) {
return await this.pb.collection<Recipe>(Collection.RECIPES).getOne(id, { expand: 'ingredients,tags,steps,images,steps.ingredients' })
}
// IMAGE
async getImageURL(imgID: string, relative: boolean = true) {
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
}
async getRecipeImages(recipeID: string) {
const re = await this.getRecipe(recipeID)
const imgIDs = re.images ?? []
const urls = Promise.all(
imgIDs.map(img => this.getImageURL(img))
)
return urls
}
async getAllTags() {
return await this.pb.collection<Tag>(Collection.TAGS).getFullList()
}
async getTag(name: string) {
return await this.pb.collection<Tag>(Collection.TAGS).getList(1, 50, { filter: `name = '${name}'` })
}
async getRecipesOfTag(tagName: string) {
// get the tag id first
const tagResult = await this.getTag(tagName)
if (tagResult.items.length === 0) {
return []
}
const tag = tagResult.items[0]
return await this.pb.collection<Recipe>(Collection.RECIPES).getFullList({
filter: `tags ~ '${tag.id}'`,
expand: 'ingredients,tags,steps,images,steps.ingredients'
})
}
}
const client = new APIClient()
export default client; export default client;

View File

@@ -1,55 +0,0 @@
// Base PB type
export interface BaseRecord {
id: string,
created: string,
updated: string
}
export interface Ingredient extends BaseRecord {
quantity: string,
unit: string,
name: string
}
export interface Step extends BaseRecord {
index: number,
instruction: string,
ingredients?: Ingredient[]
}
export interface Tag extends BaseRecord {
name: string
}
// 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 {
id: string
filename: string
url?: string
}
export interface Recipe extends BaseRecord {
name: string,
description?: string,
servings?: number,
images?: string[], // image IDs
ingredients: string[]
steps: string[],
tags?: string[]
expand: {
images?: Image[], // image IDs,
ingredients: Ingredient[]
steps: Step[],
tags?: Tag[]
}
}
export const Collection = {
RECIPES: 'recipes',
STEPS: 'steps',
INGREDIENTS: 'ingredients',
TAGS: 'tags',
IMAGES: 'images'
}

View File

@@ -10,7 +10,7 @@ import Header from "@/components/Header";
<body> <body>
<main id="main" class="flex-1"> <main id="main" class="flex-1">
<Header/> <Header/>
<div class="px-3 mb-5 md:px-5 pt-2"> <div class="px-3 md:px-5 pt-2">
<slot /> <slot />
</div> </div>
</main> </main>

View File

@@ -1,9 +0,0 @@
---
import Base from "@/layouts/base";
---
<Base>
<div class="flex items-center justify-center text-3xl font-bold">
🥧 404 🥧
</div>
</Base>

View File

@@ -5,15 +5,12 @@ import type { APIRoute } from "astro";
const getProxyUrl = (request: Request) => { const getProxyUrl = (request: Request) => {
const proxyUrl = new URL(import.meta.env.PUBLIC_PB_URL); const proxyUrl = new URL(import.meta.env.PUBLIC_PB_URL);
const requestUrl = new URL(request.url); const requestUrl = new URL(request.url);
return new URL(requestUrl.pathname + requestUrl.search, proxyUrl);
return new URL(requestUrl.pathname, proxyUrl);
}; };
export const ALL: APIRoute = async ({ request }) => { export const ALL: APIRoute = async ({ request }) => {
const proxyUrl = getProxyUrl(request); const proxyUrl = getProxyUrl(request);
const response = await fetch(proxyUrl.href, 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
});
}; };

View File

@@ -3,15 +3,15 @@ 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 recipes = await client.getAllRecipes() const recipies = await client.collection("recipes").getFullList()
--- ---
<PageLayout> <PageLayout>
<!-- <p class="pb-2">What would you like today?</p> --> <!-- <p class="pb-2">What would you like today?</p> -->
<div class="grid gap-3 grid-cols-1 py-3 md:grid-cols-2 lg:grid-cols-4 xl:grid-cols-6"> <div class="grid md:gap-2 gap-3 grid-cols-2 md:grid-cols-2 lg:grid-cols-4 xl:grid-cols-8">
{ {
recipes.map(r => ( recipies.map(r => (
<OverviewCard recipe={r} /> <OverviewCard recipe={r} />
)) ))
} }

View File

@@ -1,6 +1,5 @@
--- ---
import client from "@/data/pocketbase"; import client from "@/data/pocketbase";
import SiteLayout from "@/layouts/base"; import SiteLayout from "@/layouts/base";
import ImageCarousel from "@/components/Detail/ImageCarousel"; import ImageCarousel from "@/components/Detail/ImageCarousel";
import IngredientTableView from "@/components/Detail/IngredientTableView"; import IngredientTableView from "@/components/Detail/IngredientTableView";
@@ -9,25 +8,41 @@ import InfoView from "@/components/Detail/InfoView";
const { recipeid } = Astro.params; const { recipeid } = Astro.params;
const re = await client.getRecipe(recipeid as string) 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)
)
)
--- ---
<SiteLayout> <SiteLayout>
<div class="flex flex-col md:flex-row mx-auto justify-center w-full lg:max-w-3/4 xl:max-w-2/3 2xl:max-w-1/2"> <div class="flex flex-col md:flex-row mx-auto justify-center w-full lg:max-w-3/4 xl:max-w-2/3 2xl:max-w-1/2">
<div class="flex md:flex-1/3 flex-col mt-2 md:mt-4 sticky"> <div class="flex md:flex-1/3 flex-col mt-2 md:mt-4 sticky">
<ImageCarousel class="w-full" recipe={recipeid} /> <ImageCarousel class="w-full" recipe={re} />
<p class="text-[28pt] font-bold leading-11 mt-2">{re.name}</p> <p class="text-[28pt] font-bold leading-11 mt-2">{re.name}</p>
<!-- Details --> <!-- Details -->
<InfoView re={re} /> <InfoView re={re} />
<p class="text-[22pt] font-bold 'md:mt-4'">Ingredients</p> <p class="text-[22pt] font-bold 'md:mt-4'">Ingredients</p>
<IngredientTableView class:list={['md:w-80', 'px-4']} ingredients={re.expand.ingredients ?? []} /> <IngredientTableView class:list={['md:w-80', 'px-4']} ingredients={ingredients} />
</div> </div>
<div class="flex mt-4 md:flex-2/3 w-full flex-col"> <div class="flex mt-4 md:flex-2/3 w-full flex-col">
<!-- Steps --> <!-- Steps -->
<StepView class="md:ml-3" steps={re.expand.steps ?? []} /> <StepView class="md:ml-3" steps={steps} />
</div> </div>
</div> </div>

View File

@@ -13,18 +13,7 @@ async function submitRecipe() {
<SiteLayout> <SiteLayout>
<div class="flex flex-col md:flex-row mx-auto justify-center w-full lg:max-w-3/4 xl:max-w-2/3 2xl:max-w-1/2"> <div class="flex flex-col md:flex-row mx-auto justify-center w-full lg:max-w-3/4 xl:max-w-2/3 2xl:max-w-1/2">
<div class="flex md:flex-1/3 flex-col sticky"> <div class="flex md:flex-1/3 flex-col mt-2 md:mt-4 sticky">
<div class="flex mb-2 items-center">
<p class="text-[28pt] mr-auto">New Recipe</p>
<button
id="btn-save"
class="px-1 w-15 h-9 bg-white/10 active:bg-white/20 transition-colors rounded-lg"
>
Save
</button>
</div>
<div class="relative"> <div class="relative">
<input <input
id="photo" id="photo"
@@ -39,55 +28,20 @@ async function submitRecipe() {
[&::-webkit-file-upload-button]:hidden" [&::-webkit-file-upload-button]:hidden"
> >
</div> </div>
<!-- Details -->
<textarea <textarea
id="rec-name" id="rec-name"
rows="1" rows="1"
placeholder="Name" placeholder="Name"
class="text-[28pt] font-bold p-1 leading-none mt-2 bg-white/10 rounded-lg resize-none overflow-hidden" class="text-[28pt] font-bold p-1 leading-none mt-2 bg-white/10 rounded-lg resize-none overflow-hidden"
oninput="this.style.height = ''; this.style.height = this.scrollHeight + 'px'" oninput="this.style.height = ''; this.style.height = this.scrollHeight + 'px'"
/>
<textarea
id="rec-desc"
rows="3"
placeholder="Description"
class="text-sm italic leading-none mt-2 bg-white/10 rounded-lg resize-none overflow-hidden p-2"
oninput="this.style.height = ''; this.style.height = this.scrollHeight + 'px'"
/> />
<!-- if it works :3 --> <!-- if it works :3 -->
<!-- Smaller details --> <!-- Details -->
<div class="flex mt-2 h-9 space-x-2"> <!-- <InfoView re={re} /> -->
<input
id="rec-servings"
type="number"
class="bg-white/10 px-2 rounded-lg w-24 overflow-hidden"
placeholder="Servings"
/>
<input
id="rec-worktime"
type="text"
class="bg-white/10 px-2 rounded-lg w-24 overflow-hidden"
placeholder="Work Time"
/>
<input
id="rec-waittime"
type="text"
class="bg-white/10 px-2 rounded-lg w-24 overflow-hidden"
placeholder="Wait Time"
/>
<input
id="rec-rating"
type="number"
class="bg-white/10 px-2 rounded-lg w-23 overflow-hidden"
placeholder="Rating"
/>
</div>
<div class="flex flex-row align-middle items-center"> <div class="flex flex-row align-middle items-center">
<p class="mt-4 text-[22pt] font-bold">Ingredients</p> <p class="mt-4 text-[22pt] font-bold 'mt-4'">Ingredients</p>
<button disabled class="disabled:text-white/20 transition-colors ml-auto mt-5 text-white bg-white/10 rounded-lg px-3 py-1 " id="add-ingredient-btn" >Add</button> <button disabled class="disabled:text-white/20 transition-colors ml-auto mt-5 text-white bg-white/10 rounded-lg px-3 py-1 " id="add-ingredient-btn" >Add</button>
</div> </div>
<table class={`table-fixed text-left bg-[#2a2b2c] rounded-lg w-full`}> <table class={`table-fixed text-left bg-[#2a2b2c] rounded-lg w-full`}>
@@ -101,7 +55,7 @@ async function submitRecipe() {
<tbody id="ingredient-table" class="w-full border-t px-4 py-2 border-white/10"> <tbody id="ingredient-table" class="w-full border-t px-4 py-2 border-white/10">
<tr id="ingredient-input" class=""> <tr id="ingredient-input" class="">
<td class="px-2 py-1"> <td class="px-2 py-1">
<input id="ing-qty" class="w-full h-9 my-1 bg-white/10 rounded-lg px-2 py-2" type="text" placeholder="Qty"> <input id="ing-qty" class="w-full h-9 bg-white/10 rounded-lg px-2 py-2" type="text" placeholder="Qty">
</td> </td>
<td class="px-2 py-1"> <td class="px-2 py-1">
<input id="ing-unit" class="w-full h-9 bg-white/10 rounded-lg px-2 py-2" type="text" placeholder="Unit"> <input id="ing-unit" class="w-full h-9 bg-white/10 rounded-lg px-2 py-2" type="text" placeholder="Unit">
@@ -115,7 +69,7 @@ async function submitRecipe() {
</table> </table>
</div> </div>
<div class="flex mt-4 md:mt-16 md:flex-2/3 w-full flex-col md:ml-3"> <div class="flex mt-4 md:flex-2/3 w-full flex-col md:ml-3">
<!-- <p class="hidden md:block text-[28pt] font-bold pl-5">Helloi</p> --> <!-- <p class="hidden md:block text-[28pt] font-bold pl-5">Helloi</p> -->
<!-- Steps --> <!-- Steps -->

View File

@@ -1,22 +0,0 @@
---
import SiteLayout from "@/layouts/base";
import client from "@/data/pocketbase";
import OverviewCard from "@/components/Card/OverviewCard";
const { name } = Astro.params
const recipes = await client.getRecipesOfTag(name) // todo redir to 404 if not found
---
<SiteLayout>
<p class="text-xl pb-2">
{recipes.length} { recipes.length == 1 ? "Recipe" : "Recipes" } with: <code class="bg-white/10 p-1 text-sm rounded-lg" >{name}</code>
</p>
<div class="grid md:gap-2 gap-3 grid-cols-1 md:grid-cols-2 lg:grid-cols-4 xl:grid-cols-8">
{
recipes.map(r => (
<OverviewCard recipe={r} />
))
}
</div>
</SiteLayout>

View File

@@ -1,24 +0,0 @@
---
import client from "@/data/pocketbase";
import SiteLayout from "@/layouts/base";
const tags = await client.getAllTags()
const countsPerTag = await Promise.all(
tags.map(async t => (await client.getRecipesOfTag(t.name)).length)
)
---
<SiteLayout>
<p class="title pb-2">
{tags.length} Tags
</p>
{
(tags ?? []).map((t, i) => (
// <p>{t.name} -&gt; {countsPerTag[i]} {countsPerTag[i] == 1 ? "Recipe" : "Recipes" } </p>
<a class="hover:underline" href={`/tags/${t.name}`}>
{t.name} ({countsPerTag[i]})
</a><br/>
))
}
</SiteLayout>

View File

@@ -1,5 +1,3 @@
import client from "@/data/pocketbase"
let ingredientFields: HTMLInputElement[] = [] let ingredientFields: HTMLInputElement[] = []
let ingredientTable: HTMLTableSectionElement = document.querySelector('#ingredient-table')! let ingredientTable: HTMLTableSectionElement = document.querySelector('#ingredient-table')!
let ingredientAddButton: HTMLButtonElement = document.querySelector('#add-ingredient-btn')! let ingredientAddButton: HTMLButtonElement = document.querySelector('#add-ingredient-btn')!
@@ -10,26 +8,13 @@ let stepList: HTMLUListElement = document.querySelector('#step-list')!
let currentStepIndex = 0 let currentStepIndex = 0
// - VARS // - VARS
let ingredients: {quantity: string, unit: string, name: string}[] = [] let ingredients: {qty: string, unit: string, name: string}[] = []
let steps: { let steps: {
index: number, index: number,
instruction: string, instruction: string,
ingredients: string[], // IDs of ingredient fields 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 // - INIT
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
@@ -40,7 +25,6 @@ document.addEventListener('DOMContentLoaded', function() {
) )
stepInput.addEventListener('input', showAddStepButton) stepInput.addEventListener('input', showAddStepButton)
document.querySelector('#btn-save')?.addEventListener('click', addRecipe)
// show plus button once the user types in the text fields // show plus button once the user types in the text fields
ingredientFields.forEach(f => { ingredientFields.forEach(f => {
@@ -76,35 +60,9 @@ document.addEventListener('DOMContentLoaded', function() {
}); });
// - ADD // - 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(it)).id) // get the id of the returned record
)
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() { function addIngredient() {
const ing = { const ing = {
quantity: ingredientFields[0].value, qty: ingredientFields[0].value,
unit: ingredientFields[1].value, unit: ingredientFields[1].value,
name: ingredientFields[2].value name: ingredientFields[2].value
} }
@@ -113,7 +71,7 @@ function addIngredient() {
const newRow = document.createElement('tr') const newRow = document.createElement('tr')
newRow.innerHTML = ` newRow.innerHTML = `
<td class="px-4 py-2 border-t border-white/10">${ing.quantity}</td> <td class="px-4 py-2 border-t border-white/10">${ing.qty}</td>
<td class="px-4 py-2 border-t border-white/10">${ing.unit}</td> <td class="px-4 py-2 border-t border-white/10">${ing.unit}</td>
<td class="px-4 py-2 border-t border-white/10">${ing.name}</td> <td class="px-4 py-2 border-t border-white/10">${ing.name}</td>
` `

View File

@@ -8,7 +8,3 @@ html {
@apply font-sans; @apply font-sans;
/* font-family: 'SF Pro Display', 'Segoe UI', 'Helvetica Neue', Arial, 'Noto Sans', sans-serif; */ /* font-family: 'SF Pro Display', 'Segoe UI', 'Helvetica Neue', Arial, 'Noto Sans', sans-serif; */
} }
.title {
@apply text-2xl;
}