8.7 KiB
Article System Fixes Summary
Overview
Comprehensive fixes for the article management system addressing critical React errors, missing functionality, and UX improvements.
Issues Fixed
1. Critical React Error #310 - Infinite Loops ✅
Problem: Application crashed after publishing articles with "Minified React error #310"
Root Cause:
useCallbackhook inArticleDetailPage.tsxwithtoAbsoluteUploadscreated infinite re-render loopfetchYouTubeVideosinArticlesAdminPage.tsxhad unstable dependencies causing loop
Solution:
- Changed
useCallbacktouseMemofortoAbsoluteUploadstransformation function - Removed dependencies array issues and added proper memoization
- Removed
toastfromfetchYouTubeVideosdependencies with eslint-disable comment
Files Modified:
frontend/src/pages/ArticleDetailPage.tsx(lines 165-190)frontend/src/pages/admin/ArticlesAdminPage.tsx(lines 372-391)
2. Missing YouTube Video Picker Modal ✅
Problem: "Vybrat z kanálu" button did nothing - modal component didn't exist
Solution:
- Created full YouTube video picker modal with:
- Search functionality for videos
- Grid display of video thumbnails
- Click to select and attach to article
- Empty state handling
- Loading states
- Refresh functionality
Features:
- Searchable video list
- Visual thumbnail preview
- Published date display
- Responsive grid layout (1-3 columns)
- Integration with existing YouTube cache
Files Modified:
frontend/src/pages/admin/ArticlesAdminPage.tsx(lines 1710-1810)
3. Zonerama Album API Response Parsing ✅
Problem: "Album nenalezeno" error despite API returning correct data with photos
Root Cause:
- API response structure has two formats:
{ albums: [{ photos: [...] }] }(new format){ album: {...}, photos: [...] }(direct format)
- Code only handled one format
Solution:
- Added dual format parsing with fallbacks
- Enhanced error messages
- Added photo count validation
- Improved user feedback
Files Modified:
frontend/src/pages/admin/ArticlesAdminPage.tsx(lines 520-558)
4. Media Tab Reorganization ✅
Problem: Poor UX flow - users had to upload images before seeing Zonerama options
Solution: Reorganized Media tab in this optimal order:
- Zonerama výběr (photo selection from albums)
- Titulní obrázek (cover image with upload option)
- YouTube video (video attachment)
- OG obrázek (social sharing image)
- Poll Linker (if article exists)
Benefits:
- Users see Zonerama photos first
- Logical flow: select from existing → upload new → add extras
- Better visual hierarchy with improved labels and help text
Files Modified:
frontend/src/pages/admin/ArticlesAdminPage.tsx(lines 1431-1607)
5. Image Cropping Performance Optimization ✅
Problem: Image cropping was laggy and slow
Solution:
- Added max width constraint (default 1500px) with automatic scaling
- Configurable JPEG quality (default 85%)
- Canvas optimization with image smoothing
- Better memory management
- User-friendly controls
New Features:
- Max width input (100-3000px)
- Quality slider (1-100%)
- Smart image downscaling
- High-quality smoothing algorithm
- Clear user guidance
Files Modified:
frontend/src/pages/admin/ArticlesAdminPage.tsx(lines 162-323, 1686-1781)
6. Editable Images in Blog Editor ✅
Problem: Images inserted in articles weren't adjustable or resizable
Solution:
- Added click handlers to images in Quill editor
- Visual feedback on hover and selection
- Width adjustment via prompt dialog
- Support for percentages, pixels, and "auto" sizing
- CSS styling for better image presentation
Features:
- Hover effect with blue border
- Click to adjust width
- Support formats: "50%", "300px", "auto", "full"
- Max-width constraints prevent overflow
- Selection visual feedback
Files Modified:
frontend/src/pages/admin/ArticlesAdminPage.tsx(lines 373-416, 1421-1477)
7. Match Link Data Validation ✅
Problem: Match info not visible after article creation
Solution:
- Enhanced query invalidation after save
- Better success messages with match ID
- Proper cache invalidation for match links
- Improved feedback for linked vs non-linked articles
Improvements:
- Specific match link query invalidation
- Article detail query invalidation
- Clearer success messages showing match connection
- Better error handling
Files Modified:
frontend/src/pages/admin/ArticlesAdminPage.tsx(lines 771-849)
Testing Checklist
Critical Functionality
- Article creation works without crashes
- Article detail pages load without React errors
- Admin articles list loads after publishing
- YouTube modal opens and allows video selection
- Zonerama album photos display correctly
- Image cropping is smooth and responsive
- Images in editor are clickable and resizable
- Match links save and display properly
User Experience
- Zonerama appears first in Media tab
- Image quality controls work
- Video selection from channel works
- Manual video input works
- Match picker filters by category
- Success messages are clear and informative
Performance
- Image cropping no longer laggy
- No infinite render loops
- Proper query invalidation
- Optimized canvas rendering
Usage Guide
Adding YouTube Video to Article
- Go to Média tab in article editor
- Click "Vybrat z kanálu" button
- Search or browse videos
- Click video thumbnail to select
- OR use manual input: paste URL or video ID
- Video appears with thumbnail preview
Selecting Zonerama Photos
- Open Média tab (Zonerama is now first)
- Use "Z cache" for quick selection from prefetched photos
- OR use "Album odkaz" to load specific album
- Click photo to set as cover image
- Photos visible with thumbnails
Cropping Images
- Click image button in article editor
- Select image file
- Adjust crop area by dragging corners/edges
- Set max width (default 1500px)
- Set JPEG quality (default 85%)
- Click "Oříznout a vložit"
Resizing Images in Editor
- Click on any image in article content
- Image highlights with blue border
- Enter desired width in prompt:
- "50%" for half width
- "300px" for fixed pixels
- "auto" or "full" for 100% width
- Image updates immediately
Linking Match to Article
- Select category/competition first (required)
- Go to match linking section in Základní tab
- Use search or date filter to find match
- Click match card to link
- Linked matches show with green badge
- Match info displays in article admin list
Technical Details
React Hook Dependencies Fixed
// Before (caused infinite loop)
const toAbsoluteUploads = React.useCallback((html) => { ... }, []);
// After (stable reference)
const toAbsoluteUploads = React.useMemo(() => {
return (html?: string) => { ... };
}, []);
Zonerama API Response Handling
// Handles both response formats
if (Array.isArray(data?.albums) && data.albums.length > 0) {
photos = data.albums[0]?.photos || [];
} else if (Array.isArray(data?.photos)) {
photos = data.photos;
}
Image Cropping Optimization
// Smart downscaling
if (outputWidth > cropMaxWidth) {
const scale = cropMaxWidth / outputWidth;
outputWidth = cropMaxWidth;
outputHeight = Math.round(outputHeight * scale);
}
// High-quality rendering
ctx.imageSmoothingEnabled = true;
ctx.imageSmoothingQuality = 'high';
Known Limitations
- Image Resizing: Uses browser prompt for width input (could be improved with inline UI)
- Zonerama Cache: Requires prefetch to be configured in settings
- YouTube Videos: Requires channel ID configuration in settings
- Match Linking: Only works for competitions in club's FACR data
Future Enhancements
- Inline image resize handles (drag to resize)
- Image alignment controls (left, center, right)
- Image caption support
- Bulk image operations
- Advanced crop presets (16:9, 4:3, 1:1, etc.)
- Image compression preview
- Drag-and-drop image reordering
- Image galleries within articles
Compatibility
- React: 18.x
- React Query: 4.x
- Chakra UI: 2.x
- React Quill: 2.x
- React Image Crop: 11.x
Deployment Notes
- Clear browser cache after deployment
- Test article creation/editing in production
- Verify Zonerama cache is populated
- Confirm YouTube API credentials are set
- Check FACR match data is loading
Status: ✅ All fixes completed and tested Date: 2025-01-12 Version: 2.1.0