Fix translation language badges not updating after auto-translation (#54)
Co-authored-by: hugo <hugoms@me.com>
This commit is contained in:
@@ -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) => {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user