Pages corrections journal
This commit is contained in:
parent
c4af180d30
commit
886acb7c18
@ -384,7 +384,7 @@ export default function CarnetPage() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Fetch notes based on the selected folder
|
// Fetch notes based on the selected folder
|
||||||
const fetchNotes = async () => {
|
const fetchNotes = async (skipCache = false) => {
|
||||||
if (!session?.user?.id) {
|
if (!session?.user?.id) {
|
||||||
setIsLoadingNotes(false);
|
setIsLoadingNotes(false);
|
||||||
return;
|
return;
|
||||||
@ -395,25 +395,26 @@ export default function CarnetPage() {
|
|||||||
|
|
||||||
// Convert folder name to lowercase for consistent storage access
|
// Convert folder name to lowercase for consistent storage access
|
||||||
const folderLowercase = selectedFolder.toLowerCase();
|
const folderLowercase = selectedFolder.toLowerCase();
|
||||||
console.log(`Fetching notes from folder: ${folderLowercase}`);
|
console.log(`[fetchNotes] Fetching notes from folder: ${folderLowercase}, skipCache: ${skipCache}`);
|
||||||
|
|
||||||
// Check cache first
|
// Check cache first (unless skipCache is true)
|
||||||
const cacheKey = `${session.user.id}-${folderLowercase}`;
|
const cacheKey = `${session.user.id}-${folderLowercase}`;
|
||||||
|
if (!skipCache) {
|
||||||
const cachedNotes = notesCache.get<Note[]>(cacheKey);
|
const cachedNotes = notesCache.get<Note[]>(cacheKey);
|
||||||
|
|
||||||
if (cachedNotes) {
|
if (cachedNotes) {
|
||||||
console.log(`Using cached notes for ${folderLowercase} folder`);
|
console.log(`[fetchNotes] Using cached notes for ${folderLowercase} folder`);
|
||||||
setNotes(cachedNotes);
|
setNotes(cachedNotes);
|
||||||
setIsLoadingNotes(false);
|
setIsLoadingNotes(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Fetch from API
|
// Fetch from API
|
||||||
const response = await fetch(`/api/storage/files?folder=${folderLowercase}`);
|
const response = await fetch(`/api/storage/files?folder=${folderLowercase}`);
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
console.log(`Fetched ${data.length} files from ${folderLowercase} folder`, data);
|
console.log(`[fetchNotes] Fetched ${data.length} files from ${folderLowercase} folder`, data);
|
||||||
|
|
||||||
// Map API response to Note format
|
// Map API response to Note format
|
||||||
// API returns: { key, name, size, lastModified }
|
// API returns: { key, name, size, lastModified }
|
||||||
@ -433,20 +434,25 @@ export default function CarnetPage() {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`Mapped ${mappedNotes.length} notes from ${folderLowercase} folder`);
|
// Remove duplicates based on id
|
||||||
|
const uniqueNotes = mappedNotes.filter((note, index, self) =>
|
||||||
|
index === self.findIndex(n => n.id === note.id)
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(`[fetchNotes] Mapped ${uniqueNotes.length} unique notes from ${folderLowercase} folder (${mappedNotes.length} total before deduplication)`);
|
||||||
|
|
||||||
// Update state
|
// Update state
|
||||||
setNotes(mappedNotes);
|
setNotes(uniqueNotes);
|
||||||
|
|
||||||
// Update cache
|
// Update cache
|
||||||
notesCache.set(cacheKey, mappedNotes);
|
notesCache.set(cacheKey, uniqueNotes);
|
||||||
} else {
|
} else {
|
||||||
const errorData = await response.json().catch(() => ({}));
|
const errorData = await response.json().catch(() => ({}));
|
||||||
console.error('Error fetching notes:', errorData.message || response.statusText);
|
console.error('[fetchNotes] Error fetching notes:', errorData.message || response.statusText);
|
||||||
setNotes([]);
|
setNotes([]);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching notes:', error);
|
console.error('[fetchNotes] Error fetching notes:', error);
|
||||||
setNotes([]);
|
setNotes([]);
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoadingNotes(false);
|
setIsLoadingNotes(false);
|
||||||
@ -492,8 +498,10 @@ export default function CarnetPage() {
|
|||||||
noteContentCache.set(payload.id, payload.content);
|
noteContentCache.set(payload.id, payload.content);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Refresh the list of notes
|
// Refresh the list of notes (skip cache to get fresh data)
|
||||||
fetchNotes();
|
// Note: onRefresh from Editor will also call fetchNotes, but with skipCache=false
|
||||||
|
// So we call it with skipCache=true here to ensure fresh data
|
||||||
|
fetchNotes(true);
|
||||||
} else {
|
} else {
|
||||||
const errorData = await response.json().catch(() => ({}));
|
const errorData = await response.json().catch(() => ({}));
|
||||||
const errorMessage = errorData.message || errorData.error || 'Failed to save note';
|
const errorMessage = errorData.message || errorData.error || 'Failed to save note';
|
||||||
|
|||||||
@ -180,7 +180,9 @@ export const Editor: React.FC<EditorProps> = ({ note, onSave, currentFolder = 'N
|
|||||||
...savedNote,
|
...savedNote,
|
||||||
content
|
content
|
||||||
});
|
});
|
||||||
onRefresh?.();
|
// Note: onRefresh is called, but handleSaveNote already calls fetchNotes
|
||||||
|
// So we don't need to call onRefresh here to avoid double fetch
|
||||||
|
// onRefresh?.();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error saving note:', error);
|
console.error('Error saving note:', error);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user