mirror of
https://github.com/olegvodyanov/instalinks.git
synced 2025-12-20 09:07:04 +03:00
Compare commits
2 Commits
1b2f86ce39
...
174668e85f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
174668e85f | ||
|
|
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 => {
|
||||||
|
localStorage.setItem(cacheKey, JSON.stringify(data));
|
||||||
|
if (!cached) {
|
||||||
linksData = data.results;
|
linksData = data.results;
|
||||||
renderPaginatedList(linksData, newLinksContainer, false, data.page, data.pages);
|
renderPaginatedList(
|
||||||
renderPaginatedList(linksData.filter(l => l.watched), watchedLinksContainer, true, data.page, data.pages);
|
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