From c2f59420534fce7bc88f7a1b2c208e84c0ed94d4 Mon Sep 17 00:00:00 2001 From: keannu125 Date: Sun, 16 Apr 2023 18:48:29 +0800 Subject: [PATCH 1/5] 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 + + ); +} From 3ee11b888a998662aceea35c003ccd346e414c43 Mon Sep 17 00:00:00 2001 From: keannu125 Date: Sun, 16 Apr 2023 19:34:19 +0800 Subject: [PATCH 2/5] Made notes editable --- App.tsx | 42 +++++------ src/Components/Note/Note.tsx | 9 ++- src/Routes/EditNote/EditNote.tsx | 119 +++++++++++++++++++++++++++++++ src/Routes/Note/Note.tsx | 10 --- src/styles.tsx | 5 +- 5 files changed, 150 insertions(+), 35 deletions(-) create mode 100644 src/Routes/EditNote/EditNote.tsx delete mode 100644 src/Routes/Note/Note.tsx diff --git a/App.tsx b/App.tsx index 62b43f4..e08a156 100644 --- a/App.tsx +++ b/App.tsx @@ -13,31 +13,31 @@ import Register from "./src/Routes/Register/Register"; import { Provider } from "react-redux"; import Store from "./src/Features/Redux/Store/Store"; import { QueryClient, QueryClientProvider } from "react-query"; - +import EditNote from "./src/Routes/EditNote/EditNote"; const Drawer = createDrawerNavigator(); const queryClient = new QueryClient(); export default function App() { return ( - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + ); -} \ No newline at end of file +} diff --git a/src/Components/Note/Note.tsx b/src/Components/Note/Note.tsx index 3610a08..e56b355 100644 --- a/src/Components/Note/Note.tsx +++ b/src/Components/Note/Note.tsx @@ -1,12 +1,14 @@ import * as React from "react"; import { View, Text, TextInput, ScrollView } from "react-native"; import styles from "../../styles"; -import { NoteProps } from "../../Interfaces/Interfaces"; +import { NoteProps, RootDrawerParamList } from "../../Interfaces/Interfaces"; import ButtonCentered from "../Buttons/ButtonCentered/ButtonCentered"; import { useQueryClient, useMutation } from "react-query"; import { DeleteNote } from "../Api/Api"; +import { useNavigation } from "@react-navigation/native"; export default function Note(props: NoteProps) { + const navigation = useNavigation(); const queryClient = useQueryClient(); const mutation = useMutation({ mutationFn: DeleteNote, @@ -45,7 +47,10 @@ export default function Note(props: NoteProps) { console.log("Edited note id " + props.id)} + onPress={() => { + navigation.navigate("EditNote", { noteId: props.id }); + console.log("Editing note id " + props.id); + }} width={64} > diff --git a/src/Routes/EditNote/EditNote.tsx b/src/Routes/EditNote/EditNote.tsx new file mode 100644 index 0000000..ecddbbd --- /dev/null +++ b/src/Routes/EditNote/EditNote.tsx @@ -0,0 +1,119 @@ +import * as React from "react"; +import { View, Text, TextInput } from "react-native"; +import styles from "../../styles"; +import Background from "../../Components/Background/Background"; +import { SafeAreaView } from "react-native-safe-area-context"; +import { useEffect, useState } from "react"; +import { TouchableOpacity } from "react-native"; +import { RootDrawerParamList } from "../../Interfaces/Interfaces"; +import { useNavigation } from "@react-navigation/native"; +import { useMutation, useQuery, useQueryClient } from "react-query"; +import { AddNote, GetNote, UpdateNote } from "../../Components/Api/Api"; + +export default function EditNote({ navigation, route }: any) { + const { noteId } = route.params; + const [note, setNote] = useState({ + title: "", + content: "", + public: true, + }); + async function retrieve() { + let a = await GetNote(noteId); + setNote(a); + return a; + } + const { data, isLoading, error } = useQuery("note", retrieve, { + retry: 0, + }); + useEffect(() => { + setNote(data); + }, [data]); + + const queryClient = useQueryClient(); + const mutation = useMutation({ + mutationFn: UpdateNote, + onSuccess: () => { + queryClient.invalidateQueries("notes"); + queryClient.invalidateQueries("public_notes"); + }, + }); + if (error) { + return ( + + + Error retrieving specific note + + + ); + } + if (isLoading) { + return ( + + + Loading note... + + + ); + } + if (data && note) { + return ( + + + Edit Note + + + + + { + setNote({ ...note, title: text }); + }} + maxLength={20} + /> + + + { + await setNote({ ...note, content: text }); + }} + /> + + { + try { + await mutation.mutate({ + title: note.title, + content: note.content, + id: noteId, + }); + navigation.navigate("Home"); + } catch (error) {} + console.log(note.content); + }} + > + SAVE + + { + navigation.navigate("Home"); + }} + > + CANCEL + + + + + ); + } +} diff --git a/src/Routes/Note/Note.tsx b/src/Routes/Note/Note.tsx deleted file mode 100644 index 0e2ce6d..0000000 --- a/src/Routes/Note/Note.tsx +++ /dev/null @@ -1,10 +0,0 @@ -import * as React from "react"; -import { View, Text } from "react-native"; - -export default function Note(id: number) { - return ( - - Note - - ); -} diff --git a/src/styles.tsx b/src/styles.tsx index 7b212a1..c53a371 100644 --- a/src/styles.tsx +++ b/src/styles.tsx @@ -158,9 +158,10 @@ const styles = StyleSheet.create({ }, typeinput: { color: "white", - flex: 1, - paddingBottom: 250, + marginBottom: 16, marginLeft: 5, + minHeight: 128, + maxHeight: 768, }, title: { color: "white", From 2559c72cd99fc4412fea1708a202c3b147d41fb1 Mon Sep 17 00:00:00 2001 From: keannu125 Date: Sun, 16 Apr 2023 19:41:13 +0800 Subject: [PATCH 3/5] Fixed 250 padding bottom jusko lord damn thicc & added public toggle to editnote --- src/Components/PublicNote/PublicNote.tsx | 37 +++++++ src/Components/PublicNotes/Notes.tsx | 3 +- src/Interfaces/Interfaces.tsx | 1 + src/Routes/EditNote/EditNote.tsx | 118 +++++++++++++---------- src/styles.tsx | 3 +- 5 files changed, 109 insertions(+), 53 deletions(-) create mode 100644 src/Components/PublicNote/PublicNote.tsx diff --git a/src/Components/PublicNote/PublicNote.tsx b/src/Components/PublicNote/PublicNote.tsx new file mode 100644 index 0000000..9eef3cc --- /dev/null +++ b/src/Components/PublicNote/PublicNote.tsx @@ -0,0 +1,37 @@ +import * as React from "react"; +import { View, Text, TextInput, ScrollView } from "react-native"; +import styles from "../../styles"; +import { NoteProps, RootDrawerParamList } from "../../Interfaces/Interfaces"; +import ButtonCentered from "../Buttons/ButtonCentered/ButtonCentered"; +import { useQueryClient, useMutation } from "react-query"; +import { DeleteNote } from "../Api/Api"; +import { useNavigation } from "@react-navigation/native"; + +export default function PublicNote(props: NoteProps) { + const navigation = useNavigation(); + const queryClient = useQueryClient(); + const mutation = useMutation({ + mutationFn: DeleteNote, + onSuccess: () => { + queryClient.invalidateQueries("notes"); + queryClient.invalidateQueries("public_notes"); + }, + }); + return ( + + + + + + + {props.content} + + + + ); +} diff --git a/src/Components/PublicNotes/Notes.tsx b/src/Components/PublicNotes/Notes.tsx index efc4850..82ab0c1 100644 --- a/src/Components/PublicNotes/Notes.tsx +++ b/src/Components/PublicNotes/Notes.tsx @@ -8,6 +8,7 @@ import { RootState } from "../../Features/Redux/Store/Store"; import { NoteProps, RootDrawerParamList } from "../../Interfaces/Interfaces"; import { useNavigation } from "@react-navigation/native"; import Note from "../Note/Note"; +import PublicNote from "../PublicNote/PublicNote"; export default function PublicNotes() { const navigation = useNavigation(); @@ -39,7 +40,7 @@ export default function PublicNotes() { {notes.map((note: NoteProps, index: number) => { return ( - Edit Note - - - - { - setNote({ ...note, title: text }); - }} - maxLength={20} - /> - - - { - await setNote({ ...note, content: text }); - }} - /> - - { - try { - await mutation.mutate({ - title: note.title, - content: note.content, - id: noteId, - }); - navigation.navigate("Home"); - } catch (error) {} - console.log(note.content); + + + { + setNote({ ...note, title: text }); }} - > - SAVE - - { - navigation.navigate("Home"); - }} - > - CANCEL - + maxLength={20} + /> - + + { + await setNote({ ...note, content: text }); + }} + /> + + + setNote({ ...note, public: !note.public })} + value={note.public} + /> + + Public? + + + { + try { + await mutation.mutate({ + title: note.title, + content: note.content, + public: note.public, + id: noteId, + }); + navigation.navigate("Home"); + } catch (error) {} + console.log(note.content); + }} + > + SAVE + + { + navigation.navigate("Home"); + }} + > + CANCEL + + ); } diff --git a/src/styles.tsx b/src/styles.tsx index c53a371..a77b043 100644 --- a/src/styles.tsx +++ b/src/styles.tsx @@ -180,7 +180,8 @@ const styles = StyleSheet.create({ addnotecont: { marginTop: 30, marginLeft: 22, - height: 500, + paddingBottom: 30, + minHeight: 500, width: 350, borderRadius: 25, backgroundColor: "black", From cecc63eb7e6bbfbca220a433b075da386646aa4a Mon Sep 17 00:00:00 2001 From: keannu125 Date: Sun, 16 Apr 2023 19:44:16 +0800 Subject: [PATCH 4/5] Removed unused code --- src/Components/PublicNote/PublicNote.tsx | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/Components/PublicNote/PublicNote.tsx b/src/Components/PublicNote/PublicNote.tsx index 9eef3cc..87e313e 100644 --- a/src/Components/PublicNote/PublicNote.tsx +++ b/src/Components/PublicNote/PublicNote.tsx @@ -1,22 +1,9 @@ import * as React from "react"; import { View, Text, TextInput, ScrollView } from "react-native"; import styles from "../../styles"; -import { NoteProps, RootDrawerParamList } from "../../Interfaces/Interfaces"; -import ButtonCentered from "../Buttons/ButtonCentered/ButtonCentered"; -import { useQueryClient, useMutation } from "react-query"; -import { DeleteNote } from "../Api/Api"; -import { useNavigation } from "@react-navigation/native"; +import { NoteProps } from "../../Interfaces/Interfaces"; export default function PublicNote(props: NoteProps) { - const navigation = useNavigation(); - const queryClient = useQueryClient(); - const mutation = useMutation({ - mutationFn: DeleteNote, - onSuccess: () => { - queryClient.invalidateQueries("notes"); - queryClient.invalidateQueries("public_notes"); - }, - }); return ( From ed9715c63fe7c3ce4d5957ab7caa3f9d8253f447 Mon Sep 17 00:00:00 2001 From: keannu125 Date: Sun, 16 Apr 2023 19:48:26 +0800 Subject: [PATCH 5/5] Added public toggle to add note and made it consistent with edit note --- src/Interfaces/Interfaces.tsx | 1 + src/Routes/EditNote/EditNote.tsx | 2 +- src/Routes/NewNote/NewNote.tsx | 130 ++++++++++++++++++------------- 3 files changed, 79 insertions(+), 54 deletions(-) diff --git a/src/Interfaces/Interfaces.tsx b/src/Interfaces/Interfaces.tsx index f03a912..3f31b60 100644 --- a/src/Interfaces/Interfaces.tsx +++ b/src/Interfaces/Interfaces.tsx @@ -59,6 +59,7 @@ export interface ActivationParams { export interface AddNoteParams { title: string; content: string; + public: boolean; } export interface UpdateNoteParams { diff --git a/src/Routes/EditNote/EditNote.tsx b/src/Routes/EditNote/EditNote.tsx index b062aa0..3189e80 100644 --- a/src/Routes/EditNote/EditNote.tsx +++ b/src/Routes/EditNote/EditNote.tsx @@ -15,7 +15,7 @@ export default function EditNote({ navigation, route }: any) { const [note, setNote] = useState({ title: "", content: "", - public: true, + public: false, }); async function retrieve() { let a = await GetNote(noteId); diff --git a/src/Routes/NewNote/NewNote.tsx b/src/Routes/NewNote/NewNote.tsx index e10b50c..54a0fef 100644 --- a/src/Routes/NewNote/NewNote.tsx +++ b/src/Routes/NewNote/NewNote.tsx @@ -1,10 +1,10 @@ -import * as React from 'react'; -import {View, Text, TextInput} from 'react-native'; -import styles from '../../styles'; -import Background from '../../Components/Background/Background'; -import { SafeAreaView } from 'react-native-safe-area-context'; +import * as React from "react"; +import { View, Text, TextInput, Switch } from "react-native"; +import styles from "../../styles"; +import Background from "../../Components/Background/Background"; +import { SafeAreaView } from "react-native-safe-area-context"; import { useState } from "react"; -import {TouchableOpacity,} from "react-native"; +import { TouchableOpacity } from "react-native"; import { RootDrawerParamList } from "../../Interfaces/Interfaces"; import { useNavigation } from "@react-navigation/native"; import { useMutation, useQueryClient } from "react-query"; @@ -14,10 +14,11 @@ export default function NewNote() { const [note, setNote] = useState({ title: "", content: "", + public: false, }); const navigation = useNavigation(); - + const queryClient = useQueryClient(); const mutation = useMutation({ mutationFn: AddNote, @@ -28,54 +29,77 @@ export default function NewNote() { return ( - New Note - - - - { - setNote({ ...note, title: text }); + + New Note + + + + + { + setNote({ ...note, title: text }); + }} + maxLength={20} + /> + + + { + await setNote({ ...note, content: text }); + }} + /> + + - - - { - await setNote({ ...note, content: text }); + > + setNote({ ...note, public: !note.public })} + value={note.public} + /> + + Public? + + + { + try { + await mutation.mutate({ + title: note.title, + content: note.content, + public: note.public, + }); + navigation.navigate("Home"); + } catch (error) {} + console.log(note.content); }} - /> - - { - try { - await mutation.mutate({ - title: note.title, - content: note.content, - }); - navigation.navigate("Home"); - } catch (error) {} - console.log(note.content) - }}> - - SAVE - - { - navigation.navigate("Home"); - }}> - CANCEL - - - + > + SAVE + + { + navigation.navigate("Home"); + }} + > + CANCEL + + );