Compare commits
No commits in common. "a9e4d5fb50681eea6728e3e808097587e56e62b3" and "0e469e60245e631724a7081736e965d6255e8f1b" have entirely different histories.
a9e4d5fb50
...
0e469e6024
@ -85,8 +85,6 @@ async function submitRecipe() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button disabled class="disabled:text-white/20 ml-auto mb-2 text-white bg-white/10 rounded-lg px-3 py-1 " id="add-step-btn" >Add</button>
|
|
||||||
|
|
||||||
<ul id="step-list"></ul>
|
<ul id="step-list"></ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ let ingredientTable: HTMLTableSectionElement = document.querySelector('#ingredie
|
|||||||
let ingredientAddButton: HTMLButtonElement = document.querySelector('#add-ingredient-btn')!
|
let ingredientAddButton: HTMLButtonElement = document.querySelector('#add-ingredient-btn')!
|
||||||
|
|
||||||
let stepInput: HTMLTextAreaElement = document.querySelector('#new-instruction')!
|
let stepInput: HTMLTextAreaElement = document.querySelector('#new-instruction')!
|
||||||
let stepAddButton: HTMLButtonElement = document.querySelector('#add-step-btn')!
|
|
||||||
let stepList: HTMLUListElement = document.querySelector('#step-list')!
|
let stepList: HTMLUListElement = document.querySelector('#step-list')!
|
||||||
let currentStepIndex = 0
|
let currentStepIndex = 0
|
||||||
|
|
||||||
@ -23,40 +22,22 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
document.querySelector('#ing-unit')!,
|
document.querySelector('#ing-unit')!,
|
||||||
document.querySelector('#ing-name')!
|
document.querySelector('#ing-name')!
|
||||||
)
|
)
|
||||||
|
|
||||||
stepInput.addEventListener('input', showAddStepButton)
|
|
||||||
|
|
||||||
// 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 => {
|
||||||
f.addEventListener('input', showAddIngredientButton)
|
f.addEventListener('input', showAddIngredientButton)
|
||||||
f.addEventListener('keydown', showAddIngredientButton)
|
f.addEventListener('keyup', showAddIngredientButton)
|
||||||
})
|
})
|
||||||
// onclick for add button
|
// onclick for add button
|
||||||
document.querySelector('#add-ingredient-btn')?.addEventListener('click', addIngredient);
|
document.querySelector('#add-ingredient-btn')?.addEventListener('click', addIngredient);
|
||||||
|
// for pressing enter to reset cursor
|
||||||
// Enter key navigation for ingredient fields
|
ingredientFields[2].addEventListener('keyup', e => {if (e.key === 'Enter') addIngredient()} )
|
||||||
ingredientFields[0].addEventListener('keydown', e => {
|
|
||||||
if (e.key === 'Enter') {
|
|
||||||
ingredientFields[1].focus() // Move from qty to unit
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
ingredientFields[1].addEventListener('keydown', e => {
|
|
||||||
if (e.key === 'Enter') {
|
|
||||||
ingredientFields[2].focus() // Move from unit to name
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// for pressing enter to add ingredient (on the last field)
|
|
||||||
ingredientFields[2].addEventListener('keydown', e => {if (e.key === 'Enter') addIngredient()} )
|
|
||||||
|
|
||||||
// Initial check for button state
|
// Initial check for button state
|
||||||
showAddIngredientButton()
|
showAddIngredientButton()
|
||||||
showAddStepButton()
|
|
||||||
|
|
||||||
// Steps
|
// Steps
|
||||||
stepInput.addEventListener('keyup', e => { if (e.key === 'Enter' && e.shiftKey) addStep() } )
|
stepInput.addEventListener('keyup', e => { if (e.key === 'Enter' && e.shiftKey) addStep() } )
|
||||||
stepAddButton.addEventListener('click', addStep)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// - ADD
|
// - ADD
|
||||||
@ -79,7 +60,7 @@ function addIngredient() {
|
|||||||
// Add row to table and clear fields
|
// Add row to table and clear fields
|
||||||
ingredientTable.appendChild(newRow)
|
ingredientTable.appendChild(newRow)
|
||||||
ingredientFields.forEach(f => f.value = '')
|
ingredientFields.forEach(f => f.value = '')
|
||||||
ingredientAddButton.disabled = true // Hide Add Ingredient button
|
ingredientAddButton.style.display = 'none' // Hide Add Ingredient button
|
||||||
// move cursor to Qty field again
|
// move cursor to Qty field again
|
||||||
ingredientFields[0].focus()
|
ingredientFields[0].focus()
|
||||||
}
|
}
|
||||||
@ -94,7 +75,6 @@ function addStep() {
|
|||||||
steps.push(step)
|
steps.push(step)
|
||||||
renderSteps()
|
renderSteps()
|
||||||
stepInput.value = ''
|
stepInput.value = ''
|
||||||
stepAddButton.disabled = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderSteps() {
|
function renderSteps() {
|
||||||
@ -106,7 +86,7 @@ function renderSteps() {
|
|||||||
const newStep = document.createElement('div')
|
const newStep = document.createElement('div')
|
||||||
// times like this i regret using astro
|
// times like this i regret using astro
|
||||||
newStep.innerHTML = `
|
newStep.innerHTML = `
|
||||||
<div class="flex justify-between items-start ">
|
<div class="flex justify-between items-start mb-2">
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<p class="text-bold text-[10pt]">Step ${displayIndex + 1}</p>
|
<p class="text-bold text-[10pt]">Step ${displayIndex + 1}</p>
|
||||||
<div class="flex flex-col md:flex-row md:items-stretch">
|
<div class="flex flex-col md:flex-row md:items-stretch">
|
||||||
@ -116,7 +96,6 @@ function renderSteps() {
|
|||||||
|
|
||||||
<div class="flex flex-col gap-1">
|
<div class="flex flex-col gap-1">
|
||||||
<button id="move-up-btn" class="px-2 py-1 bg-white/10 hover:bg-white/30 transition-colors rounded text-xs" data-step-index="${step.index}" ${displayIndex === 0 ? 'disabled' : ''}>↑</button>
|
<button id="move-up-btn" class="px-2 py-1 bg-white/10 hover:bg-white/30 transition-colors rounded text-xs" data-step-index="${step.index}" ${displayIndex === 0 ? 'disabled' : ''}>↑</button>
|
||||||
|
|
||||||
<button id="move-down-btn" class="px-2 py-1 bg-white/10 hover:bg-white/30 transition-colors rounded text-xs" data-step-index="${step.index}" ${displayIndex === steps.length - 1 ? 'disabled' : ''}>↓</button>
|
<button id="move-down-btn" class="px-2 py-1 bg-white/10 hover:bg-white/30 transition-colors rounded text-xs" data-step-index="${step.index}" ${displayIndex === steps.length - 1 ? 'disabled' : ''}>↓</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -154,14 +133,6 @@ function showAddIngredientButton() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function showAddStepButton() {
|
|
||||||
if (stepInput.value.trim().length > 0) {
|
|
||||||
stepAddButton.disabled = false
|
|
||||||
} else {
|
|
||||||
stepAddButton.disabled = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// shift: the direction to move. should be +1 to move down or -1 to move up the list
|
// shift: the direction to move. should be +1 to move down or -1 to move up the list
|
||||||
function moveStep(stepIndex: number, shift: number) {
|
function moveStep(stepIndex: number, shift: number) {
|
||||||
// Find the step in the array
|
// Find the step in the array
|
||||||
|
Loading…
x
Reference in New Issue
Block a user