fine tuning

This commit is contained in:
IGNY8 VPS (Salman)
2025-11-28 12:25:45 +00:00
parent 831b179c49
commit 0839455418
15 changed files with 840 additions and 95 deletions

View File

@@ -240,63 +240,8 @@ 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 are ready and not already published
const readyItems = images
.filter(item => ids.includes(item.content_id.toString()))
.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 be published and not already synced to WordPress.');
return;
}
try {
let successCount = 0;
let failedCount = 0;
// 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 (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'}`);
}
} else {
toast.info(`Bulk action "${action}" for ${ids.length} items`);
}
}, [images, toast, loadImages]);
toast.info(`Bulk action "${action}" for ${ids.length} items`);
}, [toast]);
// Row action handler
const handleRowAction = useCallback(async (action: string, row: ContentImagesGroup) => {
@@ -304,30 +249,8 @@ export default function Images() {
setStatusUpdateContentId(row.content_id);
setStatusUpdateRecordName(row.content_title || `Content #${row.content_id}`);
setIsStatusModalOpen(true);
} else if (action === 'publish_wordpress') {
// Handle WordPress publishing for individual item
try {
const response = await fetchAPI('/v1/publisher/publish/', {
method: 'POST',
body: JSON.stringify({
content_id: row.content_id,
destinations: ['wordpress']
})
});
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.error || response.message}`);
}
} catch (error: any) {
console.error('WordPress publish error:', error);
toast.error(`Failed to publish to WordPress: ${error.message || 'Network error'}`);
}
}
}, [loadImages, toast]);
}, []);
// Handle status update confirmation
const handleStatusUpdate = useCallback(async (status: string) => {
@@ -577,6 +500,7 @@ export default function Images() {
{ label: 'Tasks', path: '/writer/tasks', icon: <TaskIcon /> },
{ label: 'Content', path: '/writer/content', icon: <FileIcon /> },
{ label: 'Images', path: '/writer/images', icon: <ImageIcon /> },
{ label: 'Review', path: '/writer/review', icon: <CheckCircleIcon /> },
{ label: 'Published', path: '/writer/published', icon: <CheckCircleIcon /> },
];