continue watching/reading
This commit is contained in:
@@ -71,6 +71,70 @@ async function fetchSearh(query) {
|
||||
}
|
||||
}
|
||||
|
||||
async function loadContinueWatching() {
|
||||
const token = localStorage.getItem('token');
|
||||
if (!token) return;
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/list/filter?status=watching&entry_type=ANIME', {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`
|
||||
}
|
||||
});
|
||||
|
||||
if (!res.ok) return;
|
||||
|
||||
const data = await res.json();
|
||||
const list = data.results || [];
|
||||
|
||||
renderContinueWatching('my-status', list);
|
||||
|
||||
} catch (err) {
|
||||
console.error('Continue Watching Error:', err);
|
||||
}
|
||||
}
|
||||
|
||||
function renderContinueWatching(id, list) {
|
||||
const container = document.getElementById(id);
|
||||
if (!container) return;
|
||||
|
||||
container.innerHTML = '';
|
||||
|
||||
if (list.length === 0) {
|
||||
container.innerHTML = `<div style="padding:1rem; color:#888">No watching anime</div>`;
|
||||
return;
|
||||
}
|
||||
|
||||
// ✅ ordenar por fecha
|
||||
list.sort((a, b) => new Date(b.updated_at) - new Date(a.updated_at));
|
||||
|
||||
list.forEach(item => {
|
||||
const el = document.createElement('div');
|
||||
el.className = 'card';
|
||||
|
||||
el.onclick = () => window.location.href =
|
||||
item.source === 'anilist'
|
||||
? `/anime/${item.entry_id}`
|
||||
: `/anime/${item.source}/${item.entry_id}`;
|
||||
|
||||
const progressText = item.total_episodes
|
||||
? `${item.progress || 0}/${item.total_episodes}`
|
||||
: `${item.progress || 0}`;
|
||||
|
||||
el.innerHTML = `
|
||||
<div class="card-img-wrap">
|
||||
<img src="${item.poster}" loading="lazy">
|
||||
</div>
|
||||
<div class="card-content">
|
||||
<h3>${item.title}</h3>
|
||||
<p>Ep ${progressText} - ${item.source}</p> </div>
|
||||
`;
|
||||
|
||||
container.appendChild(el);
|
||||
});
|
||||
}
|
||||
|
||||
function renderSearchResults(results) {
|
||||
searchResults.innerHTML = '';
|
||||
if (results.length === 0) {
|
||||
@@ -263,4 +327,5 @@ function renderList(id, list) {
|
||||
}
|
||||
|
||||
fetchContent();
|
||||
loadContinueWatching();
|
||||
setInterval(() => fetchContent(true), 60000);
|
||||
Reference in New Issue
Block a user