From c2f59420534fce7bc88f7a1b2c208e84c0ed94d4 Mon Sep 17 00:00:00 2001 From: keannu125 Date: Sun, 16 Apr 2023 18:48:29 +0800 Subject: [PATCH] Added delete note functionality --- src/Components/Note/Note.tsx | 34 ++++++++++++++++++++++++++++++++++ src/Routes/Note/Note.tsx | 10 ++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/Routes/Note/Note.tsx diff --git a/src/Components/Note/Note.tsx b/src/Components/Note/Note.tsx index 19657c0..3610a08 100644 --- a/src/Components/Note/Note.tsx +++ b/src/Components/Note/Note.tsx @@ -2,8 +2,19 @@ import * as React from "react"; import { View, Text, TextInput, ScrollView } from "react-native"; import styles from "../../styles"; import { NoteProps } from "../../Interfaces/Interfaces"; +import ButtonCentered from "../Buttons/ButtonCentered/ButtonCentered"; +import { useQueryClient, useMutation } from "react-query"; +import { DeleteNote } from "../Api/Api"; export default function Note(props: NoteProps) { + const queryClient = useQueryClient(); + const mutation = useMutation({ + mutationFn: DeleteNote, + onSuccess: () => { + queryClient.invalidateQueries("notes"); + queryClient.invalidateQueries("public_notes"); + }, + }); return ( @@ -19,6 +30,29 @@ export default function Note(props: NoteProps) { {props.content} + + { + console.log("Deleted note id " + props.id); + mutation.mutate(props.id); + }} + width={64} + > + + Delete Note + + + console.log("Edited note id " + props.id)} + width={64} + > + + Edit Note + + + ); } diff --git a/src/Routes/Note/Note.tsx b/src/Routes/Note/Note.tsx new file mode 100644 index 0000000..0e2ce6d --- /dev/null +++ b/src/Routes/Note/Note.tsx @@ -0,0 +1,10 @@ +import * as React from "react"; +import { View, Text } from "react-native"; + +export default function Note(id: number) { + return ( + + Note + + ); +}