Files
mal/internal/templates/watchlist.templ

123 lines
4.4 KiB
Plaintext

package templates
import (
"fmt"
"malago/internal/database"
)
templ Watchlist(entries []database.GetUserWatchListRow, layout string, currentStatus string) {
@Layout("My Watchlist") {
<div class="watchlist-header">
<h2>watchlist</h2>
<div class="watchlist-controls">
<a href="/api/watchlist/export" class="text-link">export</a>
<button class="text-link" onclick="document.getElementById('import-file').click()">import</button>
<form id="import-form" hx-post="/api/watchlist/import" hx-encoding="multipart/form-data" style="display: none;">
<input type="file" id="import-file" name="file" accept=".json" onchange="htmx.trigger('#import-form', 'submit')" />
</form>
<div class="view-toggle">
<a href={ templ.URL(fmt.Sprintf("/watchlist?view=grid&status=%s", currentStatus)) } class={ viewClass(layout == "grid") }>grid</a>
<a href={ templ.URL(fmt.Sprintf("/watchlist?view=table&status=%s", currentStatus)) } class={ viewClass(layout == "table") }>table</a>
</div>
</div>
</div>
<div class="status-tabs">
<a href={ templ.URL(fmt.Sprintf("/watchlist?view=%s&status=all", layout)) } class={ tabClass(currentStatus == "all") }>all</a>
<a href={ templ.URL(fmt.Sprintf("/watchlist?view=%s&status=watching", layout)) } class={ tabClass(currentStatus == "watching") }>watching</a>
<a href={ templ.URL(fmt.Sprintf("/watchlist?view=%s&status=on_hold", layout)) } class={ tabClass(currentStatus == "on_hold") }>on hold</a>
<a href={ templ.URL(fmt.Sprintf("/watchlist?view=%s&status=plan_to_watch", layout)) } class={ tabClass(currentStatus == "plan_to_watch") }>plan to watch</a>
<a href={ templ.URL(fmt.Sprintf("/watchlist?view=%s&status=dropped", layout)) } class={ tabClass(currentStatus == "dropped") }>dropped</a>
<a href={ templ.URL(fmt.Sprintf("/watchlist?view=%s&status=completed", layout)) } class={ tabClass(currentStatus == "completed") }>completed</a>
</div>
if len(entries) == 0 {
<div class="empty-state">
<div class="empty-state-title">nothing here yet</div>
<div class="empty-state-text">
if currentStatus == "all" {
your watchlist is empty. <a href="/">search for anime</a> to get started.
} else {
no anime in this category.
}
</div>
</div>
} else {
if layout == "grid" {
<div class="catalog-grid">
for _, entry := range entries {
<div class="catalog-item watchlist-item" id={ fmt.Sprintf("watchlist-entry-%d", entry.AnimeID) }>
<a href={ templ.URL(fmt.Sprintf("/anime/%d", entry.AnimeID)) }>
if entry.ImageUrl != "" {
<img src={ entry.ImageUrl } alt={ entry.Title } class="catalog-thumb" loading="lazy" />
} else {
<div class="no-image">no image</div>
}
</a>
<div class="catalog-title">{ entry.Title }</div>
<div class="watchlist-status">{ entry.Status }</div>
<button
class="remove-btn"
hx-delete={ string(templ.URL(fmt.Sprintf("/api/watchlist/%d?from=watchlist", entry.AnimeID))) }
hx-target={ fmt.Sprintf("#watchlist-entry-%d", entry.AnimeID) }
hx-swap="delete"
>&times;</button>
</div>
}
</div>
} else {
<table class="watchlist-table">
<thead>
<tr>
<th></th>
<th>title</th>
<th>status</th>
<th></th>
</tr>
</thead>
<tbody>
for _, entry := range entries {
<tr id={ fmt.Sprintf("watchlist-entry-%d", entry.AnimeID) }>
<td>
<a href={ templ.SafeURL(fmt.Sprintf("/anime/%d", entry.AnimeID)) }>
<img src={ entry.ImageUrl } alt={ entry.Title } class="thumb" loading="lazy"/>
</a>
</td>
<td class="title-cell">
<a href={ templ.SafeURL(fmt.Sprintf("/anime/%d", entry.AnimeID)) }>
{ entry.Title }
</a>
</td>
<td class="status-cell">{ entry.Status }</td>
<td class="actions-cell">
<button
class="remove-link"
hx-delete={ string(templ.URL(fmt.Sprintf("/api/watchlist/%d?from=watchlist", entry.AnimeID))) }
hx-target={ fmt.Sprintf("#watchlist-entry-%d", entry.AnimeID) }
hx-swap="delete"
style="background: none; border: none; cursor: pointer;"
>remove</button>
</td>
</tr>
}
</tbody>
</table>
}
}
}
}
func viewClass(active bool) string {
if active {
return "active"
}
return ""
}
func tabClass(active bool) string {
if active {
return "active"
}
return ""
}