Skip to content

Commit

Permalink
Fix card checkboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
Headscracher committed Feb 6, 2024
1 parent 87146c2 commit 50b2dd4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
3 changes: 3 additions & 0 deletions app/Livewire/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ class Card extends Component
{
public Group $group;
public $checkCount;
public $checkboxes = [];

public function mount(Group $group)
{
$this->group = $group;
$this->checkCount = auth()->user()->getCheckCountForGroupAndDate($this->group, Carbon::today());
$this->checkboxes = [...array_fill(0, $this->checkCount, true), ...array_fill(0, $group->per_day-$this->checkCount, false)];
}
public function render()
{
Expand All @@ -25,5 +27,6 @@ public function check($count)
{
$update = auth()->user()->setCheckCountForGroupAndDate($this->group, Carbon::today(), $count);
$this->checkCount = $update;
$this->checkboxes = [...array_fill(0, $this->checkCount, true), ...array_fill(0, $this->group->per_day-$this->checkCount, false)];
}
}
10 changes: 3 additions & 7 deletions resources/views/livewire/card.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,10 @@ class="{{ $checkCount === $group->per_day ? 'border-pine-400' : 'border-cool-gr
style="font-size: 15px;font-weight: 500;color: #4e4e4e87;">{{ $checkCount ?? 0 }} /
{{ $group->per_day}}</span>
<div class="flex text-lg leading-7 font-medium text-cool-gray-900">
@for ($i = 0; $i < $group['per_day']; $i++) @if($i < $checkCount) <input type="checkbox"
class="form-checkbox w-6 h-6 ml-2 text-pine-600" style="cursor: pointer;"
id="{{ $group['name'].$i }}" wire:click.prevent="check({{$i}})" checked>
@else
<input type="checkbox" class="form-checkbox w-6 h-6 ml-2 text-pine-600"
@for ($i = 0; $i < $group['per_day']; $i++)
<input type="checkbox" class="form-checkbox w-6 h-6 ml-2 text-pine-600"
style="cursor: pointer;" id="{{ $group['name'].$i }}"
wire:click.prevent="check({{$i + 1}})">
@endif
wire:click.prevent="check({{$i < $checkCount ? $i : $i + 1}})" wire:model="checkboxes.{{ $i }}">
@endfor
</div>
</div>
Expand Down

0 comments on commit 50b2dd4

Please sign in to comment.