widgets and other fixes

This commit is contained in:
IGNY8 VPS (Salman)
2026-01-11 15:24:52 +00:00
parent 747770ac58
commit e9369df151
16 changed files with 761 additions and 277 deletions

View File

@@ -115,42 +115,47 @@ export default function Keywords() {
loadClusters();
}, []);
// Load total metrics for footer widget (not affected by pagination)
// Load total metrics for footer widget (site-wide totals, no sector filter)
const loadTotalMetrics = useCallback(async () => {
if (!activeSite) return;
try {
// Get all keywords (total count) - this is already in totalCount from main load
// Get keywords with status='mapped' (those that have been mapped to a cluster)
const mappedRes = await fetchKeywords({
page_size: 1,
site_id: activeSite.id,
...(activeSector?.id && { sector_id: activeSector.id }),
status: 'mapped',
});
// Batch all API calls in parallel for better performance
const [allRes, mappedRes, newRes, imagesRes] = await Promise.all([
// Get total keywords count (site-wide)
fetchKeywords({
page_size: 1,
site_id: activeSite.id,
}),
// Get keywords with status='mapped' (site-wide)
fetchKeywords({
page_size: 1,
site_id: activeSite.id,
status: 'mapped',
}),
// Get keywords with status='new' (site-wide)
fetchKeywords({
page_size: 1,
site_id: activeSite.id,
status: 'new',
}),
// Get actual total images count
fetchImages({ page_size: 1 }),
]);
setTotalCount(allRes.count || 0);
setTotalClustered(mappedRes.count || 0);
// Get keywords with status='new' (those that are ready to cluster but haven't been yet)
const newRes = await fetchKeywords({
page_size: 1,
site_id: activeSite.id,
...(activeSector?.id && { sector_id: activeSector.id }),
status: 'new',
});
setTotalUnmapped(newRes.count || 0);
setTotalImagesCount(imagesRes.count || 0);
// Get total volume across all keywords (we need to fetch all or rely on backend aggregation)
// For now, we'll just calculate from current data or set to 0
// TODO: Backend should provide total volume as an aggregated metric
setTotalVolume(0);
// Get actual total images count
const imagesRes = await fetchImages({ page_size: 1 });
setTotalImagesCount(imagesRes.count || 0);
} catch (error) {
console.error('Error loading total metrics:', error);
}
}, [activeSite, activeSector]);
}, [activeSite]);
// Load total metrics when site/sector changes
useEffect(() => {