mirror of
https://github.com/olegvodyanov/instalinks.git
synced 2025-12-20 07:57:04 +03:00
This commit is contained in:
parent
79f8ca6ecf
commit
0c5dffc527
@ -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,
|
||||||
|
|||||||
@ -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));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user