mirror of
https://github.com/lemeow125/React-NotesApp.git
synced 2024-11-17 06:29:28 +08:00
Polished code and updateed url
This commit is contained in:
parent
26d6b64c4b
commit
9920738a33
4 changed files with 7 additions and 22 deletions
|
@ -20,7 +20,9 @@ export default function Note(props: props) {
|
||||||
style={styles.button_remove}
|
style={styles.button_remove}
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
axios.delete("http://localhost:8000/notes/" + props.id + "/");
|
axios.delete(
|
||||||
|
"http://localhost:8000/api/v1/notes/" + props.id + "/"
|
||||||
|
);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Remove Note
|
Remove Note
|
||||||
|
|
|
@ -10,17 +10,16 @@ export default function NoteMapper() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [notes, setNotes] = useState([]);
|
const [notes, setNotes] = useState([]);
|
||||||
const [error, setError] = useState(false);
|
const [error, setError] = useState(false);
|
||||||
const [errormessage, seterrormessage] = useState("");
|
|
||||||
function server_get() {
|
function server_get() {
|
||||||
axios
|
axios
|
||||||
.get("http://localhost:8000/notes/")
|
.get("http://localhost:8000/api/v1/notes/", { timeout: 50 })
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log("Server Response", res.data);
|
console.log("Server Response", res.data);
|
||||||
|
setError(false);
|
||||||
setNotes(res.data);
|
setNotes(res.data);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
setError(true);
|
setError(true);
|
||||||
seterrormessage(err);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -33,8 +32,7 @@ export default function NoteMapper() {
|
||||||
if (error) {
|
if (error) {
|
||||||
return (
|
return (
|
||||||
<div style={styles.note}>
|
<div style={styles.note}>
|
||||||
<p style={styles.text_medium}>404</p>
|
<p style={styles.text_medium}>Error contacting Notes server</p>
|
||||||
<p style={styles.text_medium}>{errormessage}</p>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -68,7 +66,6 @@ export default function NoteMapper() {
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
style={styles.button_add}
|
style={styles.button_add}
|
||||||
variant="contained"
|
variant="contained"
|
||||||
|
|
|
@ -1,24 +1,10 @@
|
||||||
import styles from "../../styles";
|
import styles from "../../styles";
|
||||||
import { Button } from "@mui/material";
|
|
||||||
|
|
||||||
import Note from "../../Components/Note/Note";
|
|
||||||
import Header from "../../Components/Header/Header";
|
import Header from "../../Components/Header/Header";
|
||||||
import { useEffect, useState } from "react";
|
|
||||||
import NoteMapper from "../../Components/NoteMapper/NoteMapper";
|
import NoteMapper from "../../Components/NoteMapper/NoteMapper";
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
const [notes, setNotes] = useState();
|
|
||||||
const notes_sample = [
|
|
||||||
{ title: "note1", content: "notes are great!" },
|
|
||||||
{ title: "note2", content: "notes are awesome!" },
|
|
||||||
];
|
|
||||||
return (
|
return (
|
||||||
<div style={styles.background}>
|
<div style={styles.background}>
|
||||||
<Header />
|
<Header />
|
||||||
{/*}
|
|
||||||
{notes_sample.map((note) => (
|
|
||||||
<Note title={note.title} content={note.content} />
|
|
||||||
))}
|
|
||||||
{*/}
|
|
||||||
<NoteMapper />
|
<NoteMapper />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -43,7 +43,7 @@ export default function NewNote() {
|
||||||
style={styles.button_add}
|
style={styles.button_add}
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
axios.post("http://localhost:8000/notes/", {
|
axios.post("http://localhost:8000/api/v1/notes/", {
|
||||||
title: note.title,
|
title: note.title,
|
||||||
content: note.content,
|
content: note.content,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue