Skip to content

Commit eea99bf

Browse files
dotMavriQclaude
andcommitted
refactor: extract WithSourcePriority trait, delete dead view
- Extract duplicated moveSourceUp/moveSourceDown into shared WithSourcePriority trait used by all 3 MetadataEnrichment components - Delete unused book-import-fixed.blade.php Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a8a749a commit eea99bf

5 files changed

Lines changed: 31 additions & 346 deletions

File tree

app/Livewire/Anime/AnimeMetadataEnrichment.php

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
class AnimeMetadataEnrichment extends Component
1414
{
15+
use \App\Livewire\Concerns\WithSourcePriority;
1516
public array $sourcePriority = ['current', 'jikan'];
1617

1718
public array $animeNeedingEnrichment = [];
@@ -36,26 +37,6 @@ class AnimeMetadataEnrichment extends Component
3637

3738
protected const ENRICHABLE_FIELDS = ['description', 'poster_url', 'runtime_minutes', 'genres', 'studios', 'episodes_total', 'media_type', 'original_title'];
3839

39-
public function moveSourceUp(string $source): void
40-
{
41-
$index = array_search($source, $this->sourcePriority);
42-
if ($index > 0) {
43-
$temp = $this->sourcePriority[$index - 1];
44-
$this->sourcePriority[$index - 1] = $source;
45-
$this->sourcePriority[$index] = $temp;
46-
}
47-
}
48-
49-
public function moveSourceDown(string $source): void
50-
{
51-
$index = array_search($source, $this->sourcePriority);
52-
if ($index < count($this->sourcePriority) - 1) {
53-
$temp = $this->sourcePriority[$index + 1];
54-
$this->sourcePriority[$index + 1] = $source;
55-
$this->sourcePriority[$index] = $temp;
56-
}
57-
}
58-
5940
public function scanLibrary(): void
6041
{
6142
$this->isScanning = true;

app/Livewire/Books/MetadataEnrichment.php

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
class MetadataEnrichment extends Component
1515
{
16+
use \App\Livewire\Concerns\WithSourcePriority;
1617
// Source priority: sources listed in order of preference
1718
public array $sourcePriority = ['current', 'openlibrary'];
1819

@@ -59,26 +60,6 @@ public function clearJobStatus(): void
5960
$this->jobStatus = null;
6061
}
6162

62-
public function moveSourceUp(string $source): void
63-
{
64-
$index = array_search($source, $this->sourcePriority);
65-
if ($index > 0) {
66-
$temp = $this->sourcePriority[$index - 1];
67-
$this->sourcePriority[$index - 1] = $source;
68-
$this->sourcePriority[$index] = $temp;
69-
}
70-
}
71-
72-
public function moveSourceDown(string $source): void
73-
{
74-
$index = array_search($source, $this->sourcePriority);
75-
if ($index < count($this->sourcePriority) - 1) {
76-
$temp = $this->sourcePriority[$index + 1];
77-
$this->sourcePriority[$index + 1] = $source;
78-
$this->sourcePriority[$index] = $temp;
79-
}
80-
}
81-
8263
public function scanLibrary(): void
8364
{
8465
$this->isScanning = true;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Livewire\Concerns;
6+
7+
trait WithSourcePriority
8+
{
9+
public function moveSourceUp(string $source): void
10+
{
11+
$index = array_search($source, $this->sourcePriority);
12+
if ($index > 0) {
13+
$temp = $this->sourcePriority[$index - 1];
14+
$this->sourcePriority[$index - 1] = $source;
15+
$this->sourcePriority[$index] = $temp;
16+
}
17+
}
18+
19+
public function moveSourceDown(string $source): void
20+
{
21+
$index = array_search($source, $this->sourcePriority);
22+
if ($index < count($this->sourcePriority) - 1) {
23+
$temp = $this->sourcePriority[$index + 1];
24+
$this->sourcePriority[$index + 1] = $source;
25+
$this->sourcePriority[$index] = $temp;
26+
}
27+
}
28+
}

app/Livewire/Movies/MovieMetadataEnrichment.php

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
class MovieMetadataEnrichment extends Component
1717
{
18+
use \App\Livewire\Concerns\WithSourcePriority;
1819
public array $sourcePriority = ['current', 'trakt', 'tmdb'];
1920

2021
public array $moviesNeedingEnrichment = [];
@@ -61,26 +62,6 @@ public function clearJobStatus(): void
6162
$this->jobStatus = null;
6263
}
6364

64-
public function moveSourceUp(string $source): void
65-
{
66-
$index = array_search($source, $this->sourcePriority);
67-
if ($index > 0) {
68-
$temp = $this->sourcePriority[$index - 1];
69-
$this->sourcePriority[$index - 1] = $source;
70-
$this->sourcePriority[$index] = $temp;
71-
}
72-
}
73-
74-
public function moveSourceDown(string $source): void
75-
{
76-
$index = array_search($source, $this->sourcePriority);
77-
if ($index < count($this->sourcePriority) - 1) {
78-
$temp = $this->sourcePriority[$index + 1];
79-
$this->sourcePriority[$index + 1] = $source;
80-
$this->sourcePriority[$index] = $temp;
81-
}
82-
}
83-
8465
public function scanLibrary(): void
8566
{
8667
$this->isScanning = true;

0 commit comments

Comments
 (0)