Skip to content

Commit 1cc8606

Browse files
committed
fix: rename date_recorded back to date_finished for books
date_recorded was a confusing name - it's the date you finished reading the book, not when it was recorded. Rename to date_finished to match comics and anime. Clear bogus finish dates on unread books and move the original shelf-added timestamps into date_added where they belong. Sort options now hide Date Finished and Date Started when they don't apply to the current status filter.
1 parent 6f67918 commit 1cc8606

7 files changed

Lines changed: 51 additions & 12 deletions

File tree

app/Livewire/Books/BookIndex.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private function applyAccentInsensitiveSearch($query, string $search, array $col
4545

4646
public bool $selectAll = false;
4747

48-
private const ALLOWED_SORT_COLUMNS = ['title', 'author', 'rating', 'page_count', 'date_finished', 'updated_at', 'date_started', 'date_recorded'];
48+
private const ALLOWED_SORT_COLUMNS = ['title', 'author', 'rating', 'page_count', 'date_finished', 'date_added', 'updated_at', 'date_started'];
4949

5050
protected $queryString = [
5151
'search' => ['except' => ''],
@@ -61,8 +61,15 @@ public function updatingSearch(): void
6161
$this->resetPage();
6262
}
6363

64-
public function updatingStatus(): void
64+
public function updatingStatus(string $value): void
6565
{
66+
// Reset sort if it no longer applies to the new status
67+
if ($value === 'want_to_read' && in_array($this->sortBy, ['date_finished', 'date_started'])) {
68+
$this->sortBy = 'date_added';
69+
} elseif ($value === 'reading' && $this->sortBy === 'date_finished') {
70+
$this->sortBy = 'date_started';
71+
}
72+
6673
$this->resetPage();
6774
}
6875

app/Livewire/Dashboard.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function getReadingStats(): array
5959
$bookStats = $user->books()
6060
->selectRaw("COUNT(*) as total")
6161
->selectRaw("SUM(CASE WHEN status = ? THEN 1 ELSE 0 END) as currently_reading", [ReadingStatus::Reading->value])
62-
->selectRaw("SUM(CASE WHEN status = ? AND " . sprintf($yearSql, 'date_recorded') . " = ? THEN 1 ELSE 0 END) as read_this_year", [ReadingStatus::Read->value, (string) $year])
62+
->selectRaw("SUM(CASE WHEN status = ? AND " . sprintf($yearSql, 'date_finished') . " = ? THEN 1 ELSE 0 END) as read_this_year", [ReadingStatus::Read->value, (string) $year])
6363
->first();
6464

6565
$comicStats = $user->comics()

app/Models/Book.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Book extends Model
3737
'date_pub',
3838
'date_pub_edition',
3939
'date_started',
40-
'date_recorded',
40+
'date_finished',
4141
'date_added',
4242
'shelves',
4343
'notes',
@@ -61,7 +61,7 @@ protected function casts(): array
6161
'owned' => 'boolean',
6262
'published_date' => 'date',
6363
'date_started' => 'date',
64-
'date_recorded' => 'date',
64+
'date_finished' => 'date',
6565
'date_added' => 'date',
6666
];
6767
}

app/Services/GoodReadsImportService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected function mapRowToBook(array $row): array
5555
'status' => $this->mapShelfToStatus($row['Exclusive Shelf'] ?? $row['Shelves'] ?? ''),
5656
'rating' => $this->parseRating($row['My Rating'] ?? ''),
5757
'date_started' => $this->parseDate($row['Date Started'] ?? ''),
58-
'date_recorded' => $this->parseDate($row['Date Read'] ?? ''),
58+
'date_finished' => $this->parseDate($row['Date Read'] ?? ''),
5959
'notes' => $row['My Review'] ?? $row['Review'] ?? null,
6060
'cover_url' => null,
6161
];
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\DB;
6+
use Illuminate\Support\Facades\Schema;
7+
8+
return new class extends Migration
9+
{
10+
public function up(): void
11+
{
12+
// Clear dates for books that aren't "read" -- these are just Goodreads shelf timestamps
13+
DB::table('books')
14+
->whereNot('status', 'read')
15+
->update(['date_recorded' => null]);
16+
17+
Schema::table('books', function (Blueprint $table) {
18+
$table->renameColumn('date_recorded', 'date_finished');
19+
});
20+
}
21+
22+
public function down(): void
23+
{
24+
Schema::table('books', function (Blueprint $table) {
25+
$table->renameColumn('date_finished', 'date_recorded');
26+
});
27+
}
28+
};

resources/views/livewire/books/book-index.blade.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,13 @@ class="rounded-md border-0 py-1.5 pl-3 pr-8 text-sm text-theme-text-primary ring
109109
</optgroup>
110110
<optgroup label="Your Data">
111111
<option value="rating">Your Rating</option>
112-
<option value="date_recorded">Added to Library</option>
113-
<option value="date_started">Date Started</option>
114-
<option value="created_at">Date Added</option>
112+
@if(in_array($status, ['read', 'reading', '']))
113+
<option value="date_started">Date Started</option>
114+
@endif
115+
@if(in_array($status, ['read', '']))
116+
<option value="date_finished">Date Finished</option>
117+
@endif
118+
<option value="date_added">Added to Library</option>
115119
<option value="updated_at">Recently Updated</option>
116120
</optgroup>
117121
</select>

resources/views/livewire/books/book-show.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,10 @@ class="btn-danger inline-flex items-center rounded-md px-3 py-2 text-sm font-sem
211211
</div>
212212
@endif
213213

214-
@if($book->date_recorded ?? $book->date_added)
214+
@if($book->date_finished)
215215
<div>
216-
<dt class="text-sm font-medium text-theme-text-secondary">Added to Library</dt>
217-
<dd class="mt-1 text-sm text-theme-text-primary">{{ ($book->date_recorded ?? $book->date_added)->format('F j, Y') }}</dd>
216+
<dt class="text-sm font-medium text-theme-text-secondary">Date Finished</dt>
217+
<dd class="mt-1 text-sm text-theme-text-primary">{{ $book->date_finished->format('F j, Y') }}</dd>
218218
</div>
219219
@endif
220220

0 commit comments

Comments
 (0)