diff --git a/app/(tabs)/posts.tsx b/app/(tabs)/posts.tsx index 153a9ec..dab81b3 100644 --- a/app/(tabs)/posts.tsx +++ b/app/(tabs)/posts.tsx @@ -1,6 +1,7 @@ import { useFocusEffect } from 'expo-router' import React, { useState } from 'react' -import { Image, StyleSheet, Text, TouchableOpacity, View } from 'react-native' +import { StyleSheet, Text, View } from 'react-native' +import { PostComponent } from '../components/PostComponent' import { Post } from '../models/postModel' export default function PostsScreen() { @@ -27,89 +28,12 @@ export default function PostsScreen() { }) } - async function approvePost(postID: string) { - // add code to update post to approved status - console.log('Approving post ' + postID) - await fetch(`http://localhost:3000/api/v1/posts/${postID}`, { - method: 'PATCH', - headers: { - Accept: 'application/json, text/plain, */*', - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - status: 'approved' - }) - }).then(() => { - fetchData() - }) - } - - async function denyPost(postID: string) { - // add code to update post to remove status - console.log('Denying post ' + postID) - await fetch(`http://localhost:3000/api/v1/posts/${postID}`, { - method: 'PATCH', - headers: { - Accept: 'application/json, text/plain, */*', - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - status: 'denied' - }) - }).then(() => { - fetchData() - }) - } - return ( Posts {posts?.length ? ( - posts.map((el) => ( - - {el._id} - - - - {el.notes} - - denyPost(el._id)}> - - Deny - - - approvePost(el._id)} - > - - Approve - - - - - )) + posts.map((el) => ) ) : ( All caught up! diff --git a/app/components/Post.tsx b/app/components/Post.tsx deleted file mode 100644 index 2594dae..0000000 --- a/app/components/Post.tsx +++ /dev/null @@ -1,3 +0,0 @@ -export const Post = () => { - return null -} diff --git a/app/components/PostComponent.tsx b/app/components/PostComponent.tsx new file mode 100644 index 0000000..2322cf0 --- /dev/null +++ b/app/components/PostComponent.tsx @@ -0,0 +1,98 @@ +import React from 'react' +import { Image, StyleSheet, Text, TouchableOpacity, View } from 'react-native' +import { Post } from '../models/postModel' + +type PostComponentProps = { + post: Post + fetchData: () => void +} + +export const PostComponent: React.FC = ({ post, fetchData }) => { + async function approvePost(postID: string) { + console.log('Approving post ' + postID) + await fetch(`http://localhost:3000/api/v1/posts/${postID}`, { + method: 'PATCH', + headers: { + Accept: 'application/json, text/plain, */*', + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + status: 'approved' + }) + }).then(() => { + fetchData() + }) + } + + async function denyPost(postID: string) { + console.log('Denying post ' + postID) + await fetch(`http://localhost:3000/api/v1/posts/${postID}`, { + method: 'PATCH', + headers: { + Accept: 'application/json, text/plain, */*', + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + status: 'denied' + }) + }).then(() => { + fetchData() + }) + } + + return ( + + {post._id} + + + + {post.notes} + + denyPost(post._id)}> + + Deny + + + approvePost(post._id)}> + + Approve + + + + + ) +} + +const styles = StyleSheet.create({ + text: { + color: '#fff', + justifyContent: 'center' + }, + posts: { + marginTop: 10, + backgroundColor: '#363c43ff', + padding: 10, + width: '90%', + borderRadius: 5 + } +})