Added delete note functionality

This commit is contained in:
keannu125 2023-04-16 18:48:29 +08:00
parent c3b4816ce2
commit c2f5942053
2 changed files with 44 additions and 0 deletions

View file

@ -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 (
<View style={styles.addnotecont}>
<View style={styles.tle}>
@ -19,6 +30,29 @@ export default function Note(props: NoteProps) {
<Text style={styles.typeinput}>{props.content}</Text>
</ScrollView>
</View>
<View style={styles.flex_row}>
<ButtonCentered
color={"Red"}
onPress={() => {
console.log("Deleted note id " + props.id);
mutation.mutate(props.id);
}}
width={64}
>
<Text style={{ ...styles.text_white, ...{ fontSize: 16 } }}>
Delete Note
</Text>
</ButtonCentered>
<ButtonCentered
color={"Yellow"}
onPress={() => console.log("Edited note id " + props.id)}
width={64}
>
<Text style={{ ...styles.text_white, ...{ fontSize: 16 } }}>
Edit Note
</Text>
</ButtonCentered>
</View>
</View>
);
}

10
src/Routes/Note/Note.tsx Normal file
View file

@ -0,0 +1,10 @@
import * as React from "react";
import { View, Text } from "react-native";
export default function Note(id: number) {
return (
<View>
<Text>Note</Text>
</View>
);
}