mirror of
https://github.com/olegvodyanov/instalinks.git
synced 2025-12-20 06:47:05 +03:00
Compare commits
2 Commits
8720c08250
...
8b0cddb9aa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b0cddb9aa | ||
|
|
0c5dffc527 |
@ -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,
|
||||
|
||||
@ -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));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user