diff --git a/package-lock.json b/package-lock.json index f803556..9bec7d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,6 +19,7 @@ "@types/node": "^16.18.12", "@types/react": "^18.0.28", "@types/react-dom": "^18.0.11", + "axios": "^1.3.3", "localforage": "^1.10.0", "match-sorter": "^6.3.1", "react": "^18.2.0", @@ -5262,6 +5263,29 @@ "node": ">=4" } }, + "node_modules/axios": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.3.3.tgz", + "integrity": "sha512-eYq77dYIFS77AQlhzEL937yUBSepBfPIe8FcgEDN35vMNZKMrs81pgnyrQpwfy4NF4b4XWX1Zgx7yX+25w8QJA==", + "dependencies": { + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, + "node_modules/axios/node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/axobject-query": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-3.1.1.tgz", @@ -14353,6 +14377,11 @@ "node": ">= 0.10" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, "node_modules/psl": { "version": "1.9.0", "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz", diff --git a/package.json b/package.json index a99d56b..fee4f50 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "@types/node": "^16.18.12", "@types/react": "^18.0.28", "@types/react-dom": "^18.0.11", + "axios": "^1.3.3", "localforage": "^1.10.0", "match-sorter": "^6.3.1", "react": "^18.2.0", diff --git a/src/Components/Note/NoteMapper/NoteMapper.tsx b/src/Components/Note/NoteMapper/NoteMapper.tsx new file mode 100644 index 0000000..0217761 --- /dev/null +++ b/src/Components/Note/NoteMapper/NoteMapper.tsx @@ -0,0 +1,65 @@ +import * as React from "react"; +import styles from "../../../styles"; +import { useEffect, useState } from "react"; +import { useNavigate } from "react-router-dom"; +import Note from "../Note"; +import { Button } from "@mui/material"; + +export default function NoteMapper() { + const navigate = useNavigate(); + const [notes, setNotes] = useState([]); + 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); + }) + .catch((err) => { + setError(true); + console.log(err.message); + seterrormessage(err.message); + }); + }, []); + if (error) { + return ( +
+

404

+

{errormessage}

+
+ ); + } + if (!notes) { +
+

No notes exist yet

+

Make one!

+ +
; + } + return ( + <> + {notes.map((note: { title: string; content: string }) => ( + + ))} + + + ); +} diff --git a/src/Routes/Home/Home.tsx b/src/Routes/Home/Home.tsx index a78f4b1..4ffa7a3 100644 --- a/src/Routes/Home/Home.tsx +++ b/src/Routes/Home/Home.tsx @@ -1,11 +1,13 @@ import styles from "../../styles"; import { Button } from "@mui/material"; -import { useNavigate } from "react-router-dom"; + import Note from "../../Components/Note/Note"; import Header from "../../Components/Note/Header/Header"; +import { useEffect, useState } from "react"; +import NoteMapper from "../../Components/Note/NoteMapper/NoteMapper"; export default function Home() { - const navigate = useNavigate(); + const [notes, setNotes] = useState(); const notes_sample = [ { title: "note1", content: "notes are great!" }, { title: "note2", content: "notes are awesome!" }, @@ -13,20 +15,12 @@ export default function Home() { return (
+ {/*} {notes_sample.map((note) => ( ))} -
- -
+ {*/} +
); } diff --git a/src/Routes/NewNote/NewNote.tsx b/src/Routes/NewNote/NewNote.tsx index 2c9f762..41a6e9f 100644 --- a/src/Routes/NewNote/NewNote.tsx +++ b/src/Routes/NewNote/NewNote.tsx @@ -1,25 +1,52 @@ import styles from "../../styles"; import { Button } from "@mui/material"; import { useNavigate } from "react-router-dom"; +import { useState } from "react"; import Header from "../../Components/Note/Header/Header"; +import axios from "axios"; +import { title } from "process"; +export interface input { + e: React.ChangeEvent; +} export default function NewNote() { const navigate = useNavigate(); + const [note, setNote] = useState({ + title: "", + content: "", + }); return (

New Note

- +
+

Title: 

+ { + setNote({ ...note, title: e.target.value }); + }} + maxLength={20} + /> +
-

Content

-