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.

84 lines
2.5 KiB
HTML

{% extends "base.html" %}
{% from "_pagination.html" import pager %}
{% block title %}{{ username }} — Videos{% endblock %}
{% block content %}
<h1>📼 {{ username }}</h1>
<div class="grid">
{% for v in videos %}
<div class="card video-card" data-video-id="{{ v.video_id }}">
<div class="thumb thumb-wrap">
{% set thumb = v.thumbnail %}
<a class="thumb-link" href="{{ url_for('web.view_video', video_id=v.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="{{ v.video_id }}"
aria-pressed="{{ 'true' if v.is_favorite else 'false' }}"
title="{{ 'Unfavorite' if v.is_favorite else 'Favorite' }}"
>
{{ '★' if v.is_favorite else '☆' }}
</button>
</div>
<div class="meta">
<div class="row">
<span class="muted">Size:</span>
{{ "%.2f"|format((v.size or 0)/1024) }} GB
</div>
{% if v.site %}
<div class="row">
<span class="muted">Site:</span>
<a href="https://{{ v.site }}.com/{{ username }}" target="_blank" rel="noopener">{{ v.site }}</a>
</div>
{% endif %}
{% if v.created_at %}
<div class="row muted">
{{ v.created_at }}
</div>
{% endif %}
</div>
</div>
{% endfor %}
</div>
{{ pager('web.user_page', page, total_pages, username=username) }}
{% 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';
} catch (err) {
alert('Could not toggle favorite. ' + (err?.message || ''));
}
});
</script>
{% endblock %}