import React, { useState, useEffect } from 'react';
import { View, Text, TextInput, Button, FlatList, TouchableOpacity } from 'react-native';
import firestore from '@react-native-firebase/firestore';
export default function FirestoreCRUD() {
const [newItem, setNewItem] = useState('');
const [items, setItems] = useState([]);
useEffect(() => {
// TODO: Subscribe to Firestore collection and update items state
}, []);
const addItem = () => {
// TODO: Add new item to Firestore
};
const deleteItem = (id) => {
// TODO: Delete item from Firestore by id
};
const editItem = (id, newText) => {
// TODO: Update item text in Firestore
};
return (
<View style={{ flex: 1, padding: 20 }}>
<Text style={{ fontSize: 24, marginBottom: 10 }}>Firestore CRUD Demo</Text>
<TextInput
placeholder="New Item"
value={newItem}
onChangeText={setNewItem}
style={{ borderWidth: 1, padding: 8, marginBottom: 10 }}
/>
<Button title="Add Item" onPress={addItem} />
<FlatList
data={items}
keyExtractor={item => item.id}
renderItem={({ item }) => (
<View style={{ flexDirection: 'row', justifyContent: 'space-between', marginTop: 10 }}>
<Text>{item.text}</Text>
<View style={{ flexDirection: 'row' }}>
<TouchableOpacity onPress={() => {/* TODO: Trigger edit */}}>
<Text style={{ color: 'blue', marginRight: 10 }}>Edit</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => deleteItem(item.id)}>
<Text style={{ color: 'red' }}>Delete</Text>
</TouchableOpacity>
</View>
</View>
)}
/>
</View>
);
}