You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.2 KiB
HTML

{% extends "base.html" %}
{% from "_pagination.html" import pager %}
{% block title %}★ Favorites{% endblock %}
{% block content %}
<h1>★ Favorites</h1>
<div class="grid videos">
{% for video in videos %}
<div class="card video-card" data-video-id="{{ video.video_id }}">
<div class="thumb thumb-wrap">
{% set thumb = video.thumbnail %}
<a class="thumb-link" href="{{ url_for('web.view_video', video_id=video.video_id) }}">
<img
src="{{ thumb if thumb and thumb.startswith('http') else ('/' ~ (thumb or '')) }}"
alt="Thumbnail"
loading="lazy"
decoding="async"
onerror="this.style.display='none'; this.parentElement.parentElement.querySelector('.fallback').style.display='flex';"
>
</a>
<span class="fallback">🎞️</span>
<button
class="fav-btn"
data-video-id="{{ video.video_id }}"
aria-pressed="{{ 'true' if video.is_favorite else 'false' }}"
title="{{ 'Unfavorite' if video.is_favorite else 'Favorite' }}"
>
{{ '★' if video.is_favorite else '☆' }}
</button>
</div>
<div class="meta">
<div class="row muted">{{ "%.2f"|format((video.size or 0)/1024) }} GB</div>
</div>
</div>
{% endfor %}
</div>
{{ pager('web.favorites_page', page, total_pages) }}
{% endblock %}
{% block scripts %}
<script>
document.addEventListener('click', async (e) => {
const btn = e.target.closest('.fav-btn');
if (!btn) return;
e.preventDefault(); e.stopPropagation();
const card = btn.closest('.video-card');
const vid = btn.dataset.videoId;
try {
const res = await fetch(`/api/fav/toggle/${encodeURIComponent(vid)}`, { method: 'POST' });
const data = await res.json();
if (!res.ok || !data.ok) throw new Error(data.error || 'Failed');
const isFav = data.is_favorite;
btn.textContent = isFav ? '★' : '☆';
btn.setAttribute('aria-pressed', isFav ? 'true' : 'false');
btn.title = isFav ? 'Unfavorite' : 'Favorite';
// Remove immediately if unfavorited (since this is the Favorites page)
if (!isFav) card.remove();
} catch (err) {
alert('Could not toggle favorite. ' + (err?.message || ''));
}
});
</script>
{% endblock %}