Compare commits
2 Commits
aa2409e591
...
89c04bb909
Author | SHA1 | Date | |
---|---|---|---|
89c04bb909 | |||
4dd50aae36 |
@ -1,20 +1,66 @@
|
|||||||
---
|
---
|
||||||
import client from "@/data/pocketbase";
|
|
||||||
import SiteLayout from "@/layouts/base";
|
import SiteLayout from "@/layouts/base";
|
||||||
import ImageCarousel from "@/components/Detail/ImageCarousel";
|
|
||||||
import IngredientTableView from "@/components/Detail/IngredientTableView";
|
|
||||||
import StepView from "@/components/Detail/StepView";
|
|
||||||
import InfoView from "@/components/Detail/InfoView";
|
|
||||||
|
|
||||||
const { recipeid } = Astro.params;
|
const { recipeid } = Astro.params;
|
||||||
|
|
||||||
|
// Actually post the recipe with the stored variables
|
||||||
|
async function submitRecipe() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
let ingredients: {qty: string, unit: string, name: string}[] = []
|
let ingredientFields: HTMLInputElement[] = []
|
||||||
|
let ingredientTable: HTMLTableSectionElement = document.querySelector('#ingredient-table')!
|
||||||
|
let ingredientAddButton: HTMLButtonElement = document.querySelector('#add-ingredient-btn')!
|
||||||
|
|
||||||
function addIngredient(q: string, u: string, n: string) {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
ingredients.push({qty: q, unit: u, name: n})
|
|
||||||
|
ingredientFields.push(
|
||||||
|
document.querySelector('#ing-qty')!,
|
||||||
|
document.querySelector('#ing-unit')!,
|
||||||
|
document.querySelector('#ing-name')!
|
||||||
|
)
|
||||||
|
|
||||||
|
// show plus button once the user clicks off one of the text fields
|
||||||
|
ingredientFields.forEach(f => f.addEventListener('beforeinput', showAddIngredientButton))
|
||||||
|
// onclick for add button
|
||||||
|
document.querySelector('#add-ingredient-btn')?.addEventListener('click', addIngredient);
|
||||||
|
});
|
||||||
|
|
||||||
|
let ingredients: {qty: string, unit: string, name: string}[] = []
|
||||||
|
function addIngredient() {
|
||||||
|
const ing = {
|
||||||
|
qty: ingredientFields[0].value,
|
||||||
|
unit: ingredientFields[1].value,
|
||||||
|
name: ingredientFields[2].value
|
||||||
|
}
|
||||||
|
|
||||||
|
ingredients.push(ing)
|
||||||
|
|
||||||
|
// Create the table row HTML directly
|
||||||
|
const newRow = document.createElement('tr')
|
||||||
|
newRow.innerHTML = `
|
||||||
|
<td class="px-2 py-1 border-t border-white/10">${ing.qty}</td>
|
||||||
|
<td class="px-2 py-1 border-t border-white/10">${ing.unit}</td>
|
||||||
|
<td class="px-2 py-1 border-t border-white/10">${ing.name}</td>
|
||||||
|
`
|
||||||
|
|
||||||
|
ingredientTable.appendChild(newRow)
|
||||||
|
|
||||||
|
ingredientFields.forEach(f => f.value = "")
|
||||||
|
ingredientAddButton.style.display = 'none'
|
||||||
|
}
|
||||||
|
|
||||||
|
function showAddIngredientButton() {
|
||||||
|
// only show if there is text in the field
|
||||||
|
|
||||||
|
if (ingredientFields[0].value && ingredientFields[2].value) {
|
||||||
|
ingredientAddButton.style.display = 'block'
|
||||||
|
} else {
|
||||||
|
ingredientAddButton.style.display = 'hidden'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -40,11 +86,12 @@ const { recipeid } = Astro.params;
|
|||||||
|
|
||||||
<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 'mt-4'">Ingredients</p>
|
<p class="mt-4 text-[22pt] font-bold 'mt-4'">Ingredients</p>
|
||||||
|
<button class="hidden" 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`}>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="px-4 py-2 w-25">Quantity</th>
|
<th class="px-4 py-2 w-18">Qty</th>
|
||||||
<th class="px-4 py-2 w-20">Unit</th>
|
<th class="px-4 py-2 w-20">Unit</th>
|
||||||
<th class="px-4 py-2">Ingredient</th>
|
<th class="px-4 py-2">Ingredient</th>
|
||||||
</tr>
|
</tr>
|
||||||
@ -58,7 +105,8 @@ const { recipeid } = Astro.params;
|
|||||||
<input id="ing-unit" class="w-full h-11 bg-white/20 rounded-lg px-2 py-2" type="text" placeholder="Unit">
|
<input id="ing-unit" class="w-full h-11 bg-white/20 rounded-lg px-2 py-2" type="text" placeholder="Unit">
|
||||||
</td>
|
</td>
|
||||||
<td class="px-2 py-1">
|
<td class="px-2 py-1">
|
||||||
<textarea id="ing-name" class="w-full h-11 bg-white/20 rounded-lg px-2 py-3 mt-1 resize-none leading-tight" placeholder="Ingredient" rows="1"/>
|
<!-- <textarea id="ing-name" class="w-full h-11 bg-white/20 rounded-lg px-2 py-3 mt-1 resize-none leading-tight" placeholder="Ingredient" rows="1"/> -->
|
||||||
|
<input id="ing-name" class="w-full h-11 bg-white/20 rounded-lg px-2 py-2" type="text" placeholder="Ingredient">
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user