So called working
This commit is contained in:
parent
79328b6b62
commit
556bf52865
2 changed files with 22 additions and 4 deletions
11
App.tsx
11
App.tsx
|
@ -5,6 +5,17 @@ import { PostsContainer } from "./src/components/PostsContainer";
|
|||
import { NavigationContainer } from "@react-navigation/native";
|
||||
import { createNativeStackNavigator } from "@react-navigation/native-stack";
|
||||
import { NewPostContainer } from "./src/components/NewPostContainer";
|
||||
import { NativeStackNavigationProp } from "@react-navigation/native-stack";
|
||||
|
||||
type RootStackParamList = {
|
||||
Home: undefined;
|
||||
New: undefined;
|
||||
};
|
||||
|
||||
export type HomeScreenNavigationProp = NativeStackNavigationProp<
|
||||
RootStackParamList,
|
||||
"Home"
|
||||
>;
|
||||
|
||||
const Stack = createNativeStackNavigator();
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import React from "react";
|
||||
import { View, Text, TextInput, Button } from "react-native";
|
||||
import { style } from "../util/style";
|
||||
import { createPost, NewPost } from "../util/api";
|
||||
import { createPost, NewPost, submitLogin } from "../util/api";
|
||||
|
||||
export function NewPostContainer({ navigation }): JSX.Element {
|
||||
const [currentInput, setCurrentInput] = React.useState<string>("");
|
||||
|
@ -21,13 +21,20 @@ export function NewPostContainer({ navigation }): JSX.Element {
|
|||
<Button
|
||||
title="Post"
|
||||
onPress={() => {
|
||||
if (currentInput.length > 0) {
|
||||
async function submit(): Promise<void> {
|
||||
const user = (await submitLogin("demouser", "demopw")) ?? {
|
||||
token: "",
|
||||
};
|
||||
const p: NewPost = {
|
||||
content: currentInput,
|
||||
token: "token",
|
||||
token: user.token,
|
||||
};
|
||||
createPost(p);
|
||||
await createPost(p);
|
||||
setCurrentInput("");
|
||||
}
|
||||
if (currentInput.length > 0) {
|
||||
submit();
|
||||
navigation.navigate("Home");
|
||||
} else {
|
||||
setCurrentInputError("Post must not be empty!");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue