Skip to content

Commit

Permalink
Merge pull request #3445 from Roardom/speed-ticking-similar
Browse files Browse the repository at this point in the history
(Fix) Quickly ticking torrents on similar page
  • Loading branch information
HDVinnie committed Jan 31, 2024
2 parents da98071 + 493767f commit 1e6f47b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 31 deletions.
27 changes: 8 additions & 19 deletions app/Http/Livewire/SimilarTorrent.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ class SimilarTorrent extends Component
public string $reason;

/**
* @var string[]
* @var array<int, bool|string>
*
* Currently, in livewire v2, a checkbox type is false|string.
* In livewire v3, the type should be changed to array<int, bool>.
*/
public array $checked = [];

public bool $selectPage = false;

public bool $selectAll = false;

public string $sortField = 'bumped_at';

public string $sortDirection = 'desc';
Expand All @@ -61,27 +62,16 @@ final public function updating(string $field, mixed &$value): void
$this->castLivewireProperties($field, $value);
}

final public function updatedSelectPage($value): void
{
$this->checked = $value ? $this->torrents->pluck('id')->map(fn ($item) => (string) $item)->toArray() : [];
}

final public function selectAll(): void
final public function updatedSelectPage(bool $value): void
{
$this->selectAll = true;
$this->checked = $this->torrents->pluck('id')->map(fn ($item) => (string) $item)->toArray();
$this->checked = $value ? $this->torrents->pluck('id')->mapWithKeys(fn ($id) => [(int) $id => true])->toArray() : [];
}

final public function updatedChecked(): void
{
$this->selectPage = false;
}

final public function isChecked($torrentId): bool
{
return \in_array($torrentId, $this->checked);
}

/**
* @return \Illuminate\Support\Collection<int, Torrent>
*/
Expand Down Expand Up @@ -150,7 +140,7 @@ final public function alertConfirm(): void
return;
}

$torrents = Torrent::whereKey($this->checked)->pluck('name')->toArray();
$torrents = Torrent::whereKey(array_keys($this->checked, true))->pluck('name')->toArray();
$names = $torrents;
$this->dispatchBrowserEvent('swal:confirm', [
'type' => 'warning',
Expand All @@ -168,7 +158,7 @@ final public function deleteRecords(): void
return;
}

$torrents = Torrent::whereKey($this->checked)->get();
$torrents = Torrent::whereKey(array_keys($this->checked, true))->get();
$names = [];
$users = [];
$title = match (true) {
Expand Down Expand Up @@ -236,7 +226,6 @@ final public function deleteRecords(): void
}

$this->checked = [];
$this->selectAll = false;
$this->selectPage = false;

$this->dispatchBrowserEvent('swal:modal', [
Expand Down
10 changes: 0 additions & 10 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1135,16 +1135,6 @@ parameters:
count: 1
path: app/Http/Livewire/PersonCredit.php

-
message: "#^Method App\\\\Http\\\\Livewire\\\\SimilarTorrent\\:\\:isChecked\\(\\) has parameter \\$torrentId with no type specified\\.$#"
count: 1
path: app/Http/Livewire/SimilarTorrent.php

-
message: "#^Method App\\\\Http\\\\Livewire\\\\SimilarTorrent\\:\\:updatedSelectPage\\(\\) has parameter \\$value with no type specified\\.$#"
count: 1
path: app/Http/Livewire/SimilarTorrent.php

-
message: "#^Property App\\\\Http\\\\Livewire\\\\SimilarTorrent\\:\\:\\$listeners has no type specified\\.$#"
count: 1
Expand Down
5 changes: 3 additions & 2 deletions resources/views/livewire/similar-torrent.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ class="torrents-filename"
>
<input
id="torrent_checkbox_{{ $torrent->id }}"
name="torrent_checkbox_{{ $torrent->id }}"
type="checkbox"
value="{{ $torrent->id }}"
wire:model="checked"
value="1"
wire:model="checked.{{ $torrent->id }}"
/>
</td>
</tr>
Expand Down

0 comments on commit 1e6f47b

Please sign in to comment.