refactor(Index.tsx): remove unused AbortController state and logic from text correction
This commit is contained in:
@@ -124,7 +124,6 @@ $current`);
|
|||||||
const [correctedContent, setCorrectedContent] = useState('');
|
const [correctedContent, setCorrectedContent] = useState('');
|
||||||
const [previousNoteCorrectedContent, setPreviousNoteCorrectedContent] = useState('');
|
const [previousNoteCorrectedContent, setPreviousNoteCorrectedContent] = useState('');
|
||||||
const [correctionTimeout, setCorrectionTimeout] = useState<NodeJS.Timeout>();
|
const [correctionTimeout, setCorrectionTimeout] = useState<NodeJS.Timeout>();
|
||||||
const [correctionAbortController, setCorrectionAbortController] = useState<AbortController | null>(null);
|
|
||||||
|
|
||||||
const { resolvedTheme, setTheme } = useTheme();
|
const { resolvedTheme, setTheme } = useTheme();
|
||||||
|
|
||||||
@@ -339,38 +338,23 @@ $current`);
|
|||||||
|
|
||||||
// Debounced text correction for previous note
|
// Debounced text correction for previous note
|
||||||
const debouncedCorrectPreviousNote = (content: string) => {
|
const debouncedCorrectPreviousNote = (content: string) => {
|
||||||
// Cancel any pending correction request
|
|
||||||
if (correctionAbortController) {
|
|
||||||
try {
|
|
||||||
correctionAbortController.abort();
|
|
||||||
} catch (error) {
|
|
||||||
// Ignore abort errors - the controller might already be aborted
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (correctionTimeout) {
|
if (correctionTimeout) {
|
||||||
clearTimeout(correctionTimeout);
|
clearTimeout(correctionTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create new AbortController for this request
|
|
||||||
const abortController = new AbortController();
|
|
||||||
setCorrectionAbortController(abortController);
|
|
||||||
|
|
||||||
const timeout = setTimeout(async () => {
|
const timeout = setTimeout(async () => {
|
||||||
if (content.trim()) {
|
if (content.trim()) {
|
||||||
try {
|
try {
|
||||||
addDebugInfo('Correcting previous note text...');
|
addDebugInfo('Correcting previous note text...');
|
||||||
const corrected = await correctText(content, abortController);
|
const corrected = await correctText(content);
|
||||||
|
addDebugInfo(`Received correction: ${corrected.substring(0, 50)}...`);
|
||||||
setPreviousNoteCorrectedContent(corrected);
|
setPreviousNoteCorrectedContent(corrected);
|
||||||
|
addDebugInfo('Previous note corrected content set');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error instanceof Error && error.name === 'AbortError') {
|
|
||||||
addDebugInfo('Previous note correction cancelled');
|
|
||||||
return; // Don't set empty content for aborted requests
|
|
||||||
} else {
|
|
||||||
console.error('Previous note text correction failed:', error);
|
console.error('Previous note text correction failed:', error);
|
||||||
|
addDebugInfo(`Correction error: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
||||||
setPreviousNoteCorrectedContent('');
|
setPreviousNoteCorrectedContent('');
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
setPreviousNoteCorrectedContent('');
|
setPreviousNoteCorrectedContent('');
|
||||||
}
|
}
|
||||||
@@ -380,7 +364,7 @@ $current`);
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Correct text using Ollama
|
// Correct text using Ollama
|
||||||
const correctText = async (content: string, abortController?: AbortController): Promise<string> => {
|
const correctText = async (content: string): Promise<string> => {
|
||||||
try {
|
try {
|
||||||
const response = await fetchWithTiming(`${ollamaEndpoint}/api/generate`, {
|
const response = await fetchWithTiming(`${ollamaEndpoint}/api/generate`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -406,7 +390,6 @@ ${content}`,
|
|||||||
keep_alive: ollamaKeepAlive,
|
keep_alive: ollamaKeepAlive,
|
||||||
temperature: 0.1,
|
temperature: 0.1,
|
||||||
}),
|
}),
|
||||||
signal: abortController?.signal,
|
|
||||||
}, 'Correct Text');
|
}, 'Correct Text');
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@@ -421,7 +404,7 @@ ${content}`,
|
|||||||
throw new Error('Empty response from Ollama - check if model is loaded');
|
throw new Error('Empty response from Ollama - check if model is loaded');
|
||||||
}
|
}
|
||||||
|
|
||||||
addDebugInfo(`Text corrected successfully`);
|
addDebugInfo(`Text corrected successfully: ${correctedText.substring(0, 50)}...`);
|
||||||
return correctedText;
|
return correctedText;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error correcting text:', error);
|
console.error('Error correcting text:', error);
|
||||||
@@ -1189,16 +1172,6 @@ ${content}`,
|
|||||||
const reversedDelta = -delta;
|
const reversedDelta = -delta;
|
||||||
const newIndex = Math.max(0, Math.min(currentNoteIndex + reversedDelta, noteCache.length - 1));
|
const newIndex = Math.max(0, Math.min(currentNoteIndex + reversedDelta, noteCache.length - 1));
|
||||||
if (newIndex !== currentNoteIndex && noteCache[newIndex]) {
|
if (newIndex !== currentNoteIndex && noteCache[newIndex]) {
|
||||||
// Cancel any pending correction request before changing notes
|
|
||||||
if (correctionAbortController) {
|
|
||||||
try {
|
|
||||||
correctionAbortController.abort();
|
|
||||||
} catch (error) {
|
|
||||||
// Ignore abort errors - the controller might already be aborted
|
|
||||||
}
|
|
||||||
setCorrectionAbortController(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
setCurrentNoteIndex(newIndex);
|
setCurrentNoteIndex(newIndex);
|
||||||
setPreviousNote(noteCache[newIndex]);
|
setPreviousNote(noteCache[newIndex]);
|
||||||
setIsPreviousNoteModified(false);
|
setIsPreviousNoteModified(false);
|
||||||
@@ -1219,9 +1192,15 @@ ${content}`,
|
|||||||
// Handle wheel event for previous note navigation
|
// Handle wheel event for previous note navigation
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleWheel = (e: WheelEvent) => {
|
const handleWheel = (e: WheelEvent) => {
|
||||||
if (previousNoteRef.current?.contains(e.target as Node)) {
|
// Check if we're in the previous note area (either left or right pane)
|
||||||
|
const target = e.target as HTMLElement;
|
||||||
|
const isInPreviousNoteArea = previousNoteRef.current?.contains(target) ||
|
||||||
|
target.closest('[data-previous-note-area]');
|
||||||
|
|
||||||
|
if (isInPreviousNoteArea) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const delta = e.deltaY > 0 ? 1 : -1;
|
const delta = e.deltaY > 0 ? 1 : -1;
|
||||||
|
addDebugInfo(`Previous note scroll triggered: delta=${delta}`);
|
||||||
handlePreviousNoteScroll(delta);
|
handlePreviousNoteScroll(delta);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -1385,14 +1364,7 @@ ${content}`,
|
|||||||
if (correctionTimeout) {
|
if (correctionTimeout) {
|
||||||
clearTimeout(correctionTimeout);
|
clearTimeout(correctionTimeout);
|
||||||
}
|
}
|
||||||
// Cancel any pending correction request on cleanup
|
// Cleanup complete
|
||||||
if (correctionAbortController) {
|
|
||||||
try {
|
|
||||||
correctionAbortController.abort();
|
|
||||||
} catch (error) {
|
|
||||||
// Ignore abort errors - the controller might already be aborted
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}, [currentNote, previousNote, scratchPad, isPreviousNoteModified, isSearchOpen, isGotoOpen, isCleanupOpen]);
|
}, [currentNote, previousNote, scratchPad, isPreviousNoteModified, isSearchOpen, isGotoOpen, isCleanupOpen]);
|
||||||
|
|
||||||
@@ -2516,6 +2488,7 @@ ${content}`,
|
|||||||
{/* Previous Note - Top Half - Split Layout */}
|
{/* Previous Note - Top Half - Split Layout */}
|
||||||
<div
|
<div
|
||||||
ref={previousNoteRef}
|
ref={previousNoteRef}
|
||||||
|
data-previous-note-area
|
||||||
className="flex-1 flex gap-4 overflow-hidden cursor-pointer select-none"
|
className="flex-1 flex gap-4 overflow-hidden cursor-pointer select-none"
|
||||||
>
|
>
|
||||||
{/* Left Side - Original Previous Note */}
|
{/* Left Side - Original Previous Note */}
|
||||||
@@ -2574,6 +2547,8 @@ ${content}`,
|
|||||||
if (autoGenerateTags) {
|
if (autoGenerateTags) {
|
||||||
debouncedGenerateTags(newContent, currentNoteIndex);
|
debouncedGenerateTags(newContent, currentNoteIndex);
|
||||||
}
|
}
|
||||||
|
// Debounced text correction for previous notes
|
||||||
|
debouncedCorrectPreviousNote(newContent);
|
||||||
if (newContent.trim() === '') {
|
if (newContent.trim() === '') {
|
||||||
deleteNote(previousNote.id);
|
deleteNote(previousNote.id);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user