loader and action in the notes Route:
export async function loader() {
const notes = await getStoredNotes();
return notes;
}
export async function action({ request }: ActionFunctionArgs) {
const formData = await request.formData();
const noteData = {
title: formData.get('title'),
content: formData.get('content'),
id: new Date().toISOString(),
} as NoteType;
if (noteData.title.trim().length < 5) {
return { message: 'Title must be at least 5 characters long' };
}
const existingNotes = await getStoredNotes();
const updatedNotes = existingNotes.concat(noteData);
await storeNotes(updatedNotes);
//await new Promise((resolve) => setTimeout(() => resolve(true), 2000));
return redirect('/notes');
}