Merge branch 'feature/NewNote_api' into feature/initial_frontend

This commit is contained in:
keannu125 2023-04-14 21:24:56 +08:00
commit eafbfaaf43
4 changed files with 102 additions and 72 deletions

32
App.tsx
View file

@ -7,7 +7,7 @@ import DrawerScreenSettings from "./src/Components/Drawer/DrawerScreenSettings/D
import Home from "./src/Routes/Home/Home";
import UserInfo from "./src/Routes/UserInfo/UserInfo";
import AddNote from "./src/Routes/AddNote/AddNote";
import NewNote from "./src/Routes/NewNote/NewNote";
import Login from "./src/Routes/Login/Login";
import Register from "./src/Routes/Register/Register";
import { Provider } from "react-redux";
@ -16,25 +16,27 @@ import { QueryClient, QueryClientProvider } from "react-query";
const Drawer = createDrawerNavigator();
const queryClient = new QueryClient();
export default function App() {
return (
<Provider store={Store}>
<NavigationContainer>
<Drawer.Navigator
initialRouteName="Home"
drawerContent={CustomDrawerContent}
screenOptions={DrawerScreenSettings}
>
<Drawer.Screen name="Home" component={Home} />
<Drawer.Screen name="Add Note" component={AddNote} />
<Drawer.Screen name="User Info" component={UserInfo} />
<Drawer.Screen name="Login" component={Login} />
<Drawer.Screen name="Register" component={Register} />
<QueryClientProvider client={queryClient}>
<NavigationContainer>
<Drawer.Navigator
initialRouteName="Home"
drawerContent={CustomDrawerContent}
screenOptions={DrawerScreenSettings}
>
<Drawer.Screen name="Home" component={Home} />
<Drawer.Screen name="New Note" component={NewNote} />
<Drawer.Screen name="User Info" component={UserInfo} />
<Drawer.Screen name="Login" component={Login} />
<Drawer.Screen name="Register" component={Register} />
</Drawer.Navigator>
</NavigationContainer>
</Drawer.Navigator>
</NavigationContainer>
</QueryClientProvider>
</Provider>
);
}

View file

@ -44,12 +44,12 @@ export default function CustomDrawerContent(props: {}) {
color="Green"
width={width}
onPress={() => {
navigation.navigate("Add Note");
navigation.navigate("New Note");
}}
>
<AddIcon size={32} color="white" />
<Text style={{ ...styles.text_white, ...{ fontSize: 32 } }}>
Add Note
New Note
</Text>
</ButtonAlignLeft>
<ButtonAlignLeft

View file

@ -27,7 +27,7 @@ export default function Home() {
<View style={styles.homecont}>
<TouchableOpacity
onPress={() => {
navigation.navigate("Add Note");
navigation.navigate("New Note");
}}
>
<Text style={styles.newnote}>+</Text>

View file

@ -1,54 +1,82 @@
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 { useState } from "react";
import {TouchableOpacity,} from "react-native";
import { RootDrawerParamList } from "../../Interfaces/Interfaces";
import { useNavigation } from "@react-navigation/native";
export default function AddNote() {
const [addnote, setNote] = useState("");
const [addtitle, setTitle] = useState("");
const navigation = useNavigation<RootDrawerParamList>();
return (
<Background>
<Text style={{...styles.text_white, ...{fontSize: 32}}}>Add Note</Text>
<SafeAreaView>
<View style={styles.addnotecont}>
<View style={styles.tle}>
<TextInput
style={styles.title}
placeholder="Title"
placeholderTextColor="white"
onChangeText={setTitle}
value={addtitle}
/>
</View>
<View style={styles.typehere}>
<TextInput
style={styles.typeinput}
placeholder="Type here...."
placeholderTextColor="white"
onChangeText={setNote}
value={addnote}
/>
</View>
<TouchableOpacity style={styles.savebtn}>
<Text style={styles.savenote}>SAVE</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.cancelbtn}
onPress={() => {
navigation.navigate("Home");
}}>
<Text style={styles.cancel}>CANCEL</Text>
</TouchableOpacity>
</View>
</SafeAreaView>
</Background>
);
}
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 { useState } from "react";
import {TouchableOpacity,} from "react-native";
import { RootDrawerParamList } from "../../Interfaces/Interfaces";
import { useNavigation } from "@react-navigation/native";
import { useMutation, useQueryClient } from "react-query";
import { AddNote } from "../../Components/Api/Api";
export default function NewNote() {
const [note, setNote] = useState({
title: "",
content: "",
});
const navigation = useNavigation<RootDrawerParamList>();
const queryClient = useQueryClient();
const mutation = useMutation({
mutationFn: AddNote,
onSuccess: () => {
queryClient.invalidateQueries("notes");
},
});
return (
<Background>
<Text style={{...styles.text_white, ...{fontSize: 32}}}>New Note</Text>
<SafeAreaView>
<View style={styles.addnotecont}>
<View style={styles.tle}>
<TextInput
style={styles.title}
placeholder="Title"
placeholderTextColor="white"
value={note.title}
onChangeText={(text) => {
setNote({ ...note, title: text });
}}
maxLength={20}
/>
</View>
<View style={styles.typehere}>
<TextInput
style={styles.typeinput}
placeholder="Type here...."
placeholderTextColor="white"
value={note.content}
onChangeText={async (text) => {
await setNote({ ...note, content: text });
}}
/>
</View>
<TouchableOpacity style={styles.savebtn}
onPress={async () => {
try {
await mutation.mutate({
title: note.title,
content: note.content,
});
navigation.navigate("Home");
} catch (error) {}
console.log(note.content)
}}>
<Text style={styles.savenote}>SAVE</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.cancelbtn}
onPress={() => {
navigation.navigate("Home");
}}>
<Text style={styles.cancel}>CANCEL</Text>
</TouchableOpacity>
</View>
</SafeAreaView>
</Background>
);
}