Pages corrections pages missions

This commit is contained in:
alma 2026-01-16 15:42:48 +01:00
parent 5395be8a3a
commit 41731dae73

View File

@ -44,6 +44,15 @@ export const Editor: React.FC<EditorProps> = ({ note, onSave, currentFolder = 'N
useEffect(() => {
const fetchNoteContent = async () => {
if (note?.id) {
// Skip fetching if id is temporary (starts with 'temp-')
// Temporary ids are used for new notes that haven't been saved yet
if (note.id.startsWith('temp-')) {
console.log(`Skipping fetch for temporary note id: ${note.id}`);
setIsLoading(false);
setContent(note.content || '');
return;
}
// If content is already provided (e.g., for mission files), use it directly
if (note.content !== undefined && note.content !== '') {
setContent(note.content);
@ -78,10 +87,32 @@ export const Editor: React.FC<EditorProps> = ({ note, onSave, currentFolder = 'N
router.push('/signin');
return;
}
if (response.status === 404) {
// File not found - this is normal for new notes that haven't been saved yet
console.log(`Note not found (404) for id: ${note.id}, treating as new note`);
setContent('');
setIsLoading(false);
return;
}
if (response.status === 403) {
// Unauthorized access - don't show error, just clear content
console.warn(`Unauthorized access to note: ${note.id}`);
setContent('');
setError(null); // Don't show error for unauthorized access
setIsLoading(false);
return;
}
if (!response.ok) {
const errorData = await response.json().catch(() => ({}));
const errorMessage = errorData.message || errorData.error || `Failed to fetch note content: ${response.status}`;
throw new Error(errorMessage);
// Only show error for non-404/403 errors
if (response.status !== 404 && response.status !== 403) {
throw new Error(errorMessage);
} else {
setContent('');
setIsLoading(false);
return;
}
}
const data = await response.json();
setContent(data.content || '');
@ -90,8 +121,15 @@ export const Editor: React.FC<EditorProps> = ({ note, onSave, currentFolder = 'N
noteContentCache.set(note.id, data.content || '');
} catch (error) {
console.error('Error fetching note content:', error);
// Only show error if it's not a 404 or 403 (which we handle above)
const errorMessage = error instanceof Error ? error.message : 'Failed to load note content. Please try again later.';
setError(errorMessage);
// Don't show error for file not found or unauthorized - these are handled above
if (!errorMessage.includes('404') && !errorMessage.includes('403') && !errorMessage.includes('File not found') && !errorMessage.includes('Unauthorized')) {
setError(errorMessage);
} else {
setError(null);
setContent('');
}
} finally {
setIsLoading(false);
}