diff --git a/src/Components/Api/Api.tsx b/src/Components/Api/Api.tsx index 52d06c3..007e5a1 100644 --- a/src/Components/Api/Api.tsx +++ b/src/Components/Api/Api.tsx @@ -1,11 +1,24 @@ import axios from "axios"; export function GetNotes() { - return axios.get("http://localhost:8000/api/v1/notes/").then((res) => { - return res.data; + return axios.get("http://localhost:8000/api/v1/notes/").then((response) => { + return response.data; }); - /*return fetch("http://localhost:8000/api/v1/notes/").then((res) => { - console.log(res.body); - return res.json(); - });*/ +} + +export interface note { + title: string; + content: string; +} + +export function AddNote(note: note) { + return axios + .post("http://localhost:8000/api/v1/notes/", note) + .then((response) => { + return response.data; + }); +} + +export function DeleteNote(id: number) { + return axios.delete("http://localhost:8000/api/v1/notes/" + id + "/"); } diff --git a/src/Components/Note/Note.tsx b/src/Components/Note/Note.tsx index f61403c..9d2aae2 100644 --- a/src/Components/Note/Note.tsx +++ b/src/Components/Note/Note.tsx @@ -2,7 +2,8 @@ import * as React from "react"; import styles from "../../styles"; import { Button } from "@mui/material"; import axios from "axios"; -import { useQueryClient } from "react-query"; +import { useMutation, useQueryClient } from "react-query"; +import { DeleteNote } from "../Api/Api"; export interface props { title: string; @@ -12,6 +13,12 @@ export interface props { } export default function Note(props: props) { const queryClient = useQueryClient(); + const mutation = useMutation({ + mutationFn: DeleteNote, + onSuccess: () => { + queryClient.invalidateQueries("notes"); + }, + }); return (