mirror of
https://github.com/lemeow125/Reactnative-notesapp.git
synced 2024-11-17 06:29:27 +08:00
Added public notes functionality to homepage
This commit is contained in:
parent
a452c0e329
commit
fad68bd97f
2 changed files with 58 additions and 2 deletions
55
src/Components/PublicNotes/Notes.tsx
Normal file
55
src/Components/PublicNotes/Notes.tsx
Normal file
|
@ -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<RootDrawerParamList>();
|
||||
const {
|
||||
data: notes,
|
||||
isLoading,
|
||||
error,
|
||||
} = useQuery("public_notes", GetPublicNotes, { retry: 0 });
|
||||
if (isLoading) {
|
||||
return (
|
||||
<Text style={{ ...styles.no, ...{ textAlign: "center" } }}>
|
||||
Loading public notes...
|
||||
</Text>
|
||||
);
|
||||
} else if (error) {
|
||||
return (
|
||||
<Text style={{ ...styles.no, ...{ textAlign: "center", color: "red" } }}>
|
||||
Error contacting Notes server
|
||||
</Text>
|
||||
);
|
||||
} else if (notes.length === 0) {
|
||||
return (
|
||||
<Text style={{ ...styles.no, ...{ textAlign: "center" } }}>
|
||||
There are no public notes...
|
||||
</Text>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<ScrollView contentContainerStyle={{ justifyContent: "center" }}>
|
||||
{notes.map((note: NoteProps, index: number) => {
|
||||
return (
|
||||
<Note
|
||||
id={note.id}
|
||||
key={index}
|
||||
title={note.title}
|
||||
content={note.content}
|
||||
date_created={note.date_created}
|
||||
owner={note.owner}
|
||||
public={note.public}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</ScrollView>
|
||||
);
|
||||
}
|
|
@ -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 <Text>Viewing public notes</Text>;
|
||||
return <PublicNotes />;
|
||||
} else {
|
||||
return <Notes />;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue