Files
MyClub/DOCS/ACTIVITIES_FIXES_SUMMARY.md
T
Tomáš Dvořák 12cba639b9 upload
2025-10-16 13:32:05 +02:00

5.2 KiB

Activities Admin Page - Fixes Summary

Issues Fixed

1. AI Parsing Not Working

Problem: AI-generated JSON was appearing as raw text in form fields instead of being parsed.

Solution:

  • Added defensive JSON parsing to handle cases where API returns JSON as a string
  • Improved error handling with detailed error messages
  • Added console logging for debugging
  • Enhanced toast notifications with proper durations

Files Modified:

  • frontend/src/pages/admin/AdminActivitiesPage.tsx (lines 195-217)

2. Map Integration Fixed

Problem:

  • Map coordinates were not being saved to the event
  • Map preview was not showing after import
  • "Poloha nebyla nalezena" error when location wasn't geocoded

Solution:

  • Added latitude and longitude fields to Event model (backend)
  • Updated EventInput to accept coordinates
  • Modified CreateEvent and UpdateEvent controllers to save coordinates
  • Added map preview after importing coordinates
  • Coordinates are now saved when using MapLinkImporter
  • EventLocationMap component now accepts and uses stored coordinates (falls back to geocoding if not provided)

Files Modified:

  • internal/models/event.go - Added YoutubeURL, Latitude, Longitude fields
  • internal/controllers/event_controller.go - Added fields to EventInput, CreateEvent, UpdateEvent
  • frontend/src/types/event.ts - Added latitude, longitude fields
  • frontend/src/pages/admin/AdminActivitiesPage.tsx - Save coordinates on import, show map preview
  • frontend/src/components/events/EventLocationMap.tsx - Accept and use provided coordinates
  • frontend/src/pages/ActivityDetailPage.tsx - Pass coordinates to map component

3. YouTube Video Embed Fixed

Problem: YouTube videos were not displaying correctly due to complex/broken URL parsing.

Solution:

  • Created robust getYouTubeEmbedUrl() helper function that handles:
    • Standard watch URLs: https://www.youtube.com/watch?v=VIDEO_ID
    • Short URLs: https://youtu.be/VIDEO_ID
    • Embed URLs: https://www.youtube.com/embed/VIDEO_ID
    • Already embedded URLs (returns as-is)
  • Properly extracts video ID using regex matching
  • Returns null for invalid URLs

Files Modified:

  • frontend/src/pages/ActivityDetailPage.tsx - Added getYouTubeEmbedUrl helper (lines 37-72)

4. File Attachments - Supported Formats

Problem: No file type restrictions or information about supported formats.

Solution:

  • Added visible list of supported file formats above upload button
  • Implemented file type validation with user-friendly error messages
  • Added accept attribute to file input for browser-level filtering
  • Shows individual error messages for each failed upload

Supported Formats:

  • Documents: PDF, Word (.doc, .docx), Excel (.xls, .xlsx), PowerPoint (.ppt, .pptx)
  • Images: JPG, JPEG, PNG, GIF, WEBP
  • Text: TXT
  • Archives: ZIP, RAR

Files Modified:

  • frontend/src/pages/admin/AdminActivitiesPage.tsx - Added file type validation (lines 864-910)

Database Schema Changes

The following fields were added to the events table (via AutoMigrate):

  • youtube_url VARCHAR(500) - Stores YouTube video URL
  • latitude FLOAT - Stores location latitude (nullable)
  • longitude FLOAT - Stores location longitude (nullable)

Note: AutoMigrate is called on every CreateEvent/UpdateEvent operation, so the schema will update automatically when the server restarts.


Testing Checklist

AI Generation

  • Test AI generation with various prompts
  • Verify title and description fields are populated correctly
  • Test with "Přepsat existující obsah" checkbox on/off
  • Verify different tone settings work

Map Integration

  • Import coordinates from Google Maps link
  • Import coordinates from Mapy.cz link
  • Verify map preview shows after import
  • Create event and verify coordinates are saved
  • Edit existing event - verify map loads with saved coordinates
  • View event detail page - verify map shows correctly

YouTube Videos

  • Add YouTube video using standard watch URL
  • Add YouTube video using short youtu.be URL
  • Add YouTube video from club channel selector
  • View event detail page - verify video embeds correctly
  • Test with various YouTube URL formats

File Attachments

  • Upload supported file types (PDF, Word, Excel, etc.)
  • Try uploading unsupported file type - verify error message
  • Upload multiple files at once
  • Verify file list shows with correct sizes
  • Remove attachment - verify it's removed from list

Form Validation

  • Try submitting without required fields - verify error messages
  • Verify "Název" and "Začátek" show required field errors

Next Steps

  1. Backend: Restart the Go server to apply database schema changes
  2. Frontend: Rebuild the React app if needed
  3. Testing: Run through the testing checklist above
  4. Monitoring: Check server logs for any migration warnings or errors

Additional Improvements Made

  • Enhanced coordinate state management in admin modal (initialize/clear on open/close)
  • Improved error messages throughout the form
  • Better loading states and user feedback
  • Consistent toast notification durations
  • Better TypeScript typing for coordinates (number | null)