From 3f5fb0f79e7ce62430b2fe62fa9f0c1849310427 Mon Sep 17 00:00:00 2001 From: keannu125 Date: Thu, 23 Feb 2023 22:29:47 +0800 Subject: [PATCH] Fixed empty notes prompt not working --- src/Components/Note/NoteMapper/NoteMapper.tsx | 52 ++++++++++--------- src/Routes/NewNote/NewNote.tsx | 2 +- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/Components/Note/NoteMapper/NoteMapper.tsx b/src/Components/Note/NoteMapper/NoteMapper.tsx index 0217761..faf2484 100644 --- a/src/Components/Note/NoteMapper/NoteMapper.tsx +++ b/src/Components/Note/NoteMapper/NoteMapper.tsx @@ -4,23 +4,22 @@ import { useEffect, useState } from "react"; import { useNavigate } from "react-router-dom"; import Note from "../Note"; import { Button } from "@mui/material"; +import axios from "axios"; export default function NoteMapper() { const navigate = useNavigate(); - const [notes, setNotes] = useState([]); + const [notes, setNotes] = useState([{ title: "", content: "" }]); const [error, setError] = useState(false); const [errormessage, seterrormessage] = useState(""); useEffect(() => { - fetch("localhost:8000/notes") - .then((res) => res.json()) - .then((data) => { - console.log(data); - setNotes(data); + axios + .get("http://localhost:8000/notes/") + .then((res) => { + setNotes(res.data); }) .catch((err) => { setError(true); - console.log(err.message); - seterrormessage(err.message); + seterrormessage(err); }); }, []); if (error) { @@ -31,26 +30,29 @@ export default function NoteMapper() { ); } - if (!notes) { -
-

No notes exist yet

-

Make one!

- -
; + if (notes.length === 0) { + return ( +
+

No notes exist yet

+

Make one!

+ +
+ ); } return ( <> - {notes.map((note: { title: string; content: string }) => ( - - ))} + {notes.map((note: { title: string; content: string }, i) => { + return ; + })} +