diff --git a/app/Http/Controllers/RecipeController.php b/app/Http/Controllers/RecipeController.php index 3c689f2..7caecb8 100644 --- a/app/Http/Controllers/RecipeController.php +++ b/app/Http/Controllers/RecipeController.php @@ -71,16 +71,8 @@ class RecipeController extends Controller */ public function edit(Recipe $recipe): View { - $foods = Food::all(['id', 'name', 'detail'])->sortBy('name')->collect() - ->map(function ($food) { - return [ - 'value' => $food->id, - 'label' => "{$food->name}" . ($food->detail ? ", {$food->detail}" : ""), - ]; - }); return view('recipes.edit') ->with('recipe', $recipe) - ->with('foods', $foods) ->with('food_units', new Collection([ ['value' => 'tsp', 'label' => 'tsp.'], ['value' => 'tbsp', 'label' => 'tbsp.'], diff --git a/app/Http/Livewire/FoodPicker.php b/app/Http/Livewire/FoodPicker.php index 3999f88..19f5cc3 100644 --- a/app/Http/Livewire/FoodPicker.php +++ b/app/Http/Livewire/FoodPicker.php @@ -7,7 +7,17 @@ use Livewire\Component; class FoodPicker extends Component { - public string $term = ''; + public ?string $term = NULL; + public int $index; + public ?int $defaultId = NULL; + public ?string $defaultName = NULL; + + /** + * Set the default term on mount. + */ + public function mount() { + $this->term = $this->defaultName; + } /** * Get the view / contents that represent the component. @@ -21,6 +31,7 @@ class FoodPicker extends Component } else { $foods = []; } - return view('livewire.food-picker')->with('foods', $foods); + return view('livewire.food-picker') + ->with('foods', $foods); } } diff --git a/public/css/app.css b/public/css/app.css index 1cef631..c0400c3 100644 --- a/public/css/app.css +++ b/public/css/app.css @@ -31425,6 +31425,12 @@ select { animation: bounce 1s infinite; } +/* See: https://ryangjchandler.co.uk/articles/hiding-elements-until-alpine-is-ready-with-x-cloak */ + +[x-cloak] { + display: none !important; +} + @media (min-width: 640px) { .sm\:container { width: 100%; diff --git a/public/js/app.js b/public/js/app.js index 42a29e2..709fb7a 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -21338,8 +21338,8 @@ window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { -__webpack_require__(/*! /Users/wellc/PhpstormProjects/prndb/resources/js/app.js */"./resources/js/app.js"); -module.exports = __webpack_require__(/*! /Users/wellc/PhpstormProjects/prndb/resources/css/app.css */"./resources/css/app.css"); +__webpack_require__(/*! /home/chris/PhpstormProjects/pfnj/resources/js/app.js */"./resources/js/app.js"); +module.exports = __webpack_require__(/*! /home/chris/PhpstormProjects/pfnj/resources/css/app.css */"./resources/css/app.css"); /***/ }) diff --git a/public/js/app.js.LICENSE.txt b/public/js/app.js.LICENSE.txt new file mode 100644 index 0000000..b1121f5 --- /dev/null +++ b/public/js/app.js.LICENSE.txt @@ -0,0 +1,8 @@ +/** + * @license + * Lodash + * Copyright OpenJS Foundation and other contributors + * Released under MIT license + * Based on Underscore.js 1.8.3 + * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors + */ diff --git a/resources/css/app.css b/resources/css/app.css index a31e444..10eee8a 100644 --- a/resources/css/app.css +++ b/resources/css/app.css @@ -1,3 +1,8 @@ @import 'tailwindcss/base'; @import 'tailwindcss/components'; @import 'tailwindcss/utilities'; + +/* See: https://ryangjchandler.co.uk/articles/hiding-elements-until-alpine-is-ready-with-x-cloak */ +[x-cloak] { + display: none !important; +} diff --git a/resources/views/livewire/food-picker.blade.php b/resources/views/livewire/food-picker.blade.php index 00d5303..5887b6e 100644 --- a/resources/views/livewire/food-picker.blade.php +++ b/resources/views/livewire/food-picker.blade.php @@ -1,35 +1,46 @@ -
+
+ + x-on:input.debounce.400ms="searching = ($event.target.value != '')" + x-on:focusout.debounce.200ms="searching = false;" + x-ref="foods_name{{ $index }}" />
-
-
+
+
@forelse($foods as $food) -
-
- {{ $food->name }}@if($food->detail), {{ $food->detail }}@endif -
- @if($food->brand) -
- {{ $food->brand }} +
+
+
+ {{ $food->name }}@if($food->detail), {{ $food->detail }}@endif +
+ @if($food->brand) +
+ {{ $food->brand }} +
+ @endif +
+ Serving size {{ \App\Support\Number::fractionStringFromFloat($food->serving_size) }} + {{ $food->serving_unit }} + ({{ $food->serving_weight }}g)
- @endif -
- Serving size {{ \App\Support\Number::fractionStringFromFloat($food->serving_size) }} - {{ $food->serving_unit }} - ({{ $food->serving_weight }}g)
@empty -
+
No results found.
@endforelse diff --git a/resources/views/recipes/edit.blade.php b/resources/views/recipes/edit.blade.php index 553bce6..8fd5716 100644 --- a/resources/views/recipes/edit.blade.php +++ b/resources/views/recipes/edit.blade.php @@ -70,10 +70,11 @@ $amount = \App\Support\Number::fractionStringFromFloat($foodAmount->amount); $unit = $foodAmount->unit; $food_id = $foodAmount->food->id; + $food_name = $foodAmount->food->name; $detail = $foodAmount->detail; } else { $foodAmount = new \App\Models\FoodAmount(); - $amount = $food_id = $unit = $detail = null; + $amount = $food_id = $food_name = $unit = $detail = null; } @endphp
@@ -86,12 +87,9 @@ :selectedValue="old('foods_unit.' . $i, $unit)"> -{{-- --}} -{{-- --}} -{{-- --}} - +