Spaces:
Sleeping
Sleeping
Upload components/PocketBase.js with huggingface_hub
Browse files- components/PocketBase.js +87 -0
components/PocketBase.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useState, useEffect } from 'react';
|
| 2 |
+
import { Database, Plus, Trash2 } from 'lucide-react';
|
| 3 |
+
|
| 4 |
+
export default function PocketBase() {
|
| 5 |
+
const [items, setItems] = useState([]);
|
| 6 |
+
const [newItem, setNewItem] = useState('');
|
| 7 |
+
const [loading, setLoading] = useState(false);
|
| 8 |
+
|
| 9 |
+
// Simulate fetching data on mount
|
| 10 |
+
useEffect(() => {
|
| 11 |
+
fetchItems();
|
| 12 |
+
}, []);
|
| 13 |
+
|
| 14 |
+
const fetchItems = async () => {
|
| 15 |
+
try {
|
| 16 |
+
const res = await fetch('/api/pocketbase');
|
| 17 |
+
const data = await res.json();
|
| 18 |
+
setItems(data.items || []);
|
| 19 |
+
} catch (error) {
|
| 20 |
+
console.error('Failed to fetch items');
|
| 21 |
+
}
|
| 22 |
+
};
|
| 23 |
+
|
| 24 |
+
const addItem = async () => {
|
| 25 |
+
if (!newItem.trim()) return;
|
| 26 |
+
setLoading(true);
|
| 27 |
+
try {
|
| 28 |
+
const res = await fetch('/api/pocketbase', {
|
| 29 |
+
method: 'POST',
|
| 30 |
+
headers: { 'Content-Type': 'application/json' },
|
| 31 |
+
body: JSON.stringify({ name: newItem }),
|
| 32 |
+
});
|
| 33 |
+
if (res.ok) {
|
| 34 |
+
setNewItem('');
|
| 35 |
+
fetchItems();
|
| 36 |
+
}
|
| 37 |
+
} catch (error) {
|
| 38 |
+
console.error('Failed to add item');
|
| 39 |
+
} finally {
|
| 40 |
+
setLoading(false);
|
| 41 |
+
}
|
| 42 |
+
};
|
| 43 |
+
|
| 44 |
+
return (
|
| 45 |
+
<div className="bg-slate-800 rounded-xl p-6 shadow-xl border border-slate-700">
|
| 46 |
+
<div className="flex items-center gap-2 mb-4">
|
| 47 |
+
<Database className="w-5 h-5 text-emerald-500" />
|
| 48 |
+
<h2 className="text-lg font-semibold text-white">PocketBase Manager</h2>
|
| 49 |
+
</div>
|
| 50 |
+
|
| 51 |
+
<div className="flex gap-2 mb-6">
|
| 52 |
+
<input
|
| 53 |
+
type="text"
|
| 54 |
+
value={newItem}
|
| 55 |
+
onChange={(e) => setNewItem(e.target.value)}
|
| 56 |
+
placeholder="Add new record..."
|
| 57 |
+
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"
|
| 58 |
+
/>
|
| 59 |
+
<button
|
| 60 |
+
onClick={addItem}
|
| 61 |
+
disabled={loading}
|
| 62 |
+
className="bg-emerald-600 hover:bg-emerald-500 text-white px-4 py-2 rounded-lg transition-colors disabled:opacity-50"
|
| 63 |
+
>
|
| 64 |
+
<Plus className="w-5 h-5" />
|
| 65 |
+
</button>
|
| 66 |
+
</div>
|
| 67 |
+
|
| 68 |
+
<div className="space-y-2 max-h-64 overflow-y-auto">
|
| 69 |
+
{items.length === 0 ? (
|
| 70 |
+
<p className="text-slate-500 text-sm text-center py-4">No records found</p>
|
| 71 |
+
) : (
|
| 72 |
+
items.map((item, index) => (
|
| 73 |
+
<div
|
| 74 |
+
key={index}
|
| 75 |
+
className="flex items-center justify-between bg-slate-900 p-3 rounded-lg border border-slate-700 group hover:border-slate-500 transition-colors"
|
| 76 |
+
>
|
| 77 |
+
<span className="text-slate-300">{item.name || item.id}</span>
|
| 78 |
+
<button className="text-red-400 opacity-0 group-hover:opacity-100 transition-opacity hover:text-red-300">
|
| 79 |
+
<Trash2 className="w-4 h-4" />
|
| 80 |
+
</button>
|
| 81 |
+
</div>
|
| 82 |
+
))
|
| 83 |
+
)}
|
| 84 |
+
</div>
|
| 85 |
+
</div>
|
| 86 |
+
);
|
| 87 |
+
}
|