Files
bookhoard/templates/dashboard.templ
T
john-okeefe 28e40e302c feat(ui): rebuild shared chrome and core browse/read pages
- Header: sticky app-wide, active nav highlighting, data-driven theme
  picker with active swatch, unified SVG icons, deduped login fragment
  (was duplicated verbatim for desktop + mobile), removed stray console.log
- LibrarySwitcher: cleaner sticky bar, SVG action icons, theme-aware
- BookCard: the atomic unit now has a real surface (was floating text
  when wood-paneling was off due to an undefined --wood-border), with
  cohesive shadow + hover lift; reused across dashboard/bookshelf/series
- Dashboard: calmer section headers, snap carousels with SVG chevrons
- Bookshelf: recompose the filter wall into a search toolbar + collapsible
  Filters panel (all 9 filters + save/load/clear preserved), redesigned
  empty state and pagination
- Book detail, series, collections, browse: cohesive cards, SVG action
  icons, uppercase muted labels, theme-aware badges/links
2026-08-05 16:01:09 -04:00

223 lines
8.2 KiB
Templ

package templates
import (
"bookhoard/internal/handlers"
"fmt"
)
templ Dashboard(user User, sections []handlers.SectionData, allSections []handlers.SectionData, libData []LibraryData, currentLibraryID string, hiddenCollections []string, itemsPerSection int, errorMessage string) {
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Dashboard - Bookhoard</title>
<script src="/static/htmx.min.js"></script>
<link href="/static/style.css" rel="stylesheet"/>
</head>
<body x-data="dashboard" x-init="initDashboard()" class="theme-{ user.Theme }">
@Header(user, "/dashboard")
@LibrarySwitcher(libData, currentLibraryID, DashboardActions())
<main id="collections-container" class="w-full px-4 sm:px-6 lg:px-8 py-8">
if len(sections) == 0 {
<div class="card mx-auto max-w-md p-10 text-center">
<div class="mx-auto mb-4 flex h-14 w-14 items-center justify-center rounded-full bg-brand/15 text-brand">
@Icon("book-open", "h-7 w-7")
</div>
<h2 class="text-lg font-semibold text-content">Your library is empty</h2>
<p class="mt-1 text-sm text-content-muted">Once books are added to your libraries, collections will appear here.</p>
</div>
} else {
<div class="space-y-10">
for _, section := range sections {
@CollectionCarousel(section)
}
</div>
}
</main>
@DashboardSettingsModal(allSections, hiddenCollections, itemsPerSection)
@ErrorToast(errorMessage)
</body>
</html>
}
templ CollectionCarousel(section handlers.SectionData) {
<section
class="dashboard-collection"
data-collection-id={ section.ID }
data-is-system={ section.IsSystem }
>
<div class="mb-4 flex items-end justify-between gap-4">
<div class="min-w-0">
<h2 class="flex items-center gap-2 text-lg font-bold tracking-tight text-content">
if section.Icon != "" {
<span class="text-base">{ section.Icon }</span>
}
{ section.Title }
</h2>
if section.Description != "" {
<p class="mt-0.5 text-sm text-content-muted">{ section.Description }</p>
}
</div>
if section.ViewAllURL != "" {
<a href={ section.ViewAllURL } class="flex items-center gap-1 text-sm font-medium text-content-muted transition-colors hover:text-brand">
View All
@Icon("arrow-right", "h-4 w-4")
</a>
}
</div>
<div class="carousel-container relative group">
<button
class="carousel-nav-left absolute left-0 top-0 z-10 flex h-full w-12 items-center justify-start bg-gradient-to-r from-surface to-transparent opacity-0 transition-opacity duration-200 group-hover:opacity-100 focus-visible:opacity-100"
data-action="scroll-carousel"
data-collection-id={ section.ID }
data-direction="-1"
aria-label="Scroll left"
>
@Icon("chevron-left", "h-6 w-6 text-content")
</button>
<div
id={ "carousel-track-" + section.ID }
class="carousel-track flex gap-4 overflow-x-auto scroll-smooth snap-x snap-mandatory px-6 pb-2"
style="scrollbar-width: none; -ms-overflow-style: none;"
>
for _, item := range section.Items {
@BookCard(item)
}
if len(section.Items) == 0 {
<div class="w-full py-10 text-center text-sm text-content-muted">
No items in this collection
</div>
}
</div>
<button
class="carousel-nav-right absolute right-0 top-0 z-10 flex h-full w-12 items-center justify-end bg-gradient-to-l from-surface to-transparent opacity-0 transition-opacity duration-200 group-hover:opacity-100 focus-visible:opacity-100"
data-action="scroll-carousel"
data-collection-id={ section.ID }
data-direction="1"
aria-label="Scroll right"
>
@Icon("chevron-right", "h-6 w-6 text-content")
</button>
</div>
</section>
}
// BookCard is the single, canonical cover-forward card used across the
// dashboard, bookshelf, series and collections. The metadata block sits on a
// real surface so cards always read as cohesive objects (previously the text
// floated with no background when wood-paneling was off).
templ BookCard(item handlers.BookInfo) {
<a href={ "/media/" + item.MediaItemID } title={ item.Title } class="block w-36 flex-shrink-0 snap-start">
<div class="book-card" tabindex="0" role="button" aria-label={ "View " + item.Title }>
<div class="aspect-[2/3] overflow-hidden bg-surface-hover">
if item.CoverImagePath != "" {
<img
src={ item.CoverImagePath }
alt={ item.Title }
class="h-full w-full object-cover"
loading="lazy"
onerror="this.src='/static/placeholder-book.svg'"
/>
} else {
<img src="/static/placeholder-book.svg" alt={ item.Title } class="h-full w-full object-cover"/>
}
</div>
<div class="book-card-meta">
<h3 class="line-clamp-2 text-sm font-semibold leading-snug text-content" title={ item.Title }>{ item.Title }</h3>
if item.Author != "" {
<p class="mt-0.5 line-clamp-1 text-xs text-content-muted" title={ item.Author }>{ item.Author }</p>
}
</div>
</div>
</a>
}
templ DashboardSettingsModal(sections []handlers.SectionData, hiddenCollections []string, itemsPerSection int) {
<div
id="dashboard-settings-modal"
class="hidden fixed inset-0 z-50 flex items-center justify-center p-4"
style="background-color: var(--surface-overlay);"
>
<div class="card w-full max-w-2xl p-6">
<div class="mb-6 flex items-center justify-between">
<div>
<h2 class="text-lg font-bold text-content">Customize Dashboard</h2>
<p class="mt-0.5 text-sm text-content-muted">Drag to reorder, toggle to show or hide.</p>
</div>
<button data-action="close-dashboard-settings" class="icon-btn" aria-label="Close">
@Icon("close", "h-5 w-5")
</button>
</div>
<div id="collection-list" class="mb-6 space-y-2">
for _, section := range sections {
<div
class="flex items-center justify-between gap-3 rounded-xl border border-line bg-surface px-3 py-2.5 cursor-move select-none"
data-collection-id={ section.ID }
data-is-system={ fmt.Sprintf("%v", section.IsSystem) }
draggable="true"
>
<div class="flex items-center gap-3 min-w-0">
@Icon("grip", "h-4 w-4 text-content-muted")
if section.Icon != "" {
<span class="text-base">{ section.Icon }</span>
}
<div class="min-w-0">
<span class="block truncate text-sm font-medium text-content">{ section.Title }</span>
</div>
if section.IsSystem {
<span class="badge bg-brand/15 text-brand">System</span>
}
</div>
<div class="flex items-center gap-3">
if section.IsSystem {
<button
data-action="restore-system-collection"
data-collection-name={ section.ID }
class="btn btn-ghost px-2 py-1 text-xs"
title="Restore"
>
Restore
</button>
}
<label class="relative inline-flex cursor-pointer items-center">
<input
type="checkbox"
class="peer sr-only"
if !ContainsString(hiddenCollections, section.ID) {
checked
}
/>
<div class="h-6 w-11 rounded-full bg-surface-hover transition-colors after:absolute after:left-[2px] after:top-[2px] after:h-5 after:w-5 after:rounded-full after:bg-content-muted after:transition-all peer-checked:bg-brand peer-checked:after:translate-x-full peer-checked:after:bg-white peer-focus-visible:ring-2 peer-focus-visible:ring-brand/50"></div>
</label>
</div>
</div>
}
</div>
<div class="mb-6">
<label class="mb-2 block text-sm font-medium text-content-muted">
Items per Collection: <span id="items-count-display" class="font-bold text-content">{ itemsPerSection }</span>
</label>
<input
type="range"
min="10"
max="50"
step="5"
value={ itemsPerSection }
class="h-2 w-full cursor-pointer appearance-none rounded-full bg-surface-hover"
data-input-action="update-items-count"
target="items-count-display"
/>
</div>
<div class="flex justify-end gap-3">
<button data-action="close-dashboard-settings" class="btn btn-secondary">Cancel</button>
<button data-action="save-dashboard-settings" class="btn btn-primary">Save Changes</button>
</div>
</div>
</div>
}