From 8103c20341fcf0c1c18d730be3847fae6a44848d Mon Sep 17 00:00:00 2001 From: alorig <220087330+alorig@users.noreply.github.com> Date: Fri, 28 Nov 2025 14:21:38 +0500 Subject: [PATCH] 1 --- .../src/config/pages/table-actions.config.tsx | 8 +- frontend/src/pages/Writer/Images.tsx | 74 ++++++++++++------- 2 files changed, 50 insertions(+), 32 deletions(-) diff --git a/frontend/src/config/pages/table-actions.config.tsx b/frontend/src/config/pages/table-actions.config.tsx index f7018c45..dd891b23 100644 --- a/frontend/src/config/pages/table-actions.config.tsx +++ b/frontend/src/config/pages/table-actions.config.tsx @@ -327,10 +327,10 @@ const tableActionsConfigs: Record = { icon: , variant: 'success', shouldShow: (row: any) => { - // Only show if images are generated and not already published/publishing - return row.status === 'complete' && - (!row.wordpress_status || - (row.wordpress_status !== 'published' && row.wordpress_status !== 'publishing')); + // Only show if content is completed and not already published to WordPress + return row.status === 'published' && + (!row.external_id || !row.external_url) && + (!row.sync_status || row.sync_status !== 'published'); }, }, { diff --git a/frontend/src/pages/Writer/Images.tsx b/frontend/src/pages/Writer/Images.tsx index 3b58cd51..68addb6e 100644 --- a/frontend/src/pages/Writer/Images.tsx +++ b/frontend/src/pages/Writer/Images.tsx @@ -13,7 +13,7 @@ import { generateImages, bulkUpdateImagesStatus, ContentImage, - api, + fetchAPI, } from '../../services/api'; import { useToast } from '../../components/ui/toast/ToastContainer'; import { FileIcon, DownloadIcon, BoltIcon, TaskIcon, ImageIcon, CheckCircleIcon } from '../../icons'; @@ -208,40 +208,54 @@ export default function Images() { // Bulk action handler const handleBulkAction = useCallback(async (action: string, ids: string[]) => { if (action === 'bulk_publish_wordpress') { - // Filter to only publish items that have images generated and are not already published + // Filter to only publish items that are ready and not already published const readyItems = images .filter(item => ids.includes(item.content_id.toString())) - .filter(item => item.status === 'complete' && - (!item.wordpress_status || - (item.wordpress_status !== 'published' && item.wordpress_status !== 'publishing'))); + .filter(item => item.status === 'published' && + (!item.external_id || !item.external_url) && + (!item.sync_status || item.sync_status !== 'published')); if (readyItems.length === 0) { - toast.warning('No items are ready for WordPress publishing. Items must have generated images and not already be published.'); + toast.warning('No items are ready for WordPress publishing. Items must be published and not already synced to WordPress.'); return; } try { - const response = await api.post('/api/wordpress/bulk-publish/', { - content_ids: readyItems.map(item => item.content_id.toString()) - }); + let successCount = 0; + let failedCount = 0; - if (response.data.success) { - const results = response.data.data.results; - const successCount = results.filter((r: any) => r.success).length; - const failedCount = results.filter((r: any) => !r.success).length; - - if (successCount > 0) { - toast.success(`Successfully published ${successCount} item(s) to WordPress`); + // Publish each item individually using the unified publisher API + for (const item of readyItems) { + try { + const response = await fetchAPI('/v1/publisher/publish/', { + method: 'POST', + body: JSON.stringify({ + content_id: item.content_id, + destinations: ['wordpress'] + }) + }); + + if (response.success) { + successCount++; + } else { + failedCount++; + console.warn(`Failed to publish content ${item.content_id}:`, response.error); + } + } catch (error) { + failedCount++; + console.error(`Error publishing content ${item.content_id}:`, error); } - if (failedCount > 0) { - toast.warning(`${failedCount} item(s) failed to publish`); - } - - // Reload images to reflect the updated WordPress status - loadImages(); - } else { - toast.error(`Bulk publish failed: ${response.data.message}`); } + + if (successCount > 0) { + toast.success(`Successfully published ${successCount} item(s) to WordPress`); + } + if (failedCount > 0) { + toast.warning(`${failedCount} item(s) failed to publish`); + } + + // Reload images to reflect the updated WordPress status + loadImages(); } catch (error: any) { console.error('Bulk WordPress publish error:', error); toast.error(`Failed to bulk publish to WordPress: ${error.message || 'Network error'}`); @@ -260,16 +274,20 @@ export default function Images() { } else if (action === 'publish_wordpress') { // Handle WordPress publishing for individual item try { - const response = await api.post('/api/wordpress/publish/', { - content_id: row.content_id.toString() + const response = await fetchAPI('/v1/publisher/publish/', { + method: 'POST', + body: JSON.stringify({ + content_id: row.content_id, + destinations: ['wordpress'] + }) }); - if (response.data.success) { + if (response.success) { toast.success(`Successfully published "${row.content_title}" to WordPress`); // Reload images to reflect the updated WordPress status loadImages(); } else { - toast.error(`Failed to publish: ${response.data.message}`); + toast.error(`Failed to publish: ${response.error || response.message}`); } } catch (error: any) { console.error('WordPress publish error:', error);