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: try:
page = int(request.GET.get('page', 1)) page = int(request.GET.get('page', 1))
per_page = int(request.GET.get('per_page', 8)) per_page = int(request.GET.get('per_page', 8))
watched = bool(request.GET.get('watched', "")) watched = bool(request.GET.get('watched', False))
except ValueError: except ValueError:
return JsonResponse({'error': 'Invalid page or per_page'}, status=400) return JsonResponse({'error': 'Invalid page or per_page'}, status=400)
offset = (page - 1) * per_page offset = (page - 1) * per_page
limit = offset + 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() total = all_links.count()
limit_results = list(all_links[offset:limit].values('id', 'url', 'watched')) results = list(all_links[offset:limit].values('id', 'url', 'watched'))
results = filter(lambda row: row['watched'] == str(watched), limit_results)
return JsonResponse({ return JsonResponse({
'results': results, 'results': results,

View File

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