mirror of
https://github.com/olegvodyanov/instalinks.git
synced 2025-12-20 05:47:03 +03:00
This commit is contained in:
parent
1b2f86ce39
commit
6e20d9c3f9
@ -5,14 +5,37 @@ const watchedLinksContainer = document.getElementById('watchedLinksContainer');
|
|||||||
|
|
||||||
const PER_PAGE = 8;
|
const PER_PAGE = 8;
|
||||||
let currentPage = 1;
|
let currentPage = 1;
|
||||||
|
let linksData = [];
|
||||||
|
|
||||||
function loadLinks() {
|
function loadLinks() {
|
||||||
|
const cacheKey = `links_cache_page_${currentPage}_per_${PER_PAGE}`;
|
||||||
|
const cached = localStorage.getItem(cacheKey);
|
||||||
|
|
||||||
|
if (cached) {
|
||||||
|
const data = JSON.parse(cached);
|
||||||
|
linksData = data.results;
|
||||||
|
renderPaginatedList(
|
||||||
|
linksData.filter(l => !l.watched),newLinksContainer,false,data.page,data.pages
|
||||||
|
);
|
||||||
|
renderPaginatedList(
|
||||||
|
linksData.filter(l => l.watched),watchedLinksContainer,true,data.page,data.pages
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Always fetch fresh data in the background
|
||||||
fetch(`/api/links/?page=${currentPage}&per_page=${PER_PAGE}`)
|
fetch(`/api/links/?page=${currentPage}&per_page=${PER_PAGE}`)
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
linksData = data.results;
|
localStorage.setItem(cacheKey, JSON.stringify(data));
|
||||||
renderPaginatedList(linksData, newLinksContainer, false, data.page, data.pages);
|
if (!cached) {
|
||||||
renderPaginatedList(linksData.filter(l => l.watched), watchedLinksContainer, true, data.page, data.pages);
|
linksData = data.results;
|
||||||
|
renderPaginatedList(
|
||||||
|
linksData.filter(l => !l.watched),newLinksContainer,false,data.page,data.pages
|
||||||
|
);
|
||||||
|
renderPaginatedList(
|
||||||
|
linksData.filter(l => l.watched),watchedLinksContainer,true,data.page,data.pages
|
||||||
|
);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(err => console.error(err));
|
.catch(err => console.error(err));
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user