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 @@ -
+ {{ $comment->body }} ++
+ {{ $comment->body }} ++