mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-19 13:21:46 +00:00
e78c2a97bd
Rebrand: - NOMAD → TREK branding across all UI, translations, server, PWA manifest - New TREK logos (dark/light, with/without icon) - Liquid glass toast notifications Bugs Fixed: - HTTPS redirect now opt-in only (FORCE_HTTPS=true), fixes #33 #43 #52 #54 #55 - PDF export "Tag" fallback uses i18n, fixes #15 - Vacay sharing color collision detection, fixes #25 - Backup settings import fix (PR #47) - Atlas country detection uses smallest bounding box, fixes #31 - JPY and zero-decimal currencies formatted correctly, fixes #32 - HTML lang="en" instead of hardcoded "de", fixes #34 - Duplicate translation keys removed - setSelectedAssignmentId crash fixed New Features: - OSM enrichment: Overpass API for opening hours, Wikimedia Commons for photos - Reverse geocoding on map right-click to add places - OIDC config via environment variables (OIDC_ISSUER, OIDC_CLIENT_ID, etc.), fixes #48 - Multi-arch Docker build (ARM64 + AMD64), fixes #11 - File management: star, trash/restore, upload owner, assign to places/bookings, notes - Markdown rendering in Collab Notes with expand modal, fixes #17 - Type-specific booking fields (flight: airline/number/airports, hotel: check-in/out/days, train: number/platform/seat), fixes #35 - Hotel bookings auto-create accommodations, bidirectional sync - Multiple hotels per day with check-in/check-out color coding - Ko-fi and Buy Me a Coffee support cards - GitHub releases proxy with server-side caching
92 lines
2.8 KiB
TypeScript
92 lines
2.8 KiB
TypeScript
import React, { useState, useEffect } from 'react'
|
|
import { mapsApi } from '../../api/client'
|
|
import { getCategoryIcon } from './categoryIcons'
|
|
import type { Place } from '../../types'
|
|
|
|
interface Category {
|
|
color?: string
|
|
icon?: string
|
|
}
|
|
|
|
interface PlaceAvatarProps {
|
|
place: Pick<Place, 'id' | 'name' | 'image_url' | 'google_place_id' | 'osm_id' | 'lat' | 'lng'>
|
|
size?: number
|
|
category?: Category | null
|
|
}
|
|
|
|
const photoCache = new Map<string, string | null>()
|
|
const photoInFlight = new Set<string>()
|
|
|
|
export default function PlaceAvatar({ place, size = 32, category }: PlaceAvatarProps) {
|
|
const [photoSrc, setPhotoSrc] = useState<string | null>(place.image_url || null)
|
|
|
|
useEffect(() => {
|
|
if (place.image_url) { setPhotoSrc(place.image_url); return }
|
|
const photoId = place.google_place_id || place.osm_id
|
|
if (!photoId && !(place.lat && place.lng)) { setPhotoSrc(null); return }
|
|
|
|
const cacheKey = photoId || `${place.lat},${place.lng}`
|
|
if (photoCache.has(cacheKey)) {
|
|
const cached = photoCache.get(cacheKey)
|
|
if (cached) setPhotoSrc(cached)
|
|
return
|
|
}
|
|
|
|
if (photoInFlight.has(cacheKey)) {
|
|
// Another instance is already fetching, wait for it
|
|
const check = setInterval(() => {
|
|
if (photoCache.has(cacheKey)) {
|
|
clearInterval(check)
|
|
const cached = photoCache.get(cacheKey)
|
|
if (cached) setPhotoSrc(cached)
|
|
}
|
|
}, 200)
|
|
return () => clearInterval(check)
|
|
}
|
|
photoInFlight.add(cacheKey)
|
|
mapsApi.placePhoto(photoId || `coords:${place.lat}:${place.lng}`, place.lat, place.lng, place.name)
|
|
.then((data: { photoUrl?: string }) => {
|
|
if (data.photoUrl) {
|
|
photoCache.set(cacheKey, data.photoUrl)
|
|
setPhotoSrc(data.photoUrl)
|
|
} else {
|
|
photoCache.set(cacheKey, null)
|
|
}
|
|
photoInFlight.delete(cacheKey)
|
|
})
|
|
.catch(() => { photoCache.set(cacheKey, null); photoInFlight.delete(cacheKey) })
|
|
}, [place.id, place.image_url, place.google_place_id, place.osm_id])
|
|
|
|
const bgColor = category?.color || '#6366f1'
|
|
const IconComp = getCategoryIcon(category?.icon)
|
|
const iconSize = Math.round(size * 0.46)
|
|
|
|
const containerStyle: React.CSSProperties = {
|
|
width: size, height: size,
|
|
borderRadius: '50%',
|
|
overflow: 'hidden',
|
|
flexShrink: 0,
|
|
backgroundColor: bgColor,
|
|
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
|
}
|
|
|
|
if (photoSrc) {
|
|
return (
|
|
<div style={containerStyle}>
|
|
<img
|
|
src={photoSrc}
|
|
alt={place.name}
|
|
style={{ width: '100%', height: '100%', objectFit: 'cover' }}
|
|
onError={() => setPhotoSrc(null)}
|
|
/>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<div style={containerStyle}>
|
|
<IconComp size={iconSize} strokeWidth={1.8} color="rgba(255,255,255,0.92)" />
|
|
</div>
|
|
)
|
|
}
|