fix fix fi x fix
This commit is contained in:
@@ -16,10 +16,11 @@
|
||||
*/
|
||||
|
||||
import React, { useEffect, useMemo, useState } from 'react';
|
||||
import { Content, fetchImages, ImageRecord } from '../services/api';
|
||||
import { Content, fetchImages, ImageRecord, fetchAPI } from '../services/api';
|
||||
import { ArrowLeftIcon, CalendarIcon, TagIcon, FileTextIcon, CheckCircleIcon, XCircleIcon, ClockIcon, PencilIcon, ImageIcon, BoltIcon } from '../icons';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import Button from '../components/ui/button/Button';
|
||||
import { useToast } from '../components/ui/toast/ToastContainer';
|
||||
|
||||
interface ContentViewTemplateProps {
|
||||
content: Content | null;
|
||||
@@ -618,9 +619,47 @@ const ArticleBody = ({ introHtml, sections, sectionImages, imagesLoading, rawHtm
|
||||
|
||||
export default function ContentViewTemplate({ content, loading, onBack }: ContentViewTemplateProps) {
|
||||
const navigate = useNavigate();
|
||||
const toast = useToast();
|
||||
const [imageRecords, setImageRecords] = useState<ImageRecord[]>([]);
|
||||
const [imagesLoading, setImagesLoading] = useState(false);
|
||||
const [imagesError, setImagesError] = useState<string | null>(null);
|
||||
|
||||
// Schedule editing state
|
||||
const [isEditingSchedule, setIsEditingSchedule] = useState(false);
|
||||
const [scheduleDateTime, setScheduleDateTime] = useState<string>('');
|
||||
const [isUpdatingSchedule, setIsUpdatingSchedule] = useState(false);
|
||||
|
||||
// Initialize schedule datetime when content loads
|
||||
useEffect(() => {
|
||||
if (content?.scheduled_publish_at) {
|
||||
// Convert ISO string to datetime-local format (YYYY-MM-DDTHH:mm)
|
||||
const date = new Date(content.scheduled_publish_at);
|
||||
const localDateTime = date.toISOString().slice(0, 16);
|
||||
setScheduleDateTime(localDateTime);
|
||||
}
|
||||
}, [content?.scheduled_publish_at]);
|
||||
|
||||
// Handler to update schedule
|
||||
const handleUpdateSchedule = async () => {
|
||||
if (!content?.id || !scheduleDateTime) return;
|
||||
|
||||
setIsUpdatingSchedule(true);
|
||||
try {
|
||||
const isoDateTime = new Date(scheduleDateTime).toISOString();
|
||||
await fetchAPI(`/v1/writer/content/${content.id}/schedule/`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ scheduled_publish_at: isoDateTime }),
|
||||
});
|
||||
toast.success('Schedule updated successfully');
|
||||
setIsEditingSchedule(false);
|
||||
// Trigger content refresh by reloading the page
|
||||
window.location.reload();
|
||||
} catch (error: any) {
|
||||
toast.error(`Failed to update schedule: ${error.message}`);
|
||||
} finally {
|
||||
setIsUpdatingSchedule(false);
|
||||
}
|
||||
};
|
||||
|
||||
const metadataPrompts = useMemo(() => extractImagePromptsFromMetadata(content?.metadata), [content?.metadata]);
|
||||
|
||||
@@ -1140,11 +1179,60 @@ export default function ContentViewTemplate({ content, loading, onBack }: Conten
|
||||
{content.site_status === 'failed' && 'Failed'}
|
||||
</span>
|
||||
</div>
|
||||
{content.scheduled_publish_at && content.site_status === 'scheduled' && (
|
||||
<span className="text-sm text-gray-500 dark:text-gray-400">
|
||||
{formatDate(content.scheduled_publish_at)}
|
||||
</span>
|
||||
|
||||
{/* Schedule Date/Time Editor - Only for scheduled content */}
|
||||
{content.site_status === 'scheduled' && (
|
||||
<div className="flex items-center gap-2">
|
||||
{isEditingSchedule ? (
|
||||
<>
|
||||
<input
|
||||
type="datetime-local"
|
||||
value={scheduleDateTime}
|
||||
onChange={(e) => setScheduleDateTime(e.target.value)}
|
||||
className="text-sm px-2 py-1 rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-700 dark:text-gray-300 focus:outline-none focus:ring-2 focus:ring-brand-500"
|
||||
/>
|
||||
<Button
|
||||
size="xs"
|
||||
variant="primary"
|
||||
tone="brand"
|
||||
onClick={handleUpdateSchedule}
|
||||
disabled={isUpdatingSchedule || !scheduleDateTime}
|
||||
>
|
||||
{isUpdatingSchedule ? 'Updating...' : 'Update'}
|
||||
</Button>
|
||||
<Button
|
||||
size="xs"
|
||||
variant="ghost"
|
||||
tone="neutral"
|
||||
onClick={() => {
|
||||
setIsEditingSchedule(false);
|
||||
// Reset to original value
|
||||
if (content.scheduled_publish_at) {
|
||||
const date = new Date(content.scheduled_publish_at);
|
||||
setScheduleDateTime(date.toISOString().slice(0, 16));
|
||||
}
|
||||
}}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<span className="text-sm text-gray-500 dark:text-gray-400">
|
||||
{content.scheduled_publish_at ? formatDate(content.scheduled_publish_at) : ''}
|
||||
</span>
|
||||
<button
|
||||
onClick={() => setIsEditingSchedule(true)}
|
||||
className="text-brand-600 hover:text-brand-700 dark:text-brand-400 dark:hover:text-brand-300 p-1"
|
||||
title="Edit schedule"
|
||||
>
|
||||
<PencilIcon className="w-4 h-4" />
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{content.external_url && content.site_status === 'published' && (
|
||||
<a
|
||||
href={content.external_url}
|
||||
|
||||
Reference in New Issue
Block a user