diff --git a/src/app/admin/page.tsx b/src/app/admin/page.tsx index f2530f9..904ca18 100644 --- a/src/app/admin/page.tsx +++ b/src/app/admin/page.tsx @@ -246,6 +246,10 @@ export default function AdminPage() { notify('Footer info updated.'); }; + const [uploadCategory, setUploadCategory] = useState('other'); + const [uploadRoomId, setUploadRoomId] = useState(''); + const [uploadLocationTarget, setUploadLocationTarget] = useState('gallery'); + const handleUpload = (e: React.ChangeEvent) => { const files = e.target.files; if (!files) return; @@ -253,15 +257,17 @@ export default function AdminPage() { const reader = new FileReader(); reader.onload = async () => { const data = reader.result as string; + const body: Record = { filename: file.name, data, category: uploadCategory, location_target: uploadLocationTarget }; + if (uploadCategory === 'rooms' && uploadRoomId) body.room_id = Number(uploadRoomId); const res = await fetch('/api/admin/images', { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ filename: file.name, data }), + body: JSON.stringify(body), credentials: 'same-origin', }); if (!res.ok) { setError('Upload failed'); return; } const result = await res.json(); - setImages((prev) => [{ ...result.image, data }, ...prev]); + setImages((prev) => [{ ...result.image, data, category: uploadCategory }, ...prev]); setCount((prev) => prev + 1); }; reader.readAsDataURL(file); @@ -525,10 +531,61 @@ export default function AdminPage() { - +
+
+ + + {uploadCategory === 'rooms' && ( + + )} + + +
+ + +
+ {images.length === 0 ? (

No images uploaded yet.

) : ( @@ -560,7 +617,7 @@ export default function AdminPage() { ))} )} - +
@@ -587,7 +644,7 @@ export default function AdminPage() {
[s.title || '(untitled)', s.image_url ? '🖼️ image' : 'no image', s.active ? 'On' : 'Off', `#${s.sort_order}`])} onEdit={(i) => editSlide(slides[i])} onDelete={(i) => deleteSlide(slides[i].id)} /> - +
@@ -625,7 +682,7 @@ export default function AdminPage() {
[ev.date, ev.title, ev.type, ev.active ? 'On' : 'Off'])} onEdit={(i) => editEvent(events[i])} onDelete={(i) => deleteEvent(events[i].id)} /> - +
@@ -690,7 +747,7 @@ export default function AdminPage() { )} )} - + @@ -745,7 +802,7 @@ export default function AdminPage() { )} )} - + @@ -768,7 +825,7 @@ export default function AdminPage() { [m.category, m.name, `$${m.price}`, m.is_daily_special ? '★ Daily' : '', m.active ? 'On' : 'Off', `#${m.sort_order}`])} onEdit={(i) => editMenu(menu[i])} onDelete={(i) => deleteMenu(menu[i].id)} /> - +
@@ -795,7 +852,7 @@ export default function AdminPage() {
[p.name, `${p.distance_km || ''} km`, p.description.slice(0, 60), p.photos.length > 0 ? `🖼️ ${p.photos.length}` : 'no image', p.active ? 'On' : 'Off', `#${p.sort_order}`])} onEdit={(i) => editPlace(places[i])} onDelete={(i) => deletePlace(places[i].id)} /> - +
{reviews.length === 0 ?

No pending reviews.

: ( @@ -1205,4 +1262,6 @@ function StatsCards({ stats }: { stats: { label: string; value: string | number ))} ); + ); +} } diff --git a/src/lib/schema.ts b/src/lib/schema.ts index f113f38..a734aa3 100644 --- a/src/lib/schema.ts +++ b/src/lib/schema.ts @@ -20,6 +20,8 @@ export async function initSchema() { id SERIAL PRIMARY KEY, filename VARCHAR(255) NOT NULL, data TEXT NOT NULL, + category VARCHAR(100) DEFAULT 'other', + room_id INTEGER REFERENCES rooms(id) ON DELETE SET NULL, uploaded_at TIMESTAMP DEFAULT NOW() ); `);