diff --git a/backend/go.mod b/backend/go.mod index 1d5bfdc..018bfa6 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -10,7 +10,7 @@ require ( github.com/mattn/go-sqlite3 v1.14.19 github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef - github.com/PuerkitoBio/goquery v1.9.2 + golang.org/x/text v0.14.0 ) require ( diff --git a/backend/handlers.go b/backend/handlers.go index 1c377fd..e1c8062 100644 --- a/backend/handlers.go +++ b/backend/handlers.go @@ -1,12 +1,12 @@ package main import ( - "bytes" + "bytes" "database/sql" "fmt" "log" "net/http" - neturl "net/url" + neturl "net/url" "os" "path/filepath" "strconv" @@ -18,34 +18,18 @@ import ( "github.com/PuerkitoBio/goquery" "github.com/gin-gonic/gin" "github.com/google/uuid" - "github.com/PuerkitoBio/goquery" - "golang.org/x/text/unicode/norm" - "unicode" + "golang.org/x/text/unicode/norm" ) - - // ==================== Club Handlers ==================== func searchClubs(c *gin.Context) { - q := strings.TrimSpace(c.Query("q")) - if q == "" { q := strings.TrimSpace(c.Query("q")) if q == "" { c.JSON(http.StatusBadRequest, gin.H{"error": "query parameter 'q' is required"}) return } - clubs, err := scrapeFotbalSearch(q) - if err != nil || len(clubs) == 0 { - nq := removeDiacritics(strings.ToLower(q)) - if nq != strings.ToLower(q) { - if c2, err2 := scrapeFotbalSearch(nq); err2 == nil && len(c2) > 0 { - c.JSON(http.StatusOK, c2) - return - } - } - c.JSON(http.StatusOK, getDemoClubs(q)) clubs, err := scrapeFotbalSearch(q) if err != nil || len(clubs) == 0 { nq := removeDiacritics(strings.ToLower(q)) @@ -69,8 +53,6 @@ func getClub(c *gin.Context) { return } - club, err := fetchClubByID(id) - if err != nil || club == nil { club, err := fetchClubByID(id) if err != nil || club == nil { c.JSON(http.StatusNotFound, gin.H{"error": "club not found"}) @@ -513,7 +495,6 @@ func getLogoWithMetadata(c *gin.Context) { // List all logos func listLogos(c *gin.Context) { q := strings.TrimSpace(c.Query("q")) - sport := strings.ToLower(strings.TrimSpace(c.DefaultQuery("sport", c.DefaultQuery("type", "")))) sortParam := c.DefaultQuery("sort", "name") limitStr := c.Query("limit") pageStr := c.Query("page") @@ -610,7 +591,9 @@ func listLogos(c *gin.Context) { args2 = append(args2, limit) if pageStr != "" { if page, err := strconv.Atoi(pageStr); err == nil { - if page < 1 { page = 1 } + if page < 1 { + page = 1 + } offset := (page - 1) * limit limitClause2 += " OFFSET ?" args2 = append(args2, offset) @@ -643,10 +626,16 @@ func listLogos(c *gin.Context) { &logo.PrimaryFormat, &logo.CreatedAt, &logo.UpdatedAt, - ); err != nil { continue } + ); err != nil { + continue + } logo.HasSVG = hasSVG2 == 1 logo.HasPNG = hasPNG2 == 1 - if logo.HasPNG { logo.LogoURL = fmt.Sprintf("%s/logos/%s?format=png", baseURL, logo.ID) } else if logo.HasSVG { logo.LogoURL = fmt.Sprintf("%s/logos/%s?format=svg", baseURL, logo.ID) } + if logo.HasPNG { + logo.LogoURL = fmt.Sprintf("%s/logos/%s?format=png", baseURL, logo.ID) + } else if logo.HasSVG { + logo.LogoURL = fmt.Sprintf("%s/logos/%s?format=svg", baseURL, logo.ID) + } nameN := removeDiacritics(strings.ToLower(logo.ClubName)) cityN := removeDiacritics(strings.ToLower(logo.ClubCity)) if strings.Contains(nameN, normQ) || strings.Contains(cityN, normQ) || strings.Contains(strings.ToLower(logo.ID), strings.ToLower(q)) { @@ -706,12 +695,22 @@ func uploadLogo(c *gin.Context) { if clubName == "" { if club, err := fetchClubByID(id); err == nil && club != nil { - if club.Name != "" { clubName = club.Name } - if clubType == "" && club.Type != "" { clubType = club.Type } - if clubCity == "" && club.City != "" { clubCity = club.City } - if clubWebsite == "" && club.Website != "" { clubWebsite = club.Website } + if club.Name != "" { + clubName = club.Name + } + if clubType == "" && club.Type != "" { + clubType = club.Type + } + if clubCity == "" && club.City != "" { + clubCity = club.City + } + if clubWebsite == "" && club.Website != "" { + clubWebsite = club.Website + } + } + if clubName == "" { + clubName = "Club " + id } - if clubName == "" { clubName = "Club " + id } } // Get uploaded file diff --git a/backend/main.go b/backend/main.go index ea9a68c..2348aa5 100644 --- a/backend/main.go +++ b/backend/main.go @@ -89,7 +89,6 @@ func setupRoutes(r *gin.Engine) { clubs := r.Group("/clubs") { clubs.GET("/search", searchClubs) - clubs.GET("/search-with-logos", searchClubsWithLogos) clubs.GET("/:id", getClub) } diff --git a/frontend/src/theme.js b/frontend/src/theme.js index 1a7f395..1495bd3 100644 --- a/frontend/src/theme.js +++ b/frontend/src/theme.js @@ -56,75 +56,3 @@ if (document.readyState === 'loading') { initThemeToggle() } -// Global light/dark theme handling for Czech Clubs Logos frontend - -const THEME_KEY = 'clublogos-theme' - -function getPreferredTheme() { - try { - const stored = localStorage.getItem(THEME_KEY) - if (stored === 'light' || stored === 'dark') return stored - } catch (_) {} - - if (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) { - return 'light' - } - return 'dark' -} - -function applyTheme(theme) { - const root = document.documentElement - const mode = theme === 'light' ? 'light' : 'dark' - - root.classList.remove('theme-light', 'theme-dark', 'dark') - if (mode === 'light') { - root.classList.add('theme-light') - } else { - root.classList.add('theme-dark', 'dark') - } - - try { - localStorage.setItem(THEME_KEY, mode) - } catch (_) {} - - const toggle = document.getElementById('themeToggle') - if (toggle) { - if (mode === 'light') { - toggle.innerHTML = ` - - - - - - - ` - } else { - toggle.innerHTML = ` - - - - - - - ` - } - } -} - -function setupThemeToggle() { - const toggle = document.getElementById('themeToggle') - if (!toggle) return - - toggle.addEventListener('click', () => { - const isLight = document.documentElement.classList.contains('theme-light') - applyTheme(isLight ? 'dark' : 'light') - }) -} - -if (typeof window !== 'undefined') { - document.addEventListener('DOMContentLoaded', () => { - const initial = getPreferredTheme() - applyTheme(initial) - setupThemeToggle() - }) -} diff --git a/go.mod b/go.mod index da4570e..51be996 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,3 @@ module club go 1.25.1 - -require ( - github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef // indirect - golang.org/x/image v0.0.0-20211028202545-6944b10bf410 // indirect -) diff --git a/go.sum b/go.sum index 93f2971..e69de29 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +0,0 @@ -github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef h1:Ch6Q+AZUxDBCVqdkI8FSpFyZDtCVBc2VmejdNrm5rRQ= -github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef/go.mod h1:nXTWP6+gD5+LUJ8krVhhoeHjvHTutPxMYl5SvkcnJNE= -golang.org/x/image v0.0.0-20211028202545-6944b10bf410 h1:hTftEOvwiOq2+O8k2D5/Q7COC7k5Qcrgc2TFURJYnvQ= -golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=