mirror of
https://github.com/lemeow125/Reactnative-notesapp.git
synced 2024-11-16 22:19:26 +08:00
Merge branch 'feature/home' into feature/initial_frontend
This commit is contained in:
commit
c3fe00f8f5
5 changed files with 198 additions and 20 deletions
24
src/Components/Note/Note.tsx
Normal file
24
src/Components/Note/Note.tsx
Normal file
|
@ -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 (
|
||||
<View style={styles.addnotecont}>
|
||||
<View style={styles.tle}>
|
||||
<TextInput
|
||||
style={styles.title}
|
||||
value={props.title}
|
||||
maxLength={20}
|
||||
editable={false}
|
||||
/>
|
||||
</View>
|
||||
<View style={styles.typehere}>
|
||||
<ScrollView style={styles.typeinput} nestedScrollEnabled={true}>
|
||||
<Text style={styles.typeinput}>{props.content}</Text>
|
||||
</ScrollView>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
87
src/Components/Notes/Notes.tsx
Normal file
87
src/Components/Notes/Notes.tsx
Normal file
|
@ -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<RootDrawerParamList>();
|
||||
const {
|
||||
data: notes,
|
||||
isLoading,
|
||||
error,
|
||||
} = useQuery("notes", GetNotes, { retry: 0 });
|
||||
const logged_in = useSelector((state: RootState) => state.logged_in.value);
|
||||
if (isLoading) {
|
||||
return (
|
||||
<Text style={{ ...styles.no, ...{ textAlign: "center" } }}>
|
||||
Loading notes...
|
||||
</Text>
|
||||
);
|
||||
} else if (!logged_in && error) {
|
||||
return (
|
||||
<Text style={{ ...styles.no, ...{ textAlign: "center" } }}>
|
||||
Please login to use Clip 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 (
|
||||
<View>
|
||||
<Text style={styles.no}>No notes exist yet. Make one!</Text>;
|
||||
<View style={styles.homecont}>
|
||||
<TouchableOpacity
|
||||
onPress={() => {
|
||||
navigation.navigate("New Note");
|
||||
}}
|
||||
>
|
||||
<Text style={styles.newnote}>+</Text>
|
||||
</TouchableOpacity>
|
||||
<Text style={styles.no}>New note...</Text>
|
||||
<View style={{ margin: 16 }} />
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
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}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
<TouchableOpacity
|
||||
style={{
|
||||
...styles.homecont,
|
||||
...{ display: "flex", alignSelf: "center" },
|
||||
}}
|
||||
onPress={() => {
|
||||
navigation.navigate("New Note");
|
||||
}}
|
||||
>
|
||||
<Text style={styles.newnote}>+</Text>
|
||||
<Text style={styles.no}>New note...</Text>
|
||||
</TouchableOpacity>
|
||||
|
||||
<View style={{ margin: 16 }} />
|
||||
</ScrollView>
|
||||
);
|
||||
}
|
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>
|
||||
);
|
||||
}
|
|
@ -30,6 +30,7 @@ export interface NoteProps {
|
|||
id: number;
|
||||
date_created: Date;
|
||||
owner: string;
|
||||
public: boolean;
|
||||
}
|
||||
|
||||
export interface IconProps {
|
||||
|
|
|
@ -1,16 +1,22 @@
|
|||
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";
|
||||
import PublicNotes from "../../Components/PublicNotes/Notes";
|
||||
|
||||
export default function Home() {
|
||||
const navigation = useNavigation<RootDrawerParamList>();
|
||||
|
||||
const dispatch = useDispatch();
|
||||
const [switchLabel, setLabel] = useState("Viewing public notes");
|
||||
const [togglePublic, setToggled] = useState(true);
|
||||
function Preview() {
|
||||
if (togglePublic) {
|
||||
return <PublicNotes />;
|
||||
} else {
|
||||
return <Notes />;
|
||||
}
|
||||
}
|
||||
return (
|
||||
<Background>
|
||||
<Text style={{ ...styles.text_white, ...{ fontSize: 25 } }}>
|
||||
|
@ -20,22 +26,27 @@ export default function Home() {
|
|||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
justifyContent: "flex-start",
|
||||
marginLeft: 16,
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
}}
|
||||
>
|
||||
<View style={styles.homecont}>
|
||||
<TouchableOpacity
|
||||
onPress={() => {
|
||||
navigation.navigate("New Note");
|
||||
}}
|
||||
>
|
||||
<Text style={styles.newnote}>+</Text>
|
||||
</TouchableOpacity>
|
||||
<Text style={styles.no}>New note...</Text>
|
||||
<View style={{ margin: 16 }} />
|
||||
</View>
|
||||
<Switch
|
||||
onValueChange={() => {
|
||||
setToggled(!togglePublic);
|
||||
if (togglePublic) {
|
||||
setLabel("Viewing own notes");
|
||||
} else {
|
||||
setLabel("Viewing public notes");
|
||||
}
|
||||
}}
|
||||
value={togglePublic}
|
||||
/>
|
||||
<Text style={{ ...styles.text_white, ...{ fontSize: 16 } }}>
|
||||
{switchLabel}
|
||||
</Text>
|
||||
</View>
|
||||
<Preview />
|
||||
</Background>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue