Boilerplate for NewPostContainer
This commit is contained in:
parent
3e906f2c66
commit
3855a587a0
1 changed files with 39 additions and 0 deletions
39
src/components/NewPostContainer.tsx
Normal file
39
src/components/NewPostContainer.tsx
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
import React from "react";
|
||||||
|
import { View, Text, TextInput, Button } from "react-native";
|
||||||
|
import { style } from "../util/style";
|
||||||
|
import { createPost, NewPost } from "../util/api";
|
||||||
|
|
||||||
|
export function NewPostContainer(): JSX.Element {
|
||||||
|
const [currentInput, setCurrentInput] = React.useState<string>("");
|
||||||
|
const [currentInputError, setCurrentInputError] = React.useState<string>("");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={style.newPostContainer}>
|
||||||
|
<TextInput
|
||||||
|
style={style.newPostInput}
|
||||||
|
placeholder="New Post"
|
||||||
|
onChangeText={(text) => {
|
||||||
|
setCurrentInput(text);
|
||||||
|
setCurrentInputError("");
|
||||||
|
}}
|
||||||
|
value={currentInput}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
title="Post"
|
||||||
|
onPress={() => {
|
||||||
|
if (currentInput.length > 0) {
|
||||||
|
const p: NewPost = {
|
||||||
|
content: currentInput,
|
||||||
|
token: "token"
|
||||||
|
}
|
||||||
|
createPost(p);
|
||||||
|
setCurrentInput("");
|
||||||
|
} else {
|
||||||
|
setCurrentInputError("Post must not be empty!");
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Text style={style.errorText}>{currentInputError}</Text>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in a new issue