fix: fixes on media importing
This commit is contained in:
@@ -276,6 +276,35 @@ const App: React.FC = () => {
|
||||
}) || (() => {})
|
||||
);
|
||||
|
||||
// Import completion event - refresh posts and media stores
|
||||
unsubscribers.push(
|
||||
window.electronAPI?.import.onComplete(async (data) => {
|
||||
// Refresh posts store if any posts were imported
|
||||
if (data.posts.imported > 0 || data.pages.imported > 0) {
|
||||
const postsResult = await window.electronAPI?.posts.getAll({ limit: 500, offset: 0 });
|
||||
if (postsResult) {
|
||||
const { items, hasMore, total } = postsResult as { items: PostData[]; hasMore: boolean; total: number };
|
||||
setPosts(items, hasMore, total);
|
||||
}
|
||||
}
|
||||
|
||||
// Refresh media store if any media was imported
|
||||
if (data.media.imported > 0) {
|
||||
const mediaResult = await window.electronAPI?.media.getAll();
|
||||
if (mediaResult) {
|
||||
setMedia(mediaResult as MediaData[]);
|
||||
}
|
||||
}
|
||||
|
||||
// Show success toast
|
||||
const importedCount = data.posts.imported + data.pages.imported;
|
||||
const importedMedia = data.media.imported;
|
||||
if (data.success) {
|
||||
showToast.success(`Import complete: ${importedCount} posts, ${importedMedia} media files`);
|
||||
}
|
||||
}) || (() => {})
|
||||
);
|
||||
|
||||
return () => {
|
||||
unsubscribers.forEach(unsub => unsub());
|
||||
};
|
||||
|
||||
@@ -359,6 +359,7 @@ export const ImportAnalysisView: React.FC<ImportAnalysisViewProps> = ({ definiti
|
||||
await window.electronAPI?.importDefinitions.update(definitionId, {
|
||||
lastAnalysisResult: JSON.stringify(result),
|
||||
wxrFilePath: result.sourceFile,
|
||||
name: result.site.link || result.site.title || undefined,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
10
src/renderer/types/electron.d.ts
vendored
10
src/renderer/types/electron.d.ts
vendored
@@ -14,6 +14,15 @@ export interface ImportExecutionProgress {
|
||||
eta?: number;
|
||||
}
|
||||
|
||||
export interface ImportCompleteResult {
|
||||
taskId: string;
|
||||
success: boolean;
|
||||
posts: { imported: number; skipped: number; errors: number };
|
||||
media: { imported: number; skipped: number; errors: number };
|
||||
pages: { imported: number; skipped: number; errors: number };
|
||||
tags: { created: number; skipped: number };
|
||||
}
|
||||
|
||||
export interface ImportDefinitionData {
|
||||
id: string;
|
||||
projectId: string;
|
||||
@@ -388,6 +397,7 @@ export interface ElectronAPI {
|
||||
execute: (reportJson: string, uploadsFolder?: string) => Promise<ImportExecuteResult>;
|
||||
onProgress: (callback: (data: { step: string; detail?: string }) => void) => () => void;
|
||||
onExecutionProgress: (callback: (data: ImportExecutionProgress) => void) => () => void;
|
||||
onComplete: (callback: (data: ImportCompleteResult) => void) => () => void;
|
||||
};
|
||||
importDefinitions: {
|
||||
create: (name?: string) => Promise<ImportDefinitionData>;
|
||||
|
||||
Reference in New Issue
Block a user