adding display of all posts in posts tab

This commit is contained in:
Will Baumbach
2025-07-30 13:44:37 -05:00
parent 717ec8ff6f
commit 913c4cf3f7

View File

@@ -1,6 +1,6 @@
import { useFocusEffect } from 'expo-router'
import React, { useState } from 'react'
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native'
import { Image, StyleSheet, Text, TouchableOpacity, View } from 'react-native'
import { Post } from '../models/postModel'
export default function PostsScreen() {
@@ -24,25 +24,51 @@ export default function PostsScreen() {
}, [])
)
function approvePost(postID: string) {
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'
})
})
}
function denyPost(postID: string) {
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 (
<View style={styles.container}>
<Text style={styles.text}>Posts</Text>
<View style={{ width: '90%', marginTop: 20 }}></View>
<View style={{ width: '90%', marginTop: 200 }}></View>
{
posts && posts.map(el => (
<View key={el._id} style={styles.posts}>
<Text style={{ color: '#fff' }}>{el._id}</Text>
<View style={{ alignItems: 'center', marginVertical: 10 }}>
<Image
source={{ uri: el.photo }}
style={{ width: 200, height: 200, borderRadius: 8 }}
resizeMode="cover"
/>
</View>
<Text style={{ color: '#fff' }}>{el.notes}</Text>
<View style={{ flexDirection: 'row', justifyContent: 'space-between', marginTop: 10 }}>
<TouchableOpacity style={{ flex: 1, marginRight: 5 }} onPress={() => denyPost(el._id)}>