Allowing AI to generate suggestions for the blog writer
This commit is contained in:
@@ -24,6 +24,9 @@ export const useBlogWriterState = () => {
|
||||
// Separate research titles from AI-generated titles
|
||||
const [researchTitles, setResearchTitles] = useState<string[]>([]);
|
||||
const [aiGeneratedTitles, setAiGeneratedTitles] = useState<string[]>([]);
|
||||
|
||||
// Outline confirmation state
|
||||
const [outlineConfirmed, setOutlineConfirmed] = useState<boolean>(false);
|
||||
|
||||
// Cache recovery - restore most recent research on page load
|
||||
useEffect(() => {
|
||||
@@ -116,6 +119,8 @@ export const useBlogWriterState = () => {
|
||||
}
|
||||
}
|
||||
setOutlineTaskId(null);
|
||||
// Reset outline confirmation when new outline is generated
|
||||
setOutlineConfirmed(false);
|
||||
}, [research]);
|
||||
|
||||
// Handle outline error
|
||||
@@ -149,6 +154,36 @@ export const useBlogWriterState = () => {
|
||||
localStorage.setItem('blog_selected_title', title);
|
||||
}, [titleOptions]);
|
||||
|
||||
// Handle outline confirmation
|
||||
const handleOutlineConfirmed = useCallback(() => {
|
||||
setOutlineConfirmed(true);
|
||||
console.log('Outline confirmed by user');
|
||||
}, []);
|
||||
|
||||
// Handle outline refinement
|
||||
const handleOutlineRefined = useCallback((feedback: string) => {
|
||||
console.log('Outline refinement requested with feedback:', feedback);
|
||||
// The actual refinement will be handled by the copilot action
|
||||
}, []);
|
||||
|
||||
// Handle content updates from WYSIWYG editor
|
||||
const handleContentUpdate = useCallback((updatedSections: any[]) => {
|
||||
console.log('Content updated:', updatedSections);
|
||||
// Update sections state with new content
|
||||
const newSections: { [key: string]: string } = {};
|
||||
updatedSections.forEach(section => {
|
||||
newSections[section.id] = section.content;
|
||||
});
|
||||
setSections(newSections);
|
||||
}, [setSections]);
|
||||
|
||||
// Handle content saving
|
||||
const handleContentSave = useCallback((content: any) => {
|
||||
console.log('Content saved:', content);
|
||||
// Here you could save to backend or local storage
|
||||
// For now, just log the content
|
||||
}, []);
|
||||
|
||||
return {
|
||||
// State
|
||||
research,
|
||||
@@ -167,6 +202,7 @@ export const useBlogWriterState = () => {
|
||||
researchCoverage,
|
||||
researchTitles,
|
||||
aiGeneratedTitles,
|
||||
outlineConfirmed,
|
||||
|
||||
// Setters
|
||||
setResearch,
|
||||
@@ -185,6 +221,7 @@ export const useBlogWriterState = () => {
|
||||
setResearchCoverage,
|
||||
setResearchTitles,
|
||||
setAiGeneratedTitles,
|
||||
setOutlineConfirmed,
|
||||
|
||||
// Handlers
|
||||
handleResearchComplete,
|
||||
@@ -193,6 +230,10 @@ export const useBlogWriterState = () => {
|
||||
handleSectionGenerated,
|
||||
handleContinuityRefresh,
|
||||
handleTitleSelect,
|
||||
handleCustomTitle
|
||||
handleCustomTitle,
|
||||
handleOutlineConfirmed,
|
||||
handleOutlineRefined,
|
||||
handleContentUpdate,
|
||||
handleContentSave
|
||||
};
|
||||
};
|
||||
|
||||
@@ -37,26 +37,37 @@ export function usePolling(
|
||||
const [result, setResult] = useState<any>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
// Debug state changes
|
||||
useEffect(() => {
|
||||
console.log('Polling state changed:', { isPolling, currentStatus, progressCount: progressMessages.length });
|
||||
}, [isPolling, currentStatus, progressMessages.length]);
|
||||
|
||||
|
||||
const intervalRef = useRef<NodeJS.Timeout | null>(null);
|
||||
const attemptsRef = useRef(0);
|
||||
const currentTaskIdRef = useRef<string | null>(null);
|
||||
|
||||
const stopPolling = useCallback(() => {
|
||||
console.log('stopPolling called');
|
||||
if (intervalRef.current) {
|
||||
clearInterval(intervalRef.current);
|
||||
intervalRef.current = null;
|
||||
}
|
||||
console.log('Setting isPolling to false');
|
||||
setIsPolling(false);
|
||||
attemptsRef.current = 0;
|
||||
currentTaskIdRef.current = null;
|
||||
}, []);
|
||||
|
||||
const startPolling = useCallback((taskId: string) => {
|
||||
console.log('startPolling called with taskId:', taskId);
|
||||
if (isPolling) {
|
||||
console.log('Already polling, stopping first');
|
||||
stopPolling();
|
||||
}
|
||||
|
||||
currentTaskIdRef.current = taskId;
|
||||
console.log('Setting isPolling to true');
|
||||
setIsPolling(true);
|
||||
setCurrentStatus('pending');
|
||||
setProgressMessages([]);
|
||||
@@ -118,7 +129,7 @@ export function usePolling(
|
||||
// Start polling immediately, then at intervals
|
||||
poll();
|
||||
intervalRef.current = setInterval(poll, interval);
|
||||
}, [isPolling, interval, maxAttempts, onProgress, onComplete, onError, pollFunction, stopPolling, progressMessages.length]);
|
||||
}, [isPolling, interval, onProgress, onComplete, onError, pollFunction, stopPolling, progressMessages.length]);
|
||||
|
||||
// Cleanup on unmount
|
||||
useEffect(() => {
|
||||
@@ -146,3 +157,12 @@ export function useResearchPolling(options: UsePollingOptions = {}) {
|
||||
export function useOutlinePolling(options: UsePollingOptions = {}) {
|
||||
return usePolling(blogWriterApi.pollOutlineStatus, options);
|
||||
}
|
||||
|
||||
export function useMediumGenerationPolling(options: UsePollingOptions = {}) {
|
||||
// Lazy import to avoid circular: poll function from mediumBlogApi
|
||||
const pollFn = (taskId: string) => import('../services/blogWriterApi').then(m => m.mediumBlogApi.pollMediumGeneration(taskId));
|
||||
// Wrap to satisfy type
|
||||
const wrapped = (taskId: string) => pollFn(taskId) as unknown as Promise<TaskStatusResponse>;
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
return usePolling(wrapped, options);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user