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 { NavigationContainer } from "@react-navigation/native"; | ||||||
| import { createNativeStackNavigator } from "@react-navigation/native-stack"; | import { createNativeStackNavigator } from "@react-navigation/native-stack"; | ||||||
| import { NewPostContainer } from "./src/components/NewPostContainer"; | 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(); | const Stack = createNativeStackNavigator(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| import React from "react"; | import React from "react"; | ||||||
| import { View, Text, TextInput, Button } from "react-native"; | import { View, Text, TextInput, Button } from "react-native"; | ||||||
| import { style } from "../util/style"; | import { style } from "../util/style"; | ||||||
| import { createPost, NewPost } from "../util/api"; | import { createPost, NewPost, submitLogin } from "../util/api"; | ||||||
| 
 | 
 | ||||||
| export function NewPostContainer({ navigation }): JSX.Element { | export function NewPostContainer({ navigation }): JSX.Element { | ||||||
|   const [currentInput, setCurrentInput] = React.useState<string>(""); |   const [currentInput, setCurrentInput] = React.useState<string>(""); | ||||||
|  | @ -21,13 +21,20 @@ export function NewPostContainer({ navigation }): JSX.Element { | ||||||
|       <Button |       <Button | ||||||
|         title="Post" |         title="Post" | ||||||
|         onPress={() => { |         onPress={() => { | ||||||
|           if (currentInput.length > 0) { |           async function submit(): Promise<void> { | ||||||
|  |             const user = (await submitLogin("demouser", "demopw")) ?? { | ||||||
|  |               token: "", | ||||||
|  |             }; | ||||||
|             const p: NewPost = { |             const p: NewPost = { | ||||||
|               content: currentInput, |               content: currentInput, | ||||||
|               token: "token", |               token: user.token, | ||||||
|             }; |             }; | ||||||
|             createPost(p); |             await createPost(p); | ||||||
|             setCurrentInput(""); |             setCurrentInput(""); | ||||||
|  |           } | ||||||
|  |           if (currentInput.length > 0) { | ||||||
|  |             submit(); | ||||||
|  |             navigation.navigate("Home"); | ||||||
|           } else { |           } else { | ||||||
|             setCurrentInputError("Post must not be empty!"); |             setCurrentInputError("Post must not be empty!"); | ||||||
|           } |           } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Imbus
						Imbus