From 587bcff62615f7a34e579bd1dfb2b18a8286f87d Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Sun, 24 Dec 2023 22:39:34 +0300 Subject: [PATCH] added show recipe page --- app/Livewire/Recipe/Comment/Create.php | 15 + app/Livewire/Recipe/Comment/Show.php | 9 + app/Livewire/Recipe/Create.php | 1 + app/Models/Recipe.php | 11 + resources/css/app.css | 9 + .../livewire/recipe/comment/create.blade.php | 64 ++- .../livewire/recipe/comment/show.blade.php | 112 +++-- .../livewire/recipe/comment/upvote.blade.php | 2 +- .../views/livewire/recipe/like.blade.php | 4 +- resources/views/recipe/show.blade.php | 428 ++++++++---------- 10 files changed, 341 insertions(+), 314 deletions(-) diff --git a/app/Livewire/Recipe/Comment/Create.php b/app/Livewire/Recipe/Comment/Create.php index 6541c37..e0a0aff 100644 --- a/app/Livewire/Recipe/Comment/Create.php +++ b/app/Livewire/Recipe/Comment/Create.php @@ -17,13 +17,25 @@ class Create extends Component public $grade = 0; + public $isChecked = false; + public function render() { return view('livewire.recipe.comment.create'); } + public function toggle() + { + $this->isChecked = !$this->isChecked; + } + public function save() { + $this->validate([ + 'body' => 'required|min:3', + 'grade' => 'required', + ]); + $comment = new RecipeComment(); $comment->grade = $this->grade; $comment->body = $this->body; @@ -32,6 +44,9 @@ class Create extends Component $comment->save(); $this->reset(['body', 'grade']); + + $this->toggle(); + $this->dispatch('commentAdded')->to('recipe.comment.show'); } } diff --git a/app/Livewire/Recipe/Comment/Show.php b/app/Livewire/Recipe/Comment/Show.php index e38077f..ca2278f 100644 --- a/app/Livewire/Recipe/Comment/Show.php +++ b/app/Livewire/Recipe/Comment/Show.php @@ -9,10 +9,19 @@ class Show extends Component { public Recipe $recipe; + public array $tabpanelState = ['positive' => 'positive', 'negative' => false]; + protected $listeners = ['commentAdded' => '$refresh']; public function render() { return view('livewire.recipe.comment.show'); } + + public function toggleTabpanelState($tabpanelName) + { + collect($this->tabpanelState)->keys()->map(fn($key) => $key === $tabpanelName + ? $this->tabpanelState[$tabpanelName] = $tabpanelName + : $this->tabpanelState[$key] = false, array_keys($this->tabpanelState)); + } } diff --git a/app/Livewire/Recipe/Create.php b/app/Livewire/Recipe/Create.php index 1713ae1..a1d1c51 100644 --- a/app/Livewire/Recipe/Create.php +++ b/app/Livewire/Recipe/Create.php @@ -136,6 +136,7 @@ class Create extends Component public function publish() { + $this->validate(); $recipe = new Recipe(); diff --git a/app/Models/Recipe.php b/app/Models/Recipe.php index beffe35..83959d6 100644 --- a/app/Models/Recipe.php +++ b/app/Models/Recipe.php @@ -7,6 +7,7 @@ use CyrildeWit\EloquentViewable\InteractsWithViews; use Illuminate\Database\Eloquent\Casts\AsCollection; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Relations\HasMany; class Recipe extends Model implements Viewable @@ -56,6 +57,16 @@ class Recipe extends Model implements Viewable return $this->hasMany(RecipeLike::class); } + public function scopeByNegative(Builder $query) + { + return static::comments()->where('grade', '<=', '3'); + } + + public function scopeByPositive(Builder $query) + { + return static::comments()->where('grade', '>', '3'); + } + public function isLiked(): bool { $curUser = auth()->user(); diff --git a/resources/css/app.css b/resources/css/app.css index a827885..fe60da7 100644 --- a/resources/css/app.css +++ b/resources/css/app.css @@ -21,3 +21,12 @@ .active-icon-heart{ color: #2f80ed; } + + /* Recipe-show like */ +.text-blue-400 { color: #2f80ed; } + +.text-blue-500 { color: #2f80ed;} + +.text-gray-400 { color: #cbd5e0; } + +.text-gray-500 { color: #a0aec0; } diff --git a/resources/views/livewire/recipe/comment/create.blade.php b/resources/views/livewire/recipe/comment/create.blade.php index 8873d7e..727b68f 100644 --- a/resources/views/livewire/recipe/comment/create.blade.php +++ b/resources/views/livewire/recipe/comment/create.blade.php @@ -1,24 +1,46 @@ -
-
- -
- - $grade >= 1]) width="24" height="24"> - - - $grade >= 2]) width="24" height="24"> - - - $grade >= 3]) width="24" height="24"> - - - $grade >= 4]) width="24" height="24"> - - - $grade >= 5]) width="24" height="24"> - +
+
+ +
+
+ $isChecked]) wire:model="isChecked" wire:click="$set('grade', 5)" type="radio" + name="rate" id="rate-5" value="5" hidden> + + $isChecked]) wire:model="isChecked" wire:click="$set('grade',4)" type="radio" + name="rate" id="rate-4" value="4" hidden> + + $isChecked]) wire:model="isChecked" wire:click="$set('grade',3)" type="radio" + name="rate" id="rate-3" value="3" hidden> + + $isChecked]) wire:model="isChecked" wire:click="$set('grade',2)" type="radio" + name="rate" id="rate-2" value="2" hidden> + + $isChecked]) wire:model="isChecked" wire:click="$set('grade',1)" type="radio" + name="rate" id="rate-1" value="1" hidden> + + +
+ -
-
+ + + + + @error('grade') +
+ {{ $message }} +
+ @enderror + + + + @error('body') +
+ {{ $message }} +
+ @enderror + +
diff --git a/resources/views/livewire/recipe/comment/show.blade.php b/resources/views/livewire/recipe/comment/show.blade.php index 361bc41..3308310 100644 --- a/resources/views/livewire/recipe/comment/show.blade.php +++ b/resources/views/livewire/recipe/comment/show.blade.php @@ -1,60 +1,84 @@ -
-
комментарии
+
@php - $positivComments = $recipe->comments()->where('grade', '>', '3'); - $negativeComments = $recipe->comments()->where('grade', '<=', '3'); - $positiveCommmentsCount = $positivComments->count(); - $negativeCommentsCount = $negativeComments->count(); - @endphp - -
-
- @foreach($positivComments->get() as $comment) -
-
- -
- {{ $comment->author->name }} - {{ $comment->body }} + $positivComments = $recipe->byPositive(); + $negativeComments = $recipe->byNegative(); + + $positiveCommmentsCount = $positivComments->count(); + + $negativeCommentsCount = $negativeComments->count(); + + @endphp + +
+
+ + +
+ +
$tabpanelState['negative'] + ]) role="tabpanel" id="tabpanel-1" tabindex="0" aria-labelledby="tab-1"> + @foreach ($positivComments->get() as $comment) +
+
+
+ user
-
-
-
- - {{ $comment->grade }} +
+
+ {{ $comment->author->name }} +
+
+ {{ $comment->body }} +
+
+
+
+ {{ $comment->grade }} +
+
- @livewire('recipe.comment.upvote', ['comment' => $comment])
@endforeach
-
- @foreach($negativeComments->get() as $comment) -
-
- -
- {{ $comment->author->name }} - {{ $comment->body }} + + +
$tabpanelState['positive'] + ]) role="tabpanel" id="tabpanel-2" tabindex="0" aria-labelledby="tab-1"> + @foreach ($negativeComments->get() as $comment) +
+
+
+ user
-
-
-
- - {{ $comment->grade }} +
+
+ {{ $comment->author->name }} +
+
+ {{ $comment->body }} +
+
+
+
+ {{ $comment->grade }} +
+ +
- @livewire('recipe.comment.upvote', ['comment' => $comment])
@endforeach
+
+
diff --git a/resources/views/livewire/recipe/comment/upvote.blade.php b/resources/views/livewire/recipe/comment/upvote.blade.php index 9286173..6dcc9d6 100644 --- a/resources/views/livewire/recipe/comment/upvote.blade.php +++ b/resources/views/livewire/recipe/comment/upvote.blade.php @@ -1,4 +1,4 @@ -
id }}> +
id }}> diff --git a/resources/views/livewire/recipe/like.blade.php b/resources/views/livewire/recipe/like.blade.php index d807ae0..f555a49 100644 --- a/resources/views/livewire/recipe/like.blade.php +++ b/resources/views/livewire/recipe/like.blade.php @@ -1,4 +1,4 @@ - diff --git a/resources/views/recipe/show.blade.php b/resources/views/recipe/show.blade.php index 2c25ff1..db42b65 100644 --- a/resources/views/recipe/show.blade.php +++ b/resources/views/recipe/show.blade.php @@ -1,147 +1,172 @@ @extends('layouts/eatvio') - @section('page_title', 'Recipe ' . $recipe->title) - @php - $recipeViewsCount = views($recipe)->unique()->count(); - @endphp - @section('main_section') -
-
-
- - Рецепты - -
-
- {{ $recipeViewsCount }} -
-
- @livewire('recipe.like-count', ['recipe' => $recipe]) -
-
- {{ $recipe->comments_count }} -
-
-
-
- {{ $author['name'] }} -
-
- @empty($author->profile_photo_path) - thumb - @else - thumb - @endempty -
-
-
-
-
-
-
-
-
-
- recipe -
-
-
-

- {{ $recipe->title }} -

- -
-
-
{{ __('recipe.t' . $recipe->cooking_time . "m") }}
-
{{ $recipe->steps->count() }} этапов
-
-

{!! $recipe->description !!}

- @if (strlen(trim($recipe->video_url)) > 4) - Посмотреть рецепт на YouTube - @endif -
-
-
-
-
- ПРОДУКТЫ: -
-
    - @foreach($recipe->ingredients as $ingredient) - @php - $localizedUnit = (isset($ingredient['unit']) && mb_strlen($ingredient['unit']) > 1) - ? $ingredient['unit'] - : 'gr'; - @endphp - @if(mb_strlen($ingredient['name']) > 1) -
  • {{ $ingredient['name'] }} - {{ $ingredient['portion'] }} {{ __('recipe.' . $localizedUnit ) }}
  • - @endif - @endforeach -
-
-
-
- ЦЕННОСТЬ: -
-
    -
  • WIP
  • - {{-- +@section('page_title', 'Recipe ' . $recipe->title) +@php + $recipeViewsCount = views($recipe) + ->unique() + ->count(); +@endphp +@section('main_section') +
    +
    +
    + + Рецепты + +
    +
    + {{ $recipeViewsCount }} +
    +
    + @livewire('recipe.like-count', ['recipe' => $recipe]) +
    +
    + {{ $recipe->comments_count }} +
    +
    +
    +
    + {{ $author['name'] }} +
    +
    + @empty($author->profile_photo_path) + thumb + @else + thumb + @endempty +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + recipe +
    +
    +
    +

    + {{ $recipe->title }} +

    + +
    + + +
      +
    • + Редактировать +
    • +
    • + +
    • +
    • + +
    • +
    • + +
    • + {{--
    • --}} + {{--
      ID: 2jkfk45JG
      --}} + {{--
    • --}} +
    + +
    + +
    +
    +
    {{ __('recipe.t' . $recipe->cooking_time . 'm') }}
    +
    {{ $recipe->steps->count() }} этапов
    +
    +

    {!! $recipe->description !!}

    + @if (strlen(trim($recipe->video_url)) > 4) + Посмотреть рецепт на YouTube + @endif +
    +
    +
    +
    +
    + ПРОДУКТЫ: +
    +
      + @foreach ($recipe->ingredients as $ingredient) + @php + $localizedUnit = isset($ingredient['unit']) && mb_strlen($ingredient['unit']) > 1 ? $ingredient['unit'] : 'gr'; + @endphp + @if (mb_strlen($ingredient['name']) > 1) +
    • {{ $ingredient['name'] }} - {{ $ingredient['portion'] }} + {{ __('recipe.' . $localizedUnit) }}
    • + @endif + @endforeach +
    +
    +
    +
    + ЦЕННОСТЬ: +
    +
      +
    • WIP
    • + {{--
    • Калории: 139.9 ккал
    • Белки: 20.4 гр
    • Жиры: 5.7 гр
    • Углеводы: 1.8 гр
    • --}} -
    -
    -
    -
    - ЦЕННОСТЬ: -
    -
    - @foreach($recipe->tags->unique() as $curTag) - {{ $curTag->name }} - @endforeach -
    -
    -
    - -
    -
    -
    -
    -
    -

    - ПОШАГОВЫЙ ФОТО РЕЦЕПТ - {{ $recipe->title }} -

    -
      - @foreach($recipe->steps as $step) +
+
+
+
+ ЦЕННОСТЬ: +
+
+ @foreach ($recipe->tags->unique() as $curTag) + {{ $curTag->name }} + @endforeach +
+
+
+ +
+
+
+
+
+

+ ПОШАГОВЫЙ ФОТО РЕЦЕПТ - {{ $recipe->title }} +

+
    + @foreach ($recipe->steps as $step) +
  1. +
    + @if (isset($step['image']) && is_string($step['image']) && strlen($step['image']) > 4) + step + @endif +
    +
    + + {!! $step['description'] !!} + +
    +
  2. + @endforeach -
  3. -
    - @if(isset($step['image']) && is_string($step['image']) && strlen($step["image"]) > 4) - step - @endif -
    -
    - - {!! $step['description'] !!} - -
    -
  4. - @endforeach - - {{--
  5. + {{--
  6. step
    @@ -162,115 +187,26 @@

--}} - -
- -
-
-

- Отзывы -

-
-
- - -
-
-
-
-
- user -
-
-
- Артём -
-
- После данного плана питания стал чувствовать себя куда лучше! Обязательно продолжу работать с Дмитрием! -
-
-
-
- Лёгкий -
-
- 5.0 -
-
-
-
-
- user -
-
-
- Артём -
-
- После данного плана питания стал чувствовать себя куда лучше! Обязательно продолжу работать с Дмитрием! -
-
-
-
- Лёгкий -
-
- 5.0 -
-
-
-
-
-
-
-
-
- user -
-
-
- Артём -
-
- Курить план – это плохо! Гласит лозунг и кричит Минздрав. Ну, конечно …Ничем не хуже водки, а водку везде продают и ничего.. ... Говорят, некоторые годами курят план и живут нормальной жизнью…Ну, если они считают это нормальной жизнью, то пусть и дальше существуют…Я не хочу…Я теперь спрашиваю себя – а зачем мне жить, что б просто курить траву?..Теперь мне плохо и траву курить, Проклятый мир! Даже год не покурил… Мне нужно что-то получше.. почище….ярче!!! -
-
-
-
- Лёгкий -
-
- 5.0 -
-
-
-
-
-
-
- -
-
- - - - - - - - - - -
- -
-
-
-
+ +
+ + +
+
+

+ ОТЗЫВЫ +

+ + @livewire('recipe.comment.show', ['recipe' => $recipe]) + @livewire('recipe.comment.create', ['recipe' => $recipe, 'user' => Auth::user()]) +
- @endsection - @push('jq_scripts') - - - @endpush +
+ + +@endsection +{{-- @push('jq_scripts') --}} +{{-- --}} +{{-- --}} +{{-- @endpush --}}