Fix translation language badges not updating after auto-translation (#54)

Co-authored-by: hugo <hugoms@me.com>
This commit is contained in:
Georg Bauer
2026-03-13 18:47:04 +01:00
committed by GitHub
parent 9bd0114012
commit f03b087c13
4 changed files with 83 additions and 0 deletions

View File

@@ -2018,6 +2018,8 @@ export function registerEventForwarding(bundle: EngineBundle): void {
postEngine.on('postCreated', forwardEvent('post:created'));
postEngine.on('postUpdated', forwardEvent('post:updated'));
postEngine.on('postDeleted', forwardEvent('post:deleted'));
postEngine.on('postTranslationCreated', forwardEvent('post:translationCreated'));
postEngine.on('postTranslationUpdated', forwardEvent('post:translationUpdated'));
postEngine.on('rebuildStarted', forwardEvent('posts:rebuildStarted'));
postEngine.on('databaseRebuilt', forwardEvent('posts:databaseRebuilt'));

View File

@@ -167,6 +167,24 @@ const App: React.FC = () => {
}) || (() => {})
);
// Post translation events (refresh post to update availableLanguages for sidebar badges)
const handlePostTranslationChange = (data: unknown) => {
const translation = data as { translationFor?: string };
if (translation.translationFor) {
window.electronAPI?.posts.get(translation.translationFor).then((post) => {
if (post) {
updatePost((post as PostData).id, post as PostData);
}
});
}
};
unsubscribers.push(
window.electronAPI?.on('post:translationCreated', handlePostTranslationChange) || (() => {})
);
unsubscribers.push(
window.electronAPI?.on('post:translationUpdated', handlePostTranslationChange) || (() => {})
);
// Media events
unsubscribers.push(
window.electronAPI?.on('media:imported', (media: unknown) => {

View File

@@ -416,6 +416,22 @@ export const PostEditor: React.FC<PostEditorProps> = ({ postId }) => {
});
}, [loadTranslations]);
// Refresh translations when auto-translation completes for this post
useEffect(() => {
const handleTranslationEvent = (data: unknown) => {
const translation = data as { translationFor?: string };
if (translation.translationFor === postId) {
loadTranslations().catch(() => {});
}
};
const unsubCreated = window.electronAPI?.on('post:translationCreated', handleTranslationEvent);
const unsubUpdated = window.electronAPI?.on('post:translationUpdated', handleTranslationEvent);
return () => {
unsubCreated?.();
unsubUpdated?.();
};
}, [loadTranslations, postId]);
// Debounce content for lightbox-only computations (not time-critical)
const debouncedContent = useDebouncedValue(content, 500);