mirror of
https://github.com/olegvodyanov/instalinks.git
synced 2025-12-20 12:37:05 +03:00
Compare commits
No commits in common. "174668e85fdf1b35ccd4f5a7390d705b3dde8aa8" and "1b2f86ce39616b416fdb1cb7c3862b0d457baa3c" have entirely different histories.
174668e85f
...
1b2f86ce39
@ -5,37 +5,14 @@ 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 => {
|
||||||
localStorage.setItem(cacheKey, JSON.stringify(data));
|
linksData = data.results;
|
||||||
if (!cached) {
|
renderPaginatedList(linksData, newLinksContainer, false, data.page, data.pages);
|
||||||
linksData = data.results;
|
renderPaginatedList(linksData.filter(l => l.watched), watchedLinksContainer, true, data.page, data.pages);
|
||||||
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