import { useFocusEffect } from 'expo-router' import React, { useState } from 'react' import { Image, StyleSheet, Text, TouchableOpacity, View } from 'react-native' import { Post } from '../models/postModel' export default function PostsScreen() { const [posts, setPosts] = useState() useFocusEffect( React.useCallback(() => { // Do something when the screen is focused // TODO: add endpoint to get only non approved or denied status posts fetch('http://localhost:3000/api/v1/posts') .then((res) => res.json()) .then((json) => { console.log(json) setPosts(json.data) }); return () => { // Do something when the screen is unfocused // Useful for cleanup functions } }, []) ) 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' }) }) } 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' }) }) } return ( Posts { posts && posts.map(el => ( {el._id} {el.notes} denyPost(el._id)}> Deny approvePost(el._id)}> Approve )) } ) } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#25292e', justifyContent: 'center', alignItems: 'center', overflow: 'scroll' }, text: { color: '#fff' }, posts: { marginBottom: 10, backgroundColor: '#363c43ff', padding: 10 } })