mirror of
https://github.com/lemeow125/Reactnative-notesapp.git
synced 2024-11-17 06:29:27 +08:00
Added delete note functionality
This commit is contained in:
parent
c3b4816ce2
commit
c2f5942053
2 changed files with 44 additions and 0 deletions
|
@ -2,8 +2,19 @@ import * as React from "react";
|
||||||
import { View, Text, TextInput, ScrollView } from "react-native";
|
import { View, Text, TextInput, ScrollView } from "react-native";
|
||||||
import styles from "../../styles";
|
import styles from "../../styles";
|
||||||
import { NoteProps } from "../../Interfaces/Interfaces";
|
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) {
|
export default function Note(props: NoteProps) {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const mutation = useMutation({
|
||||||
|
mutationFn: DeleteNote,
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries("notes");
|
||||||
|
queryClient.invalidateQueries("public_notes");
|
||||||
|
},
|
||||||
|
});
|
||||||
return (
|
return (
|
||||||
<View style={styles.addnotecont}>
|
<View style={styles.addnotecont}>
|
||||||
<View style={styles.tle}>
|
<View style={styles.tle}>
|
||||||
|
@ -19,6 +30,29 @@ export default function Note(props: NoteProps) {
|
||||||
<Text style={styles.typeinput}>{props.content}</Text>
|
<Text style={styles.typeinput}>{props.content}</Text>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</View>
|
</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>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
10
src/Routes/Note/Note.tsx
Normal file
10
src/Routes/Note/Note.tsx
Normal 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>
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in a new issue