import { useState, useEffect } from 'react'; import { Database, Plus, Trash2, RefreshCw } from 'lucide-react'; export default function PocketBase() { const [items, setItems] = useState([]); const [newItem, setNewItem] = useState(''); const [loading, setLoading] = useState(false); const [actionLoading, setActionLoading] = useState(false); const fetchItems = async () => { setLoading(true); try { const res = await fetch('/api/pocketbase'); const data = await res.json(); setItems(data.items || []); } catch (error) { console.error('Failed to fetch items'); } finally { setLoading(false); } }; useEffect(() => { fetchItems(); }, []); const addItem = async () => { if (!newItem.trim()) return; setActionLoading(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 { setActionLoading(false); } }; const deleteItem = async (id) => { setActionLoading(true); try { const res = await fetch('/api/pocketbase', { method: 'DELETE', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ id }), }); if (res.ok) { fetchItems(); } } catch (error) { console.error('Failed to delete item'); } finally { setActionLoading(false); } }; return (

PocketBase Manager

setNewItem(e.target.value)} onKeyDown={(e) => e.key === 'Enter' && addItem()} placeholder="Add new record..." className="flex-1 bg-slate-900 border border-slate-600 rounded-lg px-4 py-2 text-white placeholder-slate-500 focus:ring-2 focus:ring-emerald-500 focus:border-transparent outline-none" />
{loading ? (

Loading records...

) : items.length === 0 ? (

No records found

) : ( items.map((item) => (
{item.name || item.id}
)) )}
); }