Refactor ingredients for ingredient add (WIP)

Currently non-functional as the livewire component does not work inside an
Alpine template.
This commit is contained in:
Christopher C. Wells 2021-01-20 06:07:34 -08:00 committed by Christopher Charbonneau Wells
parent 372753887f
commit 856bfb39b9
1 changed files with 41 additions and 33 deletions

View File

@ -63,39 +63,47 @@
<!-- Ingredients --> <!-- Ingredients -->
<h3 class="pt-2 mb-2 font-extrabold">Ingredients</h3> <h3 class="pt-2 mb-2 font-extrabold">Ingredients</h3>
@for($i = 0; $i < 20; $i++) <div x-data="{ingredients: 0}">
@php @foreach($recipe->foodAmounts as $foodAmount)
if (isset($recipe->foodAmounts[$i])) { <div class="flex flex-row space-x-4 mb-4">
$foodAmount = $recipe->foodAmounts[$i]; <x-inputs.input type="text"
$amount = \App\Support\Number::fractionStringFromFloat($foodAmount->amount); name="foods_amount[]"
$unit = $foodAmount->unit; size="5"
$food_id = $foodAmount->food->id; :value="old('foods_amount.' . $loop->index, \App\Support\Number::fractionStringFromFloat($foodAmount->amount))" />
$food_name = $foodAmount->food->name; <x-inputs.select name="foods_unit[]"
$detail = $foodAmount->detail; :options="$food_units"
} else { :selectedValue="old('foods_unit.' . $loop->index, $foodAmount->unit)">
$foodAmount = new \App\Models\FoodAmount(); <option value=""></option>
$amount = $food_id = $food_name = $unit = $detail = null; </x-inputs.select>
} <livewire:food-picker :index="$loop->index"
@endphp :default-id="old('foods.' . $loop->index, $foodAmount->food->id)"
<div class="flex flex-row space-x-4 mb-4"> :default-name="old('foods_name.' . $loop->index, $foodAmount->food->name)" />
<x-inputs.input type="text" <x-inputs.input type="text"
name="foods_amount[]" class="block"
size="5" name="foods_detail[]"
:value="old('foods_amount.' . $i, $amount)" /> :value="old('foods_detail.' . $loop->index, $foodAmount->detail)" />
<x-inputs.select name="foods_unit[]" </div>
:options="$food_units" @endforeach
:selectedValue="old('foods_unit.' . $i, $unit)"> <template x-for="i in ingredients + 1">
<option value=""></option> <div class="flex flex-row space-x-4 mb-4">
</x-inputs.select> <x-inputs.input type="text"
<livewire:food-picker :index="$i" name="foods_amount[]"
:default-id="old('foods.' . $i, $food_id)" size="5" />
:default-name="old('foods_name.' . $i, $food_name)" /> <x-inputs.select name="foods_unit[]"
<x-inputs.input type="text" :options="$food_units" >
class="block" <option value=""></option>
name="foods_detail[]" </x-inputs.select>
:value="old('foods_detail.' . $i, $detail)" /> <!-- TODO: Get this working in the template. See wire:init or use wire:click? -->
</div> <livewire:food-picker index="1" />
@endfor <x-inputs.input type="text"
class="block"
name="foods_detail[]" />
</div>
</template>
<x-inputs.button type="button" class="ml-3" x-on:click="ingredients++;">
Add Ingredient
</x-inputs.button>
</div>
<!-- Steps --> <!-- Steps -->
<h3 class="pt-2 mb-2 font-extrabold">Steps</h3> <h3 class="pt-2 mb-2 font-extrabold">Steps</h3>