Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions web/src/services/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const saveNote = async (note: DiaryEntry) => {
return localNote;
};

const fetchNote = async (noteId: string): Promise<DiaryEntry | undefined> => {
const fetchNote = async (noteId: string): Promise<DiaryEntry> => {
console.log("fetching note", noteId);
const db = await openDatabase();
let cachedNote = await db.get('notes', noteId);
Expand All @@ -138,7 +138,16 @@ const fetchNote = async (noteId: string): Promise<DiaryEntry | undefined> => {
console.error(getApiErrorMessage(error, "Network error"));
}
}
return cachedNote
// Return cached note or create a default empty entry
if (cachedNote) {
return cachedNote;
}
// Return a default empty diary entry for new notes
return {
noteId,
note: '',
dirty: false,
};
};

if (typeof window !== 'undefined') {
Expand Down