import { useState, useEffect } from 'react'; import { Database, Plus, Trash2 } from 'lucide-react'; export default function PocketBase() { const [items, setItems] = useState([]); const [newItem, setNewItem] = useState(''); const [loading, setLoading] = useState(false); // Simulate fetching data on mount useEffect(() => { fetchItems(); }, []); const fetchItems = async () => { try { const res = await fetch('/api/pocketbase'); const data = await res.json(); setItems(data.items || []); } catch (error) { console.error('Failed to fetch items'); } }; const addItem = async () => { if (!newItem.trim()) return; setLoading(true); try { const res = await fetch('/api/pocketbase', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: newItem }), }); if (res.ok) { setNewItem(''); fetchItems(); } } catch (error) { console.error('Failed to add item'); } finally { setLoading(false); } }; return (
No records found
) : ( items.map((item, index) => (