Pages corrections pages missions
This commit is contained in:
parent
5395be8a3a
commit
41731dae73
@ -44,6 +44,15 @@ export const Editor: React.FC<EditorProps> = ({ note, onSave, currentFolder = 'N
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchNoteContent = async () => {
|
const fetchNoteContent = async () => {
|
||||||
if (note?.id) {
|
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 content is already provided (e.g., for mission files), use it directly
|
||||||
if (note.content !== undefined && note.content !== '') {
|
if (note.content !== undefined && note.content !== '') {
|
||||||
setContent(note.content);
|
setContent(note.content);
|
||||||
@ -78,10 +87,32 @@ export const Editor: React.FC<EditorProps> = ({ note, onSave, currentFolder = 'N
|
|||||||
router.push('/signin');
|
router.push('/signin');
|
||||||
return;
|
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) {
|
if (!response.ok) {
|
||||||
const errorData = await response.json().catch(() => ({}));
|
const errorData = await response.json().catch(() => ({}));
|
||||||
const errorMessage = errorData.message || errorData.error || `Failed to fetch note content: ${response.status}`;
|
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();
|
const data = await response.json();
|
||||||
setContent(data.content || '');
|
setContent(data.content || '');
|
||||||
@ -90,8 +121,15 @@ export const Editor: React.FC<EditorProps> = ({ note, onSave, currentFolder = 'N
|
|||||||
noteContentCache.set(note.id, data.content || '');
|
noteContentCache.set(note.id, data.content || '');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching note content:', 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.';
|
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 {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user