fix: prevent 10-post refresh from overwriting full cache, add refresh-all button
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
"Najnowsze 10" no longer saves to DB cache. New "Odswiez wszystkie" button fetches all posts via FB API pagination and saves to cache. "Analityka" uses cache for instant charts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
a6e0ce3c39
commit
73d7b8f8ee
@ -454,8 +454,9 @@
|
||||
</span>
|
||||
{% endif %}
|
||||
</h3>
|
||||
<div style="display: flex; gap: var(--spacing-xs); align-items: center;">
|
||||
<button class="btn btn-secondary btn-small" onclick="loadFbPosts({{ company_id_key }}, this)">Odswiez</button>
|
||||
<div style="display: flex; gap: var(--spacing-xs); align-items: center; flex-wrap: wrap;">
|
||||
<button class="btn btn-secondary btn-small" onclick="loadFbPosts({{ company_id_key }}, this)">Najnowsze 10</button>
|
||||
<button class="btn btn-secondary btn-small" onclick="refreshAllFbPosts({{ company_id_key }}, this)">Odswiez wszystkie</button>
|
||||
<button class="btn btn-primary btn-small" onclick="loadAllFbPosts({{ company_id_key }}, this)">Analityka</button>
|
||||
</div>
|
||||
</div>
|
||||
@ -823,7 +824,6 @@
|
||||
return;
|
||||
}
|
||||
renderFbPosts(companyId, data.posts, data.next_cursor, isAppend);
|
||||
if (!isAppend) saveFbPostsToCache(companyId, data.posts);
|
||||
})
|
||||
.catch(function(err) {
|
||||
btn.textContent = origText;
|
||||
@ -952,6 +952,54 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshAllFbPosts(companyId, btn) {
|
||||
var origText = btn.textContent;
|
||||
btn.disabled = true;
|
||||
var container = document.getElementById('fbPostsContainer-' + companyId);
|
||||
container.innerHTML = '<div style="text-align:center;padding:20px;color:var(--text-secondary);">Pobieranie WSZYSTKICH postow z Facebook API...</div>';
|
||||
|
||||
var allPosts = [];
|
||||
var cursor = null;
|
||||
var page = 0;
|
||||
|
||||
try {
|
||||
while (true) {
|
||||
page++;
|
||||
btn.textContent = 'Pobieranie... (' + allPosts.length + ' postow, strona ' + page + ')';
|
||||
|
||||
var url = '/admin/social-publisher/fb-posts/' + companyId;
|
||||
if (cursor) url += '?after=' + encodeURIComponent(cursor);
|
||||
|
||||
var response = await fetch(url);
|
||||
var data = await response.json();
|
||||
|
||||
if (!data.success || !data.posts || data.posts.length === 0) break;
|
||||
|
||||
allPosts = allPosts.concat(data.posts);
|
||||
|
||||
if (!data.next_cursor) break;
|
||||
cursor = data.next_cursor;
|
||||
}
|
||||
|
||||
btn.textContent = origText;
|
||||
btn.disabled = false;
|
||||
|
||||
if (allPosts.length === 0) {
|
||||
container.innerHTML = '<div style="text-align:center;padding:20px;color:var(--text-secondary);">Brak postow.</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
renderFbPosts(companyId, allPosts, null, false);
|
||||
container.insertAdjacentHTML('beforeend',
|
||||
'<div style="text-align:center;margin-top:var(--spacing-md);color:var(--text-secondary);font-size:var(--font-size-sm);">Pobrano ' + allPosts.length + ' postow z Facebook API i zapisano do cache</div>');
|
||||
saveFbPostsToCache(companyId, allPosts);
|
||||
} catch (err) {
|
||||
btn.textContent = origText;
|
||||
btn.disabled = false;
|
||||
showToast('Blad polaczenia: ' + err.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
function renderFbCharts(companyId, posts) {
|
||||
// Sort chronologically (oldest first)
|
||||
var sorted = posts.slice().sort(function(a, b) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user