This commit is contained in:
Stefan Hardegger
2025-08-18 10:41:32 +02:00
parent e952241e3c
commit 6b97c0a70f
3 changed files with 27 additions and 37 deletions

View File

@@ -93,27 +93,32 @@ export default function LibraryPage() {
// Enrich existing tags when fullTags are loaded
useEffect(() => {
if (fullTags.length > 0 && tags.length > 0) {
// Check if tags already have color data to avoid infinite loops
const hasColors = tags.some(tag => tag.color);
if (!hasColors) {
// Re-enrich existing tags with color data
const enrichedTags = tags.map(tag => {
const fullTag = fullTags.find(ft => ft.name.toLowerCase() === tag.name.toLowerCase());
return {
...tag,
color: fullTag?.color,
description: fullTag?.description,
aliasCount: fullTag?.aliasCount,
createdAt: fullTag?.createdAt,
aliases: fullTag?.aliases,
id: fullTag?.id || tag.id
};
});
setTags(enrichedTags);
}
if (fullTags.length > 0) {
// Use functional update to get the current tags state
setTags(currentTags => {
if (currentTags.length > 0) {
// Check if tags already have color data to avoid infinite loops
const hasColors = currentTags.some(tag => tag.color);
if (!hasColors) {
// Re-enrich existing tags with color data
return currentTags.map(tag => {
const fullTag = fullTags.find(ft => ft.name.toLowerCase() === tag.name.toLowerCase());
return {
...tag,
color: fullTag?.color,
description: fullTag?.description,
aliasCount: fullTag?.aliasCount,
createdAt: fullTag?.createdAt,
aliases: fullTag?.aliases,
id: fullTag?.id || tag.id
};
});
}
}
return currentTags; // Return unchanged if no enrichment needed
});
}
}, [fullTags, tags]); // Run when fullTags or tags change
}, [fullTags]); // Only run when fullTags change
// Debounce search to avoid too many API calls
useEffect(() => {