Compare commits

..

No commits in common. "8b0cddb9aaed23af30e6acb07fd049321b6d7dfa" and "8720c082507b6b6014c4a5f8d1924e0fec6aa9ef" have entirely different histories.

2 changed files with 7 additions and 5 deletions

View File

@ -20,16 +20,17 @@ def links_list(request):
try:
page = int(request.GET.get('page', 1))
per_page = int(request.GET.get('per_page', 8))
watched = bool(request.GET.get('watched', False))
watched = bool(request.GET.get('watched', ""))
except ValueError:
return JsonResponse({'error': 'Invalid page or per_page'}, status=400)
offset = (page - 1) * per_page
limit = offset + per_page
all_links = Link.objects.get(watched__exact=watched).order_by('-id') # latest first
all_links = Link.objects.all().order_by('-id') # latest first
total = all_links.count()
results = list(all_links[offset:limit].values('id', 'url', 'watched'))
limit_results = list(all_links[offset:limit].values('id', 'url', 'watched'))
results = filter(lambda row: row['watched'] == str(watched), limit_results)
return JsonResponse({
'results': results,

View File

@ -4,6 +4,7 @@ const newLinksContainer = document.getElementById('newLinksContainer');
const watchedLinksContainer = document.getElementById('watchedLinksContainer');
const PER_PAGE = 8;
const WATCHED = false;
let currentPage = 1;
let linksData = [];
@ -14,7 +15,7 @@ function extractReelId(url) {
}
function loadLinks() {
const cacheKeyWatched = `links_cache_page_${currentPage}_per_${PER_PAGE}&watched='True'`;
const cacheKeyWatched = `links_cache_page_${currentPage}_per_${PER_PAGE}&watched='true'`;
const cachedWatched = localStorage.getItem(cacheKeyWatched);
const cacheKey = `links_cache_page_${currentPage}_per_${PER_PAGE}`;
@ -37,7 +38,7 @@ function loadLinks() {
}
// Always fetch fresh data in the background
fetch(`/api/links/?page=${currentPage}&per_page=${PER_PAGE}&watched='True'`)
fetch(`/api/links/?page=${currentPage}&per_page=${PER_PAGE}&watched='true'`)
.then(response => response.json())
.then(data => {
localStorage.setItem(cacheKeyWatched, JSON.stringify(data));