mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-03 18:22:57 +00:00
8.5 KiB
8.5 KiB
Logo Enhancement System - Implementation Summary
Overview
Enhanced the logo fetching system to use logoapi.sportcreative.eu with local caching, SVG optimization, and proper formatting across all components.
Key Features Implemented
1. Enhanced Logo Management (sportLogosAPI.ts)
- IndexedDB Local Caching: Logos are cached locally for 7 days for fast loading
- Automatic Cleanup: Unused logos are automatically deleted after 30 days
- SVG Optimization: SVG files are optimized to remove empty space and fix viewBox
- Fallback Chain: logoapi → FACR → placeholder
- Cache Invalidation: Smart cache with timestamp validation
Key Functions:
fetchLogoFromLogoAPI(teamId, teamName): Fetches from logoapi with cachinggetTeamLogo(teamId, teamName, facrLogo): Main function with fallback chainbatchFetchLogosFromSportLogosAPI(teamIds): Batch fetch multiple logoscleanupUnusedLogos(): Removes stale cached logosoptimizeSVG(svgUrl): Removes padding and optimizes SVG viewBox
2. Reusable TeamLogo Component (TeamLogo.tsx)
New component that handles logo fetching and display with:
- Automatic logoapi integration
- Loading states with skeleton
- Error handling with fallbacks
- Configurable sizes (small/medium/large/custom)
- Proper centering and formatting
Usage Example:
<TeamLogo
teamId="12345"
teamName="FC Example"
facrLogo={match.home_logo_url}
size="medium"
/>
3. CSS Utilities (logos.css)
Added comprehensive CSS for logo formatting:
.match-logo-small(24px).match-logo-medium(32px).match-logo-large(48px).logo-container: Flex centering wrapper.team-logo: Proper object-fit and positioning- Loading animations
- Special styles for next match hero logos
4. Component Updates
Updated Components:
- MatchesWidget: Now uses TeamLogo component with proper centering
- MatchesSection: Updated to use TeamLogo with team IDs
- CompetitionMatches: Enhanced with TeamLogo and proper spacing
- HomePage: Added cleanup call and logo CSS import
All match displays now show logos:
- Centered vertically in their containers
- Properly sized without distortion
- With consistent spacing
- Using logoapi when available
SVG Optimization Details
The SVG optimization process:
- Fetches the SVG file
- Parses it with DOMParser
- Creates temporary DOM element to calculate bounding box
- Adjusts viewBox to content bounds (removes padding)
- Removes width/height attributes for responsive scaling
- Serializes and creates blob URL
- Caches the optimized version
This ensures SVGs don't have empty space and scale perfectly.
Cache Management
Storage Strategy:
- Location: IndexedDB (browser-native, large capacity)
- Duration: 7 days
- Cleanup: Unused logos (not accessed in 30 days) are auto-deleted
- Indexes: By
lastUsedandsourcefor efficient queries
Benefits:
- Fast logo loading (instant from cache)
- Reduced API calls to logoapi
- Offline support
- Automatic storage management
Integration with logoapi.sportcreative.eu
API Endpoint:
GET https://logoapi.sportcreative.eu/logos/{teamId}/json
Response Structure:
{
"logo_url_svg": "https://...",
"logo_url_png": "https://...",
"logo_url": "https://..."
}
Priority:
- SVG (optimized for web)
- PNG (fallback)
- Generic logo_url
SetupPage Integration
The SetupPage already has logoapi integration:
- Fetches logos from logoapi during club selection
- Falls back to FACR if not available
- Uploads new logos to both logoapi and loga.sportcreative.eu
- Shows source indicator (✓ logoapi.sportcreative.eu / FAČR / Nahráno)
Formatting Improvements
Before:
- Logos with empty space causing alignment issues
- Inconsistent sizing across components
- No caching (slow repeated loads)
- FACR logos only (limited availability)
After:
- Logos perfectly centered without empty space
- Consistent sizing (24px/28px/32px/48px/64px)
- Fast loading with IndexedDB cache
- logoapi first (broader coverage), FACR fallback
- SVG optimization for perfect scaling
- Automatic cleanup of unused logos
Match Display Formatting
Upcoming Matches Widget:
- Logos in 24px containers
- Perfect vertical centering
- Proper spacing between logo and team name
- Fallback icon (football) if logo fails
Match Rows (MatchesSection, CompetitionMatches):
- Logos in 28px containers
- Centered in flex containers
- Team names properly truncated
- Score display centered between teams
Hero/Featured Matches:
- Larger logos (48-64px)
- Enhanced with drop shadows
- Background effects for visual appeal
- Proper spacing in hero sections
Testing Checklist
To verify the implementation:
-
Initial Load:
- Check browser DevTools → Application → IndexedDB → LogoCache
- Verify logos are being cached
-
Logo Display:
- Check MatchesWidget - logos should be centered
- Check Calendar page - match rows properly formatted
- Check Tables page - team logos visible
- Check HomePage - all variants (Unified/Magazine/Pro/Edge)
-
Performance:
- First load: Network requests to logoapi
- Second load: Instant from cache (no network requests)
- Check cache cleanup after 30 days of non-use
-
Fallbacks:
- logoapi available: Use logoapi logo
- logoapi unavailable: Use FACR logo
- Both unavailable: Show placeholder
-
SVG Optimization:
- Inspect SVG logos in DevTools
- Verify viewBox is set correctly
- No extra padding around logo content
Files Modified
New Files:
frontend/src/utils/sportLogosAPI.ts(enhanced)frontend/src/components/common/TeamLogo.tsx(new)frontend/src/styles/logos.css(new)
Updated Files:
frontend/src/components/widgets/MatchesWidget.tsxfrontend/src/components/home/MatchesSection.tsxfrontend/src/components/home/CompetitionMatches.tsxfrontend/src/pages/HomePage.tsx
API Usage
logoapi.sportcreative.eu:
- Base URL:
https://logoapi.sportcreative.eu - Endpoint:
/logos/{teamId}/json - Method: GET
- Headers:
Accept: application/json - Response: JSON with logo URLs (SVG/PNG)
- Caching: 7 days local, honors HTTP cache headers
Future Enhancements
Potential improvements:
- Batch API: If logoapi adds batch endpoint, update
batchFetchLogosFromSportLogosAPI - WebP Support: Add WebP format preference for better compression
- Service Worker: Cache logos at service worker level for offline
- Image Optimization: Server-side image optimization pipeline
- CDN Integration: Serve cached logos from CDN
- Admin Upload: Direct upload interface in admin panel
- Logo Variants: Support for dark/light mode logo variants
Performance Metrics
Expected improvements:
- First Load: ~100-300ms per logo (network)
- Cached Load: <5ms per logo (IndexedDB)
- Storage Usage: ~50-200KB per logo (SVG optimized)
- Cache Hit Rate: >90% after initial page load
Browser Compatibility
Requires:
- IndexedDB support (all modern browsers)
- DOMParser (all modern browsers)
- Blob URLs (all modern browsers)
- SVGSVGElement.getBBox() (all modern browsers)
Troubleshooting
Issue: Logos not loading
- Check browser console for errors
- Verify logoapi.sportcreative.eu is accessible
- Check IndexedDB in DevTools
Issue: Logos not centered
- Verify CSS file is imported
- Check flex container styles
- Ensure image has object-fit: contain
Issue: Cache not working
- Check IndexedDB permissions
- Clear site data and retry
- Verify browser supports IndexedDB
Issue: SVG optimization failing
- Check SVG structure is valid
- Verify CORS headers allow fetching
- Fallback to original URL on error
Maintenance
Regular Tasks:
- Monitor logoapi availability
- Check cache size in production
- Review logo quality and coverage
- Update fallback logic if needed
When Adding New Components:
- Import TeamLogo component
- Import logos.css
- Use consistent size props
- Test with and without logoapi access
Summary
This enhancement provides a robust, performant logo management system that:
- ✅ Fetches from logoapi.sportcreative.eu first
- ✅ Caches locally for fast access
- ✅ Optimizes SVGs to remove empty space
- ✅ Properly formats and centers logos everywhere
- ✅ Falls back gracefully when logos unavailable
- ✅ Automatically cleans up unused logos
- ✅ Works across all homepage styles
- ✅ Provides reusable TeamLogo component
- ✅ Maintains consistent sizing
- ✅ Handles errors gracefully
The system is production-ready and fully integrated across the application.