From a452c0e3296c72329b018147e2182fedccd68420 Mon Sep 17 00:00:00 2001 From: keannu125 Date: Fri, 14 Apr 2023 21:59:25 +0800 Subject: [PATCH 1/2] Polished homepage and added private notes functionality --- src/Components/Note/Note.tsx | 24 ++++++++++ src/Components/Notes/Notes.tsx | 87 ++++++++++++++++++++++++++++++++++ src/Interfaces/Interfaces.tsx | 1 + src/Routes/Home/Home.tsx | 50 +++++++++++-------- 4 files changed, 142 insertions(+), 20 deletions(-) create mode 100644 src/Components/Note/Note.tsx create mode 100644 src/Components/Notes/Notes.tsx diff --git a/src/Components/Note/Note.tsx b/src/Components/Note/Note.tsx new file mode 100644 index 0000000..19657c0 --- /dev/null +++ b/src/Components/Note/Note.tsx @@ -0,0 +1,24 @@ +import * as React from "react"; +import { View, Text, TextInput, ScrollView } from "react-native"; +import styles from "../../styles"; +import { NoteProps } from "../../Interfaces/Interfaces"; + +export default function Note(props: NoteProps) { + return ( + + + + + + + {props.content} + + + + ); +} diff --git a/src/Components/Notes/Notes.tsx b/src/Components/Notes/Notes.tsx new file mode 100644 index 0000000..a58d47d --- /dev/null +++ b/src/Components/Notes/Notes.tsx @@ -0,0 +1,87 @@ +import * as React from "react"; +import { View, Text, TouchableOpacity, ScrollView } from "react-native"; +import { useQuery } from "react-query"; +import { GetNotes } from "../Api/Api"; +import styles from "../../styles"; +import { useSelector } from "react-redux"; +import { RootState } from "../../Features/Redux/Store/Store"; +import { NoteProps, RootDrawerParamList } from "../../Interfaces/Interfaces"; +import { useNavigation } from "@react-navigation/native"; +import Note from "../Note/Note"; + +export default function Notes() { + const navigation = useNavigation(); + const { + data: notes, + isLoading, + error, + } = useQuery("notes", GetNotes, { retry: 0 }); + const logged_in = useSelector((state: RootState) => state.logged_in.value); + if (isLoading) { + return ( + + Loading notes... + + ); + } else if (!logged_in && error) { + return ( + + Please login to use Clip Notes + + ); + } else if (error) { + return ( + + Error contacting Notes server + + ); + } else if (notes.length === 0) { + return ( + + No notes exist yet. Make one!; + + { + navigation.navigate("New Note"); + }} + > + + + + New note... + + + + ); + } + return ( + + {notes.map((note: NoteProps, index: number) => { + return ( + + ); + })} + { + navigation.navigate("New Note"); + }} + > + + + New note... + + + + + ); +} diff --git a/src/Interfaces/Interfaces.tsx b/src/Interfaces/Interfaces.tsx index 0ddd97d..14cc38f 100644 --- a/src/Interfaces/Interfaces.tsx +++ b/src/Interfaces/Interfaces.tsx @@ -30,6 +30,7 @@ export interface NoteProps { id: number; date_created: Date; owner: string; + public: boolean; } export interface IconProps { diff --git a/src/Routes/Home/Home.tsx b/src/Routes/Home/Home.tsx index 5851b61..0e171f8 100644 --- a/src/Routes/Home/Home.tsx +++ b/src/Routes/Home/Home.tsx @@ -1,16 +1,21 @@ import * as React from "react"; -import { View, Text, TouchableOpacity } from "react-native"; +import { View, Text } from "react-native"; import styles from "../../styles"; import Background from "../../Components/Background/Background"; -import AppIcon from "../../Components/Icons/AppIcon/AppIcon"; -import { useNavigation } from "@react-navigation/native"; -import { useDispatch } from "react-redux"; -import { RootDrawerParamList } from "../../Interfaces/Interfaces"; +import Notes from "../../Components/Notes/Notes"; +import { Switch } from "react-native-gesture-handler"; +import { useState } from "react"; export default function Home() { - const navigation = useNavigation(); - - const dispatch = useDispatch(); + const [switchLabel, setLabel] = useState("Viewing public notes"); + const [togglePublic, setToggled] = useState(false); + function Preview() { + if (togglePublic) { + return Viewing public notes; + } else { + return ; + } + } return ( @@ -20,22 +25,27 @@ export default function Home() { style={{ display: "flex", flexDirection: "row", + justifyContent: "flex-start", + marginLeft: 16, alignItems: "center", - justifyContent: "center", }} > - - { - navigation.navigate("New Note"); - }} - > - + - - New note... - - + { + setToggled(!togglePublic); + if (togglePublic) { + setLabel("Viewing own notes"); + } else { + setLabel("Viewing public notes"); + } + }} + value={togglePublic} + /> + + {switchLabel} + + ); } From fad68bd97ffbbe2eb01ef72989b702ba6cf173bb Mon Sep 17 00:00:00 2001 From: keannu125 Date: Fri, 14 Apr 2023 22:03:18 +0800 Subject: [PATCH 2/2] Added public notes functionality to homepage --- src/Components/PublicNotes/Notes.tsx | 55 ++++++++++++++++++++++++++++ src/Routes/Home/Home.tsx | 5 ++- 2 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 src/Components/PublicNotes/Notes.tsx diff --git a/src/Components/PublicNotes/Notes.tsx b/src/Components/PublicNotes/Notes.tsx new file mode 100644 index 0000000..efc4850 --- /dev/null +++ b/src/Components/PublicNotes/Notes.tsx @@ -0,0 +1,55 @@ +import * as React from "react"; +import { View, Text, TouchableOpacity, ScrollView } from "react-native"; +import { useQuery } from "react-query"; +import { GetNotes, GetPublicNotes } from "../Api/Api"; +import styles from "../../styles"; +import { useSelector } from "react-redux"; +import { RootState } from "../../Features/Redux/Store/Store"; +import { NoteProps, RootDrawerParamList } from "../../Interfaces/Interfaces"; +import { useNavigation } from "@react-navigation/native"; +import Note from "../Note/Note"; + +export default function PublicNotes() { + const navigation = useNavigation(); + const { + data: notes, + isLoading, + error, + } = useQuery("public_notes", GetPublicNotes, { retry: 0 }); + if (isLoading) { + return ( + + Loading public notes... + + ); + } else if (error) { + return ( + + Error contacting Notes server + + ); + } else if (notes.length === 0) { + return ( + + There are no public notes... + + ); + } + return ( + + {notes.map((note: NoteProps, index: number) => { + return ( + + ); + })} + + ); +} diff --git a/src/Routes/Home/Home.tsx b/src/Routes/Home/Home.tsx index 0e171f8..50bc561 100644 --- a/src/Routes/Home/Home.tsx +++ b/src/Routes/Home/Home.tsx @@ -5,13 +5,14 @@ import Background from "../../Components/Background/Background"; import Notes from "../../Components/Notes/Notes"; import { Switch } from "react-native-gesture-handler"; import { useState } from "react"; +import PublicNotes from "../../Components/PublicNotes/Notes"; export default function Home() { const [switchLabel, setLabel] = useState("Viewing public notes"); - const [togglePublic, setToggled] = useState(false); + const [togglePublic, setToggled] = useState(true); function Preview() { if (togglePublic) { - return Viewing public notes; + return ; } else { return ; }