From a575622c9c26e9867681ab13d21915450b57b5bc Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Mon, 25 Jan 2021 07:31:38 -0800 Subject: [PATCH] Improve mobile usability in forms --- .../Controllers/JournalEntryController.php | 9 +-- .../components/ingredient-picker.blade.php | 5 +- .../views/components/search-view.blade.php | 2 +- resources/views/foods/edit.blade.php | 19 +++--- resources/views/foods/index.blade.php | 10 ++- .../views/journal-entries/create.blade.php | 2 +- .../views/journal-entries/index.blade.php | 17 ++++- .../partials/entry-item-input.blade.php | 2 +- resources/views/layouts/navigation.blade.php | 68 ++----------------- resources/views/recipes/edit.blade.php | 55 ++++++++------- resources/views/recipes/index.blade.php | 10 ++- .../partials/ingredient-input.blade.php | 59 ++++++++++------ resources/views/recipes/show.blade.php | 2 +- 13 files changed, 122 insertions(+), 138 deletions(-) diff --git a/app/Http/Controllers/JournalEntryController.php b/app/Http/Controllers/JournalEntryController.php index e3dcfae..ddbb443 100644 --- a/app/Http/Controllers/JournalEntryController.php +++ b/app/Http/Controllers/JournalEntryController.php @@ -34,15 +34,15 @@ class JournalEntryController extends Controller 'user_id' => Auth::user()->id, 'date' => $date, ])->get()) - ->with('date', Carbon::createFromFormat('Y-m-d', $date)) - ->with('nutrients', ['calories', 'fat', 'cholesterol', 'carbohydrates', 'sodium', 'protein']); + ->with('date', Carbon::createFromFormat('Y-m-d', $date)); } /** * Show the form for creating a new resource. */ - public function create(): View + public function create(Request $request): View { + $date = $request->date ?? Carbon::now()->toDateString(); $ingredients = []; if ($old = old('ingredients')) { foreach ($old['amount'] as $key => $amount) { @@ -77,7 +77,8 @@ class JournalEntryController extends Controller ['value' => 'oz', 'label' => 'oz'], ['value' => 'g', 'label' => 'grams'], ['value' => 'servings', 'label' => 'servings'], - ]); + ]) + ->with('default_date', Carbon::createFromFormat('Y-m-d', $date)); } /** diff --git a/resources/views/components/ingredient-picker.blade.php b/resources/views/components/ingredient-picker.blade.php index a8c703d..8638e5c 100644 --- a/resources/views/components/ingredient-picker.blade.php +++ b/resources/views/components/ingredient-picker.blade.php @@ -25,7 +25,8 @@
+ x-bind:data-name="result.name" + x-bind:data-detail="result.detail">
@@ -77,7 +78,7 @@ if (selected.dataset.id) { this.$refs.ingredients.value = selected.dataset.id; this.$refs.ingredients_type.value = selected.dataset.type; - this.$refs.ingredients_name.value = selected.dataset.name; + this.$refs.ingredients_name.value = `${selected.dataset.name}, ${selected.dataset.detail}`; this.searching = false; } } diff --git a/resources/views/components/search-view.blade.php b/resources/views/components/search-view.blade.php index 9c42cb2..d9d50b0 100644 --- a/resources/views/components/search-view.blade.php +++ b/resources/views/components/search-view.blade.php @@ -5,7 +5,7 @@ autocomplete="off" class="w-full mb-4" @input.debounce.400ms="search($event)" /> -
+
{{ $results }}
exists)@method('put')@endif @csrf
-
+
-
+
-
+
-
+
-
+
@php if (!empty($food->serving_size)) { @@ -62,7 +62,7 @@ @@ -85,7 +86,7 @@
-
+
@foreach ($nutrients as $nutrient)
@@ -102,7 +103,7 @@ :value="ucfirst($nutrient) . ' (g)'"/> -

Foods

+
diff --git a/resources/views/journal-entries/create.blade.php b/resources/views/journal-entries/create.blade.php index 85e5020..c2d340b 100644 --- a/resources/views/journal-entries/create.blade.php +++ b/resources/views/journal-entries/create.blade.php @@ -22,7 +22,7 @@ @include('journal-entries.partials.entry-item-input', $ingredient) @endforeach
diff --git a/resources/views/journal-entries/index.blade.php b/resources/views/journal-entries/index.blade.php index ffe2656..c9ffa86 100644 --- a/resources/views/journal-entries/index.blade.php +++ b/resources/views/journal-entries/index.blade.php @@ -1,6 +1,17 @@ -

{{ Auth::user()->name }}'s Journal

+
+

+ {{ Auth::user()->name }}'s Journal +
{{ $date->format('D, j M Y') }}
+

+ + + + + New Entry + +
@@ -37,7 +48,7 @@

{{ Str::ucfirst($meal) }} - @foreach($nutrients as $nutrient) + @foreach(\App\Support\Nutrients::$all as $nutrient) {{ round($entries->where('meal', $meal)->sum($nutrient), 2) }}g {{ $nutrient }}@if(!$loop->last), @endif @endforeach @@ -57,7 +68,7 @@

nutrients: - @foreach($nutrients as $nutrient) + @foreach(\App\Support\Nutrients::$all as $nutrient) {{ round($entry->{$nutrient}, 2) }}g {{ $nutrient }}@if(!$loop->last), @endif @endforeach diff --git a/resources/views/journal-entries/partials/entry-item-input.blade.php b/resources/views/journal-entries/partials/entry-item-input.blade.php index 76371b9..1ee9541 100644 --- a/resources/views/journal-entries/partials/entry-item-input.blade.php +++ b/resources/views/journal-entries/partials/entry-item-input.blade.php @@ -4,7 +4,7 @@
diff --git a/resources/views/layouts/navigation.blade.php b/resources/views/layouts/navigation.blade.php index 3b67f39..380d6b4 100644 --- a/resources/views/layouts/navigation.blade.php +++ b/resources/views/layouts/navigation.blade.php @@ -9,70 +9,10 @@
- - - - - - - - - diff --git a/resources/views/recipes/edit.blade.php b/resources/views/recipes/edit.blade.php index c4af530..3acb360 100644 --- a/resources/views/recipes/edit.blade.php +++ b/resources/views/recipes/edit.blade.php @@ -12,35 +12,33 @@
@if ($recipe->exists)@method('put')@endif @csrf -
-
- -
- +
+ +
+ - -
+ +
- -
- + +
+ - -
+
-
+
- +
+
@@ -65,12 +64,12 @@
-

Ingredients

-
+

Ingredients

+
@foreach($ingredients as $ingredient) @include('recipes.partials.ingredient-input', $ingredient) @endforeach -