Compare commits

..

2 Commits

Author SHA1 Message Date
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
2 changed files with 37 additions and 11 deletions

View File

@ -52,7 +52,7 @@ async function submitRecipe() {
<th class="px-4 py-2">Ingredient</th> <th class="px-4 py-2">Ingredient</th>
</tr> </tr>
</thead> </thead>
<tbody id="ingredient-table" class="w-full border-t px-4 py-2 border-gray-600"> <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 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">
@ -69,13 +69,13 @@ async function submitRecipe() {
</table> </table>
</div> </div>
<ul class="flex mt-4 md:flex-2/3 w-full flex-col"> <ul id="step-list" 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 -->
<p class="text-[22pt] font-bold md:hidden">Steps</p> <p class="text-[22pt] font-bold md:hidden">Steps</p>
<div class="bg-[#2a2b2c] md:ml-3 rounded-lg mb-2 p-2"> <div class="bg-[#2a2b2c] rounded-lg mb-2 p-2">
<!-- <p class="text-bold text-[10pt]">Step</p> --> <!-- <p class="text-bold text-[10pt]">Step</p> -->
<textarea <textarea
id="new-instruction" id="new-instruction"

View File

@ -2,17 +2,16 @@ 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')!
let stepInput: HTMLTextAreaElement = document.querySelector('#new-instruction')!
let stepList: HTMLUListElement = document.querySelector('#step-list')
let currentStepIndex = 0
// - VARS // - VARS
let ingredients: {qty: string, unit: string, name: string}[] = [] let ingredients: {qty: string, unit: string, name: string}[] = []
let steps: { let steps: {
name: string, index: number,
description: string, instruction: string,
servings: number, ingredients: string[], // IDs of ingredient fields
rating: number,
worktime: number,
waittime: number,
images: string[], // record ID of uploaded image
}[] = [] }[] = []
// - INIT // - INIT
@ -30,6 +29,9 @@ document.addEventListener('DOMContentLoaded', function() {
document.querySelector('#add-ingredient-btn')?.addEventListener('click', addIngredient); document.querySelector('#add-ingredient-btn')?.addEventListener('click', addIngredient);
// for pressing enter to reset cursor // for pressing enter to reset cursor
ingredientFields[2].addEventListener('keyup', e => {if (e.key === 'Enter') addIngredient()} ) ingredientFields[2].addEventListener('keyup', e => {if (e.key === 'Enter') addIngredient()} )
// Steps
stepInput.addEventListener('keyup', e => { if (e.key === 'Enter' && e.shiftKey) addStep() } )
}); });
// - ADD // - ADD
@ -57,6 +59,30 @@ function addIngredient() {
ingredientFields[0].focus() ingredientFields[0].focus()
} }
function addStep() {
const step = {
index: currentStepIndex++,
instruction: stepInput.value,
ingredients: []
}
steps.push(step)
const newStep = document.createElement('div')
newStep.innerHTML = `
<p class="text-bold text-[10pt]">Step ${step.index + 1}</p>
<div class="flex flex-col md:flex-row md:items-stretch">
<p class="w-full md:flex-2/3 pr-1 text-left">${step.instruction}</p>
</div>
`
newStep.className = "bg-[#2a2b2c] rounded-lg mb-2 p-3"
stepList.appendChild(newStep)
stepInput.value = ''
}
// - UTILS // - UTILS
function showAddIngredientButton() { function showAddIngredientButton() {
// only show if there is text in the field // only show if there is text in the field