feat: implement photo management features in the application
Deploy Development / deploy (push) Successful in 55s
Build Test / pytest-backend (push) Successful in 5s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 24s

- Added a new `resolve_photo_path` function to handle legacy and new photo paths effectively.
- Updated the photo upload process to store only filenames in the database, improving path resolution.
- Enhanced the photo retrieval and deletion processes to utilize the new path resolution logic.
- Introduced a dedicated PhotosCapturePage for managing photo uploads and viewing.
- Updated the dashboard and navigation to include links to the new photo management features.
- Improved the photo grid display with sorting and deletion capabilities for better user experience.
This commit is contained in:
Lars committed 2026-04-19 09:20:28 +02:00
1 parent 7676897fda
commit c91317df8e
9 files changed
+417 -38

No files matched your search

+203
View File
@@ -0,0 +1,203 @@
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'
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 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)
}
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 (
<div className="capture-page">
<h1 className="page-title" style={{ marginBottom: 16 }}>
Fotos
</h1>
<div className="card section-gap">
<div className="card-title badge-container-right">
<span>Neues Foto</span>
{photoUsage && <UsageBadge {...photoUsage} />}
</div>
<p style={{ fontSize: 13, color: 'var(--text2)', marginTop: 0, marginBottom: 14, lineHeight: 1.5 }}>
Fortschrittsfotos unabhängig von Umfängen. Pro Tag beliebig viele Aufnahmen möglich — Datum ist das
Zuordnungsdatum (z. B. Aufnahmezeitpunkt).
</p>
<div className="form-row">
<label className="form-label">Zuordnungsdatum</label>
<input
type="date"
className="form-input"
style={{ width: '100%', maxWidth: 220 }}
value={date}
onChange={(e) => setDate(e.target.value)}
/>
<span className="form-unit" />
</div>
<input
ref={fileRef}
type="file"
accept="image/*"
multiple
style={{ display: 'none' }}
onChange={onPickFiles}
/>
{error && (
<div
style={{
padding: '10px',
background: 'var(--danger-bg)',
border: '1px solid var(--danger)',
borderRadius: 8,
fontSize: 13,
color: 'var(--danger)',
marginBottom: 10,
}}
>
{error}
</div>
)}
<button
type="button"
className="btn btn-primary btn-full"
disabled={uploading || blocked}
title={
blocked
? `Limit erreicht (${photoUsage.used}/${photoUsage.limit}).`
: undefined
}
onClick={() => fileRef.current?.click()}
>
<Camera size={16} style={{ marginRight: 8 }} />
{uploading ? 'Wird hochgeladen…' : 'Foto(s) auswählen'}
</button>
</div>
<div className="card section-gap">
<div className="card-title">Meine Fotos ({photos.length})</div>
{!photos.length ? (
<div style={{ fontSize: 13, color: 'var(--text3)', padding: '8px 0' }}>Noch keine Fotos.</div>
) : (
<>
{big && (
<div
style={{
position: 'fixed',
inset: 0,
background: 'rgba(0,0,0,0.9)',
zIndex: 100,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
onClick={() => setBig(null)}
role="presentation"
>
<img src={api.photoUrl(big)} style={{ maxWidth: '100%', maxHeight: '100%', borderRadius: 8 }} alt="" />
</div>
)}
<div className="photo-grid">
{photos.map((p) => (
<div key={p.id} style={{ position: 'relative' }}>
<img
src={api.photoUrl(p.id)}
className="photo-thumb"
alt=""
onClick={() => setBig(p.id)}
/>
<div
style={{
position: 'absolute',
bottom: 4,
left: 4,
fontSize: 9,
background: 'rgba(0,0,0,0.6)',
color: 'white',
padding: '1px 4px',
borderRadius: 3,
}}
>
{p.date?.slice(0, 10) || p.created?.slice(0, 10)}
</div>
<button
type="button"
className="btn btn-secondary"
style={{
position: 'absolute',
top: 4,
right: 4,
padding: 6,
minWidth: 0,
borderRadius: 8,
}}
title="Löschen"
onClick={(e) => {
e.stopPropagation()
handleDelete(p.id)
}}
>
<Trash2 size={14} />
</button>
</div>
))}
</div>
</>
)}
</div>
</div>
)
}