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} + + ); }