Boilerplate for NewPostContainer

This commit is contained in:
Imbus 2023-12-15 01:19:54 +01:00
parent 3e906f2c66
commit 3855a587a0

View 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>
);
}