201 lines
7.6 KiB
Plaintext
201 lines
7.6 KiB
Plaintext
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>{{template "title" .}} - MAL</title>
|
|
<link rel="icon" type="image/svg+xml" href="/static/favicon.svg">
|
|
<link rel="stylesheet" href="/dist/tailwind.css">
|
|
<style>
|
|
/* Prevent transition on load */
|
|
.sidebar-collapsed #mobile-menu {
|
|
width: 5rem !important; /* lg:w-20 */
|
|
}
|
|
.sidebar-collapsed .nav-label-container {
|
|
grid-template-columns: 0fr !important;
|
|
opacity: 0 !important;
|
|
margin-left: 0 !important;
|
|
}
|
|
|
|
/* Re-enable transitions after initialization */
|
|
.sidebar-ready #mobile-menu,
|
|
.sidebar-ready .nav-label-container {
|
|
transition-property: all;
|
|
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
|
|
transition-duration: 300ms;
|
|
}
|
|
</style>
|
|
<script type="module" src="/dist/static/theme.js" defer></script>
|
|
<script type="module" src="/dist/static/dropdown.js" defer></script>
|
|
<script type="module" src="/dist/static/discover.js" defer></script>
|
|
<script type="module" src="/dist/static/anime.js" defer></script>
|
|
<script type="module" src="/dist/static/timezone.js" defer></script>
|
|
<script type="module" src="/dist/static/player.js" defer></script>
|
|
<script type="module" src="/dist/static/search.js" defer></script>
|
|
<script type="module" src="/dist/static/sort_filter.js" defer></script>
|
|
<script type="module" src="/dist/static/dedupe.js" defer></script>
|
|
<script type="module" src="/dist/static/toast.js" defer></script>
|
|
<script src="https://unpkg.com/htmx.org@1.9.12"></script>
|
|
<script>
|
|
document.addEventListener('htmx:afterSwap', function(evt) {
|
|
if (evt.detail.target.classList.contains('error')) {
|
|
if (window.showToast) showToast({ message: 'Failed to load content' });
|
|
}
|
|
});
|
|
document.addEventListener('htmx:responseError', function(evt) {
|
|
if (window.showToast) showToast({ message: 'Something went wrong' });
|
|
});
|
|
</script>
|
|
<script>
|
|
// Initialize sidebar state immediately to prevent layout shift/transitions
|
|
(function() {
|
|
const isCollapsed = localStorage.getItem('sidebar-collapsed') === 'true';
|
|
if (isCollapsed && window.innerWidth >= 1024) {
|
|
document.documentElement.classList.add('sidebar-collapsed');
|
|
}
|
|
})();
|
|
|
|
function toggleSidebar() {
|
|
const sidebar = document.getElementById('mobile-menu');
|
|
const isCollapsed = document.documentElement.classList.contains('sidebar-collapsed');
|
|
|
|
if (isCollapsed) {
|
|
document.documentElement.classList.remove('sidebar-collapsed');
|
|
localStorage.setItem('sidebar-collapsed', 'false');
|
|
} else {
|
|
document.documentElement.classList.add('sidebar-collapsed');
|
|
localStorage.setItem('sidebar-collapsed', 'true');
|
|
}
|
|
}
|
|
|
|
// Initialize sidebar state on load
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
// Small delay to ensure styles are applied before enabling transitions
|
|
requestAnimationFrame(() => {
|
|
document.documentElement.classList.add('sidebar-ready');
|
|
});
|
|
});
|
|
|
|
function toggleMobileMenu() {
|
|
const menu = document.getElementById('mobile-menu');
|
|
if (menu.classList.contains('-translate-x-full')) {
|
|
menu.classList.remove('-translate-x-full');
|
|
document.getElementById('mobile-overlay').classList.remove('hidden');
|
|
} else {
|
|
menu.classList.add('-translate-x-full');
|
|
document.getElementById('mobile-overlay').classList.add('hidden');
|
|
}
|
|
}
|
|
|
|
const watchlistIds = new Set()
|
|
|
|
function initWatchlist(ids) {
|
|
ids.forEach(id => watchlistIds.add(id))
|
|
}
|
|
|
|
function toggleWatchlist(id, btn) {
|
|
const isInWatchlist = watchlistIds.has(id)
|
|
const url = isInWatchlist ? `/api/watchlist/${id}` : '/api/watchlist'
|
|
const method = isInWatchlist ? 'DELETE' : 'POST'
|
|
const body = isInWatchlist ? null : JSON.stringify({ animeId: id, status: 'plan_to_watch' })
|
|
fetch(url, {
|
|
method,
|
|
headers: body ? { 'Content-Type': 'application/json' } : {},
|
|
body
|
|
}).then(res => {
|
|
if (res.ok) {
|
|
if (isInWatchlist) {
|
|
watchlistIds.delete(id)
|
|
btn.classList.remove('in-watchlist')
|
|
btn.setAttribute('aria-label', 'Add to Watchlist')
|
|
if (window.showToast) showToast({ message: 'Removed from watchlist' })
|
|
|
|
// Update dropdown status if on anime page
|
|
syncWatchlistDropdown(id, false)
|
|
} else {
|
|
watchlistIds.add(id)
|
|
btn.classList.add('in-watchlist')
|
|
btn.setAttribute('aria-label', 'Remove from Watchlist')
|
|
if (window.showToast) showToast({ message: 'Added to watchlist' })
|
|
|
|
// Update dropdown status if on anime page
|
|
syncWatchlistDropdown(id, true)
|
|
}
|
|
|
|
// Update all other watchlist icons on the page for this anime
|
|
document.querySelectorAll('.watchlist-icon').forEach(function(icon) {
|
|
const button = icon.closest('button')
|
|
if (button && button !== btn) {
|
|
const malId = button.dataset.malId
|
|
if (malId && parseInt(malId) === id) {
|
|
if (watchlistIds.has(id)) {
|
|
button.classList.add('in-watchlist')
|
|
} else {
|
|
button.classList.remove('in-watchlist')
|
|
}
|
|
}
|
|
}
|
|
})
|
|
} else {
|
|
if (window.showToast) showToast({ message: 'Failed to update watchlist' })
|
|
}
|
|
}).catch(() => {
|
|
if (window.showToast) showToast({ message: 'Something went wrong' })
|
|
})
|
|
}
|
|
|
|
function syncWatchlistDropdown(id, inWatchlist) {
|
|
const statusDisplay = document.getElementById('watchlist-status-display-' + id)
|
|
if (statusDisplay) {
|
|
statusDisplay.textContent = inWatchlist ? 'Plan to Watch' : 'Add to Watchlist'
|
|
const removeContainer = document.getElementById('remove-watchlist-container-' + id)
|
|
if (removeContainer) {
|
|
removeContainer.classList.toggle('hidden', !inWatchlist)
|
|
}
|
|
}
|
|
}
|
|
|
|
function removeFromWatchlist(id, btn) {
|
|
fetch(`/api/watchlist/${id}`, { method: 'DELETE' }).then(res => {
|
|
if (res.ok) {
|
|
watchlistIds.delete(id)
|
|
const card = btn.closest('.group').parentElement
|
|
if (card) card.remove()
|
|
setTimeout(() => location.reload(), 100)
|
|
}
|
|
})
|
|
}
|
|
</script>
|
|
</head>
|
|
<body class="bg-background text-neutral-200">
|
|
<div class="flex min-h-screen flex-col">
|
|
{{if .User}}
|
|
<div class="sticky top-0 z-50">
|
|
{{block "header" .}}
|
|
{{template "header" .}}
|
|
{{end}}
|
|
</div>
|
|
|
|
<div class="flex flex-1">
|
|
<button id="mobile-overlay" class="hidden fixed inset-0 z-40 w-full cursor-default border-none bg-black/60 backdrop-blur-sm outline-none lg:hidden" onclick="toggleMobileMenu()" aria-label="Close mobile menu"></button>
|
|
|
|
<!-- Sidebar -->
|
|
<div id="mobile-menu" class="fixed inset-y-0 left-0 z-50 shrink-0 overflow-hidden transform lg:sticky lg:top-16 lg:z-auto lg:h-[calc(100vh-4rem)] -translate-x-full lg:shadow-none lg:w-64 lg:translate-x-0 w-64 shadow-2xl">
|
|
{{block "sidebar" .}}
|
|
{{template "navigation" dict "CurrentPath" .CurrentPath}}
|
|
{{end}}
|
|
</div>
|
|
|
|
<main class="w-full flex-1 overflow-x-hidden p-4 md:p-8 lg:p-12">
|
|
{{template "content" .}}
|
|
</main>
|
|
</div>
|
|
{{else}}
|
|
<main class="w-full flex-1">
|
|
{{template "content" .}}
|
|
</main>
|
|
{{end}}
|
|
</div>
|
|
</body>
|
|
</html>
|