mirror of
https://github.com/lemeow125/Reactnative-notesapp.git
synced 2024-11-17 06:29:27 +08:00
Added public toggle to add note and made it consistent with edit note
This commit is contained in:
parent
cecc63eb7e
commit
ed9715c63f
3 changed files with 79 additions and 54 deletions
|
@ -59,6 +59,7 @@ export interface ActivationParams {
|
||||||
export interface AddNoteParams {
|
export interface AddNoteParams {
|
||||||
title: string;
|
title: string;
|
||||||
content: string;
|
content: string;
|
||||||
|
public: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdateNoteParams {
|
export interface UpdateNoteParams {
|
||||||
|
|
|
@ -15,7 +15,7 @@ export default function EditNote({ navigation, route }: any) {
|
||||||
const [note, setNote] = useState({
|
const [note, setNote] = useState({
|
||||||
title: "",
|
title: "",
|
||||||
content: "",
|
content: "",
|
||||||
public: true,
|
public: false,
|
||||||
});
|
});
|
||||||
async function retrieve() {
|
async function retrieve() {
|
||||||
let a = await GetNote(noteId);
|
let a = await GetNote(noteId);
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import * as React from 'react';
|
import * as React from "react";
|
||||||
import {View, Text, TextInput} from 'react-native';
|
import { View, Text, TextInput, Switch } from "react-native";
|
||||||
import styles from '../../styles';
|
import styles from "../../styles";
|
||||||
import Background from '../../Components/Background/Background';
|
import Background from "../../Components/Background/Background";
|
||||||
import { SafeAreaView } from 'react-native-safe-area-context';
|
import { SafeAreaView } from "react-native-safe-area-context";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import {TouchableOpacity,} from "react-native";
|
import { TouchableOpacity } from "react-native";
|
||||||
import { RootDrawerParamList } from "../../Interfaces/Interfaces";
|
import { RootDrawerParamList } from "../../Interfaces/Interfaces";
|
||||||
import { useNavigation } from "@react-navigation/native";
|
import { useNavigation } from "@react-navigation/native";
|
||||||
import { useMutation, useQueryClient } from "react-query";
|
import { useMutation, useQueryClient } from "react-query";
|
||||||
|
@ -14,10 +14,11 @@ export default function NewNote() {
|
||||||
const [note, setNote] = useState({
|
const [note, setNote] = useState({
|
||||||
title: "",
|
title: "",
|
||||||
content: "",
|
content: "",
|
||||||
|
public: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const navigation = useNavigation<RootDrawerParamList>();
|
const navigation = useNavigation<RootDrawerParamList>();
|
||||||
|
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const mutation = useMutation({
|
const mutation = useMutation({
|
||||||
mutationFn: AddNote,
|
mutationFn: AddNote,
|
||||||
|
@ -28,54 +29,77 @@ export default function NewNote() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Background>
|
<Background>
|
||||||
<Text style={{...styles.text_white, ...{fontSize: 32}}}>New Note</Text>
|
<Text style={{ ...styles.text_white, ...{ fontSize: 32 } }}>
|
||||||
<SafeAreaView>
|
New Note
|
||||||
<View style={styles.addnotecont}>
|
</Text>
|
||||||
<View style={styles.tle}>
|
<SafeAreaView>
|
||||||
<TextInput
|
<View style={styles.addnotecont}>
|
||||||
style={styles.title}
|
<View style={styles.tle}>
|
||||||
placeholder="Title"
|
<TextInput
|
||||||
placeholderTextColor="white"
|
style={styles.title}
|
||||||
value={note.title}
|
placeholder="Title"
|
||||||
onChangeText={(text) => {
|
placeholderTextColor="white"
|
||||||
setNote({ ...note, title: text });
|
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}
|
||||||
|
multiline={true}
|
||||||
|
onChangeText={async (text) => {
|
||||||
|
await setNote({ ...note, content: text });
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "row",
|
||||||
|
justifyContent: "flex-start",
|
||||||
|
marginLeft: 16,
|
||||||
|
alignItems: "center",
|
||||||
}}
|
}}
|
||||||
maxLength={20}
|
>
|
||||||
/>
|
<Switch
|
||||||
</View>
|
onValueChange={() => setNote({ ...note, public: !note.public })}
|
||||||
<View style={styles.typehere}>
|
value={note.public}
|
||||||
<TextInput
|
/>
|
||||||
style={styles.typeinput}
|
<Text style={{ ...styles.text_white, ...{ fontSize: 16 } }}>
|
||||||
placeholder="Type here...."
|
Public?
|
||||||
placeholderTextColor="white"
|
</Text>
|
||||||
value={note.content}
|
</View>
|
||||||
onChangeText={async (text) => {
|
<TouchableOpacity
|
||||||
await setNote({ ...note, content: text });
|
style={styles.savebtn}
|
||||||
|
onPress={async () => {
|
||||||
|
try {
|
||||||
|
await mutation.mutate({
|
||||||
|
title: note.title,
|
||||||
|
content: note.content,
|
||||||
|
public: note.public,
|
||||||
|
});
|
||||||
|
navigation.navigate("Home");
|
||||||
|
} catch (error) {}
|
||||||
|
console.log(note.content);
|
||||||
}}
|
}}
|
||||||
/>
|
>
|
||||||
</View>
|
<Text style={styles.savenote}>SAVE</Text>
|
||||||
<TouchableOpacity style={styles.savebtn}
|
</TouchableOpacity>
|
||||||
onPress={async () => {
|
<TouchableOpacity
|
||||||
try {
|
style={styles.cancelbtn}
|
||||||
await mutation.mutate({
|
onPress={() => {
|
||||||
title: note.title,
|
navigation.navigate("Home");
|
||||||
content: note.content,
|
}}
|
||||||
});
|
>
|
||||||
navigation.navigate("Home");
|
<Text style={styles.cancel}>CANCEL</Text>
|
||||||
} catch (error) {}
|
</TouchableOpacity>
|
||||||
console.log(note.content)
|
</View>
|
||||||
}}>
|
|
||||||
|
|
||||||
<Text style={styles.savenote}>SAVE</Text>
|
|
||||||
</TouchableOpacity>
|
|
||||||
<TouchableOpacity style={styles.cancelbtn}
|
|
||||||
onPress={() => {
|
|
||||||
navigation.navigate("Home");
|
|
||||||
}}>
|
|
||||||
<Text style={styles.cancel}>CANCEL</Text>
|
|
||||||
</TouchableOpacity>
|
|
||||||
</View>
|
|
||||||
|
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
</Background>
|
</Background>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue