ui: unify watchlist grid and fix client-side sorting
This commit is contained in:
@@ -35,14 +35,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="watchlist-items">
|
<div id="watchlist-items" class="grid grid-cols-2 gap-4 md:grid-cols-3 lg:grid-cols-4 2xl:grid-cols-6">
|
||||||
{{range $status := $.StatusOrder}}
|
{{range $.AllEntries}}
|
||||||
{{$entries := index $.WatchlistByStatus $status}}
|
<div class="watchlist-item flex w-full flex-col gap-2" data-status="{{.Status}}" data-created-at="{{.CreatedAt}}">
|
||||||
{{if $entries}}
|
|
||||||
<div class="watchlist-section" data-status="{{$status}}">
|
|
||||||
<div class="grid grid-cols-2 gap-4 md:grid-cols-3 lg:grid-cols-4 2xl:grid-cols-6">
|
|
||||||
{{range $entries}}
|
|
||||||
<div class="watchlist-item flex w-full flex-col gap-2" data-created-at="{{.CreatedAt}}">
|
|
||||||
<div class="group relative flex aspect-[2/3] w-full flex-col overflow-hidden bg-white/5 after:absolute after:inset-0 after:bg-black/80 after:opacity-0 hover:after:opacity-100 after:transition-opacity">
|
<div class="group relative flex aspect-[2/3] w-full flex-col overflow-hidden bg-white/5 after:absolute after:inset-0 after:bg-black/80 after:opacity-0 hover:after:opacity-100 after:transition-opacity">
|
||||||
<a href="/anime/{{.AnimeID}}" class="absolute inset-0"></a>
|
<a href="/anime/{{.AnimeID}}" class="absolute inset-0"></a>
|
||||||
<img src="{{.ImageUrl}}" alt="{{.DisplayTitle}}" class="h-full w-full object-cover" loading="lazy" />
|
<img src="{{.ImageUrl}}" alt="{{.DisplayTitle}}" class="h-full w-full object-cover" loading="lazy" />
|
||||||
@@ -60,13 +55,9 @@
|
|||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{if eq (len $.AllEntries) 0}}
|
{{if eq (len $.AllEntries) 0}}
|
||||||
<div class="flex flex-col items-center justify-center gap-2 py-24 text-neutral-400">
|
<div class="col-span-full flex flex-col items-center justify-center gap-2 py-24 text-neutral-400">
|
||||||
<svg class="h-12 w-12 opacity-30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path stroke-linecap="round" stroke-linejoin="round" d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10" /></svg>
|
<svg class="h-12 w-12 opacity-30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path stroke-linecap="round" stroke-linejoin="round" d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10" /></svg>
|
||||||
<p class="text-lg">Your watchlist is empty.</p>
|
<p class="text-lg">Your watchlist is empty.</p>
|
||||||
<a href="/" class="text-accent hover:text-accent/80 transition-colors">Browse anime</a>
|
<a href="/" class="text-accent hover:text-accent/80 transition-colors">Browse anime</a>
|
||||||
@@ -89,14 +80,14 @@
|
|||||||
btn.classList.remove('text-neutral-400')
|
btn.classList.remove('text-neutral-400')
|
||||||
btn.classList.add('text-white')
|
btn.classList.add('text-white')
|
||||||
|
|
||||||
// Show/hide sections
|
// Show/hide items
|
||||||
document.querySelectorAll('.watchlist-section').forEach(function(section) {
|
document.querySelectorAll('.watchlist-item').forEach(function(item) {
|
||||||
if (status === 'all') {
|
if (status === 'all') {
|
||||||
section.style.display = 'block'
|
item.style.display = 'flex'
|
||||||
} else if (section.dataset.status === status) {
|
} else if (item.dataset.status === status) {
|
||||||
section.style.display = 'block'
|
item.style.display = 'flex'
|
||||||
} else {
|
} else {
|
||||||
section.style.display = 'none'
|
item.style.display = 'none'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
sortItems()
|
sortItems()
|
||||||
@@ -129,15 +120,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sortItems() {
|
function sortItems() {
|
||||||
document.querySelectorAll('.watchlist-section').forEach(function(section) {
|
const grid = document.getElementById('watchlist-items')
|
||||||
const grid = section.querySelector('.grid')
|
const items = Array.from(grid.querySelectorAll('.watchlist-item'))
|
||||||
const items = Array.from(grid.children)
|
|
||||||
|
|
||||||
items.sort(function(a, b) {
|
items.sort(function(a, b) {
|
||||||
let comparison = 0
|
let comparison = 0
|
||||||
if (currentSortBy === 'title') {
|
if (currentSortBy === 'title') {
|
||||||
const titleA = a.querySelector('h3').textContent.toLowerCase()
|
const titleA = a.querySelector('h3').textContent.toLowerCase().trim()
|
||||||
const titleB = b.querySelector('h3').textContent.toLowerCase()
|
const titleB = b.querySelector('h3').textContent.toLowerCase().trim()
|
||||||
comparison = titleA.localeCompare(titleB)
|
comparison = titleA.localeCompare(titleB)
|
||||||
} else {
|
} else {
|
||||||
const dateA = new Date(a.dataset.createdAt || 0).getTime()
|
const dateA = new Date(a.dataset.createdAt || 0).getTime()
|
||||||
@@ -150,7 +140,6 @@
|
|||||||
items.forEach(function(item) {
|
items.forEach(function(item) {
|
||||||
grid.appendChild(item)
|
grid.appendChild(item)
|
||||||
})
|
})
|
||||||
})
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|||||||
Reference in New Issue
Block a user