Release / build-and-push (push) Successful in 3m15s
Unidentified sync files used to be stuck: every KOReader re-sync re-queues them, and there was no way to say "this isn't a book" or "I don't want this one on the server". Ignore is the durable dismiss: a new ignored_at column hides the row from the page list, dashboard badge, and per-device API while the sync keeps refreshing its metadata (the upsert never clears the column). A collapsible "Ignored" section lists dismissed rows with Restore and Delete so a misclick is recoverable. Delete is the hard exit — the row is gone, and honestly re-queued if the device syncs that file again (the confirm dialog says so). Actions are page-scoped SSR routes: htmx swaps in the re-rendered section so counts and buckets can never drift from the DB; ownership is row → device → user (admins may act on any row). Integration tests pin the lifecycle (hide everywhere, survive the sync upsert, restore, delete), foreign-user 403s, and the render surface.
336 lines
13 KiB
Templ
336 lines
13 KiB
Templ
package templates
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"bookhoard/internal/services"
|
|
)
|
|
|
|
|
|
// UnlinkedMatchCards renders the match candidates for one device file's
|
|
// "find matches" reveal — the /unlinked-books/matches partial response.
|
|
// Cards are clicked through the delegated data-action handler (rendering
|
|
// ownership: templ renders, JS only swaps and handles the click).
|
|
templ UnlinkedMatchCards(progressId string, matches []services.BookMatch) {
|
|
if len(matches) == 0 {
|
|
<p class="text-sm text-center p-4" style="color: var(--text-secondary)">No matches found. Try manual linking.</p>
|
|
} else {
|
|
for _, match := range matches {
|
|
<div class="card p-4 rounded-lg border cursor-pointer hover:shadow-lg transition-shadow"
|
|
style="background-color: var(--bg-primary); border-color: var(--border);"
|
|
data-action="auto-link"
|
|
data-progress-id={ progressId }
|
|
data-media-item-id={ match.MediaItemID.String() }
|
|
data-confidence={ fmt.Sprintf("%v", match.Confidence) }
|
|
>
|
|
<div class="flex gap-4">
|
|
<img
|
|
src={ match.CoverImagePath }
|
|
alt="Cover"
|
|
class="w-16 h-24 object-cover rounded"
|
|
|
|
/>
|
|
<div>
|
|
<h5 class="font-semibold" style="color: var(--text-primary)">{ match.Title }</h5>
|
|
if match.Author != "" {
|
|
<p class="text-sm" style="color: var(--text-secondary)">by { match.Author }</p>
|
|
}
|
|
<div class="mt-2 flex items-center gap-2">
|
|
<span class="text-xs px-2 py-1 rounded" style="background-color: var(--accent); color: var(--bg-primary);">
|
|
{ fmt.Sprintf("%.0f%% confidence", match.Confidence*100) }
|
|
</span>
|
|
<span class="text-xs" style="color: var(--text-secondary)">{ match.MatchMethod }</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
}
|
|
}
|
|
|
|
templ UnlinkedBooks(user User, unresolved []UnlinkedBookData, ignored []UnlinkedBookData) {
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
|
<title>Unlinked Books - Bookhoard</title>
|
|
<script src="/static/htmx.min.js"></script>
|
|
<link href="/static/style.css" rel="stylesheet"/>
|
|
<link rel="icon" type="image/svg+xml" href="/static/favicon.svg"/>
|
|
</head>
|
|
<body class={ "theme-" + user.Theme } x-data="unlinkedBooks" x-init="setupEventDelegation()">
|
|
@Header(user, "/unlinked")
|
|
<main class="mx-auto container px-4 sm:px-6 lg:px-8 py-8">
|
|
@UnlinkedBooksSection(unresolved, ignored)
|
|
</main>
|
|
@unlinkedManualLinkModal()
|
|
</body>
|
|
</html>
|
|
}
|
|
|
|
// UnlinkedBooksSection is the whole actionable page body: toolbar, the
|
|
// unresolved queue, and the collapsed ignored bucket. Every dismiss/
|
|
// delete/restore action re-renders this partial server-side (htmx
|
|
// hx-target="#unlinked-section" outerHTML) so counts and buckets can
|
|
// never drift from the database after an action.
|
|
templ UnlinkedBooksSection(unresolved []UnlinkedBookData, ignored []UnlinkedBookData) {
|
|
<div id="unlinked-section">
|
|
<div class="mb-8">
|
|
<div class="flex items-center gap-3 mb-1">
|
|
<span class="grid place-items-center h-10 w-10 rounded-xl" style="background-color: var(--accent-muted); color: var(--accent);">
|
|
@Icon("sync", "h-5 w-5")
|
|
</span>
|
|
<h1 class="text-2xl font-bold tracking-tight" style="color: var(--text-primary)">Unlinked Books</h1>
|
|
</div>
|
|
<p class="text-sm" style="color: var(--text-secondary)">Resolve books that couldn't be automatically matched between devices</p>
|
|
</div>
|
|
if len(unresolved) > 0 {
|
|
<div class="card p-4 mb-6 flex flex-wrap justify-between items-center gap-3">
|
|
<div class="flex items-center gap-4">
|
|
<input type="checkbox" id="select-all-unlinked" @change="toggleAllUnlinked()" class="w-5 h-5"/>
|
|
<label for="select-all-unlinked" class="cursor-pointer text-sm font-medium" style="color: var(--text-primary)">Select All</label>
|
|
<span id="selected-count" class="text-sm" style="color: var(--text-secondary)">0 selected</span>
|
|
</div>
|
|
<div class="flex gap-2 flex-wrap">
|
|
<button @click="bulkAutoLink()" class="btn btn-secondary text-sm">
|
|
@Icon("sync", "h-4 w-4")
|
|
Auto-Link Selected (High Confidence)
|
|
</button>
|
|
<button @click="bulkGetSuggestions()" class="btn btn-secondary text-sm">
|
|
@Icon("search", "h-4 w-4")
|
|
Get Suggestions for Selected
|
|
</button>
|
|
<button @click="showBulkManualLink()" class="btn btn-primary text-sm">
|
|
@Icon("edit", "h-4 w-4")
|
|
Bulk Manual Link
|
|
</button>
|
|
</div>
|
|
</div>
|
|
}
|
|
<div id="unlinked-container" class="space-y-6">
|
|
if len(unresolved) == 0 {
|
|
<div class="card text-center py-16">
|
|
<span class="grid place-items-center h-14 w-14 mx-auto mb-4 rounded-2xl" style="background-color: color-mix(in srgb, var(--status-success) 16%, transparent); color: var(--status-success);">
|
|
@Icon("check-circle", "h-7 w-7")
|
|
</span>
|
|
<h3 class="text-xl font-semibold mb-2" style="color: var(--text-primary)">All Books Linked!</h3>
|
|
<p style="color: var(--text-secondary)">There are no unlinked books that need manual resolution.</p>
|
|
</div>
|
|
}
|
|
for _, book := range unresolved {
|
|
@unlinkedBookCard(book, false)
|
|
}
|
|
</div>
|
|
if len(ignored) > 0 {
|
|
<details class="mt-8">
|
|
<summary class="cursor-pointer text-sm font-medium mb-3 select-none" style="color: var(--text-secondary)">
|
|
Ignored ({ fmt.Sprintf("%d", len(ignored)) }) — hidden from the queue and the dashboard badge
|
|
</summary>
|
|
<div class="space-y-6">
|
|
for _, book := range ignored {
|
|
@unlinkedBookCard(book, true)
|
|
}
|
|
</div>
|
|
</details>
|
|
}
|
|
</div>
|
|
}
|
|
|
|
// unlinkedBookCard renders one queue row. Ignored rows drop the checkbox
|
|
// and the match/link actions (they are dismissed) and offer Restore +
|
|
// Delete instead; all action buttons re-render the section server-side.
|
|
templ unlinkedBookCard(book UnlinkedBookData, ignored bool) {
|
|
<div class="card p-6">
|
|
<div class="flex gap-6">
|
|
if !ignored {
|
|
<div class="flex items-start pt-2">
|
|
<input type="checkbox" class="unlinked-checkbox w-5 h-5" data-progress-id={ book.ProgressID } data-title={ book.TitleFromDevice }/>
|
|
</div>
|
|
}
|
|
<div class="flex-1 min-w-0">
|
|
<div class="flex items-center gap-3 mb-4">
|
|
<span class="grid place-items-center h-11 w-11 rounded-xl shrink-0" style="background-color: var(--accent-muted); color: var(--accent);">
|
|
if book.DeviceType == "koreader" {
|
|
@Icon("book-open", "h-5 w-5")
|
|
} else if book.DeviceType == "kobo" {
|
|
@Icon("library", "h-5 w-5")
|
|
} else {
|
|
@Icon("device", "h-5 w-5")
|
|
}
|
|
</span>
|
|
<div class="min-w-0">
|
|
<h3 class="font-semibold text-lg truncate" style="color: var(--text-primary)">{ book.TitleFromDevice }</h3>
|
|
<p class="text-sm" style="color: var(--text-secondary)">
|
|
Device: { book.DeviceName } ({ book.DeviceType })
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<div class="space-y-2 text-sm mb-4">
|
|
<div class="flex items-center gap-2 flex-wrap">
|
|
<span class="text-xs uppercase tracking-wide font-medium" style="color: var(--text-secondary)">File Path:</span>
|
|
<code class="chip font-mono">
|
|
@Icon("folder", "h-3.5 w-3.5")
|
|
{ book.FilePath }
|
|
</code>
|
|
</div>
|
|
if book.SHA256 != "" {
|
|
<div class="flex items-center gap-2 flex-wrap">
|
|
<span class="text-xs uppercase tracking-wide font-medium" style="color: var(--text-secondary)">SHA-256:</span>
|
|
<code class="chip font-mono text-xs" title={ book.SHA256 }>{ book.SHA256 }</code>
|
|
</div>
|
|
}
|
|
<div class="flex items-center gap-2">
|
|
<span class="text-xs uppercase tracking-wide font-medium" style="color: var(--text-secondary)">Last Synced:</span>
|
|
<span style="color: var(--text-primary)">{ book.LastSyncTime }</span>
|
|
</div>
|
|
if book.ConfidenceScore > 0 {
|
|
<div class="flex items-center gap-2">
|
|
<span class="text-xs uppercase tracking-wide font-medium" style="color: var(--text-secondary)">Auto-Link Confidence:</span>
|
|
<span class="badge" style="background-color: var(--accent-muted); color: var(--accent);">
|
|
{ book.ConfidenceScore }% confidence
|
|
</span>
|
|
</div>
|
|
}
|
|
</div>
|
|
if ignored {
|
|
<div class="mb-4 flex gap-2 flex-wrap">
|
|
<button
|
|
hx-post={ "/unlinked-books/" + book.ProgressID + "/unignore" }
|
|
hx-target="#unlinked-section"
|
|
hx-swap="outerHTML"
|
|
class="btn btn-secondary text-sm"
|
|
>
|
|
@Icon("check", "h-4 w-4")
|
|
Restore
|
|
</button>
|
|
<button
|
|
hx-delete={ "/unlinked-books/" + book.ProgressID }
|
|
hx-confirm="Delete this ignored entry permanently?"
|
|
hx-target="#unlinked-section"
|
|
hx-swap="outerHTML"
|
|
class="btn btn-secondary text-sm"
|
|
>
|
|
@Icon("close", "h-4 w-4")
|
|
Delete
|
|
</button>
|
|
</div>
|
|
} else {
|
|
<div class="mb-4 flex gap-2 flex-wrap">
|
|
<button
|
|
@click={ "searchMatches(" + JSONArg(book.ProgressID) + ", " + JSONArg(book.SHA256) + ", " + JSONArg(book.TitleFromDevice) + ")" }
|
|
class="btn btn-secondary text-sm"
|
|
>
|
|
@Icon("search", "h-4 w-4")
|
|
Find Potential Matches
|
|
</button>
|
|
<button
|
|
@click={ "showManualLinkModal(" + JSONArg(book.ProgressID) + ", " + JSONArg(book.TitleFromDevice) + ")" }
|
|
class="btn btn-primary text-sm"
|
|
>
|
|
@Icon("edit", "h-4 w-4")
|
|
Manually Link
|
|
</button>
|
|
<button
|
|
hx-post={ "/unlinked-books/" + book.ProgressID + "/ignore" }
|
|
hx-target="#unlinked-section"
|
|
hx-swap="outerHTML"
|
|
class="btn btn-secondary text-sm"
|
|
>
|
|
@Icon("close", "h-4 w-4")
|
|
Ignore
|
|
</button>
|
|
<button
|
|
hx-delete={ "/unlinked-books/" + book.ProgressID }
|
|
hx-confirm="Delete this entry? If the device syncs this file again, it will reappear here."
|
|
hx-target="#unlinked-section"
|
|
hx-swap="outerHTML"
|
|
class="btn btn-secondary text-sm"
|
|
>
|
|
@Icon("close", "h-4 w-4")
|
|
Delete
|
|
</button>
|
|
</div>
|
|
<div id={ "matches-" + book.ProgressID } class="hidden">
|
|
<div class="border-t pt-4 mt-2" style="border-color: var(--border);">
|
|
<h4 class="font-semibold mb-3" style="color: var(--text-primary)">Potential Matches</h4>
|
|
<div id={ "matches-list-" + book.ProgressID } class="space-y-3">
|
|
<p style="color: var(--text-secondary)">Click "Find Potential Matches" to search</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
|
|
// unlinkedManualLinkModal holds the manual-link dialog markup (unchanged
|
|
// behavior; extracted so the section partial can be re-rendered on its own).
|
|
templ unlinkedManualLinkModal() {
|
|
<div id="manual-link-modal" class="hidden fixed inset-0 z-50 flex items-center justify-center p-4" style="background-color: var(--surface-overlay);">
|
|
<div class="card p-6 w-full max-w-md mx-4">
|
|
<div class="flex justify-between items-center mb-6">
|
|
<h2 class="text-xl font-bold" style="color: var(--text-primary)">Manually Link Book</h2>
|
|
<button @click="hideManualLinkModal()" class="icon-btn" aria-label="Close">@Icon("close", "h-5 w-5")</button>
|
|
</div>
|
|
<input type="hidden" id="link-progress-id"/>
|
|
<input type="hidden" id="link-book-sha256"/>
|
|
<div class="mb-4">
|
|
<label for="link-book-title" class="block text-xs uppercase tracking-wide font-medium mb-2" style="color: var(--text-secondary)">Book Title from Device</label>
|
|
<input
|
|
type="text"
|
|
id="link-book-title"
|
|
readonly
|
|
class="input"
|
|
style="color: var(--text-secondary);"
|
|
/>
|
|
</div>
|
|
<div class="mb-4">
|
|
<label for="link-search-input" class="block text-xs uppercase tracking-wide font-medium mb-2" style="color: var(--text-secondary)">Search for Book to Link</label>
|
|
<div class="flex gap-2">
|
|
<input
|
|
type="text"
|
|
id="link-search-input"
|
|
placeholder="Search by title, author…"
|
|
class="input flex-1"
|
|
/>
|
|
<button
|
|
type="button"
|
|
@click="searchBooksForLink()"
|
|
class="btn btn-primary"
|
|
>
|
|
@Icon("search", "h-4 w-4")
|
|
Search
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<div id="link-search-results" class="mb-4 max-h-48 overflow-y-auto space-y-2">
|
|
<p class="text-sm" style="color: var(--text-secondary)">Search for books to link</p>
|
|
</div>
|
|
<div class="mb-4">
|
|
<label for="link-confidence" class="block text-xs uppercase tracking-wide font-medium mb-2" style="color: var(--text-secondary)">Confidence Score</label>
|
|
<input
|
|
type="number"
|
|
id="link-confidence"
|
|
min="0"
|
|
max="1"
|
|
step="0.1"
|
|
value="1.0"
|
|
class="input"
|
|
/>
|
|
<p class="text-xs mt-1" style="color: var(--text-secondary)">1.0 = manual override (highest confidence)</p>
|
|
</div>
|
|
<div class="flex justify-end gap-3">
|
|
<button type="button" @click="hideManualLinkModal()" class="btn btn-secondary">
|
|
Cancel
|
|
</button>
|
|
<button type="button" @click="confirmManualLink()" class="btn btn-primary">
|
|
@Icon("check", "h-4 w-4")
|
|
Link Book
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|