import { useState, useEffect, useRef } from 'react' import { Camera, Trash2 } from 'lucide-react' import dayjs from 'dayjs' import { api } from '../utils/api' import UsageBadge from '../components/UsageBadge' import { formatPhotoCaption } from '../utils/photoDisplay' export default function PhotosCapturePage() { const [date, setDate] = useState(() => dayjs().format('YYYY-MM-DD')) const [photos, setPhotos] = useState([]) const [photoUsage, setPhotoUsage] = useState(null) const [uploading, setUploading] = useState(false) const [error, setError] = useState(null) const [big, setBig] = useState(null) const [skipExif, setSkipExif] = useState(false) const fileRef = useRef(null) const load = () => api.listPhotos().then(setPhotos).catch(() => setPhotos([])) const loadUsage = () => { api .getFeatureUsage() .then((features) => { const f = features.find((x) => x.feature_id === 'photos') setPhotoUsage(f) }) .catch(() => setPhotoUsage(null)) } useEffect(() => { load() loadUsage() }, []) const onPickFiles = async (e) => { const files = Array.from(e.target.files || []) e.target.value = '' if (!files.length) return setError(null) setUploading(true) try { for (const file of files) { await api.uploadPhoto(file, date, { skipExif }) } await load() await loadUsage() } catch (err) { setError(err.message || 'Upload fehlgeschlagen') } finally { setUploading(false) } } const handleDelete = async (id) => { if (!confirm('Dieses Foto löschen?')) return try { await api.deletePhoto(id) if (big === id) setBig(null) await load() } catch (err) { alert(err.message || 'Löschen fehlgeschlagen') } } const blocked = photoUsage && !photoUsage.allowed return (
Reihenfolge: zuerst EXIF (Aufnahme aus dem Bild), sonst die{' '} Datei-Zeit (Letzte Änderung der Datei, wie vom Browser übermittelt), sonst das Fallback-Datum unten (Standard: heute).