Merge pull request #28 from olegvodyanov/add_separation
All checks were successful
continuous-integration/drone/push Build is passing

fix
This commit is contained in:
Олег Водянов 2025-04-23 15:34:04 +04:00 committed by GitHub
commit 8b0cddb9aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 7 deletions

View File

@ -20,17 +20,16 @@ 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', ""))
watched = bool(request.GET.get('watched', False))
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.all().order_by('-id') # latest first
all_links = Link.objects.get(watched__exact=watched).order_by('-id') # latest first
total = all_links.count()
limit_results = list(all_links[offset:limit].values('id', 'url', 'watched'))
results = filter(lambda row: row['watched'] == str(watched), limit_results)
results = list(all_links[offset:limit].values('id', 'url', 'watched'))
return JsonResponse({
'results': results,

View File

@ -4,7 +4,6 @@ const newLinksContainer = document.getElementById('newLinksContainer');
const watchedLinksContainer = document.getElementById('watchedLinksContainer');
const PER_PAGE = 8;
const WATCHED = false;
let currentPage = 1;
let linksData = [];
@ -15,7 +14,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}`;
@ -38,7 +37,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));