Initial outline of containers and posts outline
This commit is contained in:
parent
edb7d67547
commit
027ed45cd3
3 changed files with 49 additions and 0 deletions
3
App.tsx
3
App.tsx
|
@ -1,11 +1,14 @@
|
|||
import { StatusBar } from 'expo-status-bar';
|
||||
import { StyleSheet, Text, View } from 'react-native';
|
||||
|
||||
import { PostsContainer } from './src/components/PostsContainer';
|
||||
|
||||
export default function App() {
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<Text>Open up App.tsx to start working on your app!</Text>
|
||||
<StatusBar style="auto" />
|
||||
<PostsContainer />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
|
21
src/components/PostView.tsx
Normal file
21
src/components/PostView.tsx
Normal file
|
@ -0,0 +1,21 @@
|
|||
import React from "react";
|
||||
import { View, Text } from "react-native";
|
||||
import { Post } from "../util/api";
|
||||
|
||||
/**
|
||||
* This is the component that holds a single Post
|
||||
*
|
||||
* @param {Post} post The post to display
|
||||
* @returns {JSX.Element} The JSX for the Post
|
||||
*/
|
||||
export function PostView({ post }: { post: Post }): JSX.Element {
|
||||
// WARNING THIS IS NOT ACCEPTABLE WARNING REMOVE WARNING
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const [thisPost, setThisPost] = React.useState<Post>(post);
|
||||
|
||||
return (
|
||||
<View style={{ flexDirection: "row", height: 100, padding: 20 }}>
|
||||
<Text>{thisPost.content}</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
25
src/components/PostsContainer.tsx
Normal file
25
src/components/PostsContainer.tsx
Normal file
|
@ -0,0 +1,25 @@
|
|||
import React from "react";
|
||||
import { View, Text } from "react-native";
|
||||
import { getPosts, Post } from "../util/api";
|
||||
import { PostView } from "./PostView";
|
||||
|
||||
export function PostsContainer(): JSX.Element {
|
||||
const [posts, setPosts] = React.useState<Post[]>([]);
|
||||
|
||||
React.useEffect(() => {
|
||||
async function fetchPosts(): Promise<void> {
|
||||
const posts = await getPosts();
|
||||
setPosts(posts);
|
||||
}
|
||||
fetchPosts();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<View style={{ height: 100, padding: 20 }}>
|
||||
<Text>Hello World!</Text>
|
||||
{posts.map((post) => (
|
||||
<PostView key={post.id} post={post} />
|
||||
))}
|
||||
</View>
|
||||
);
|
||||
}
|
Loading…
Reference in a new issue