mirror of
https://github.com/Dvorinka/ClubLogos.git
synced 2026-06-04 03:52:57 +00:00
fff
This commit is contained in:
+30
-8
@@ -34,17 +34,27 @@ async function searchClubs(query) {
|
||||
const response = await fetch(`${API_BASE_URL}/clubs/search?q=${encodeURIComponent(query)}`)
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Vyhledávání selhalo')
|
||||
throw new Error('API nedostupné')
|
||||
}
|
||||
|
||||
// Check if response is JSON
|
||||
const contentType = response.headers.get('content-type')
|
||||
if (!contentType || !contentType.includes('application/json')) {
|
||||
throw new Error('API vrátilo neplatnou odpověď')
|
||||
}
|
||||
|
||||
const clubs = await response.json()
|
||||
await displaySearchResults(clubs)
|
||||
|
||||
} catch (error) {
|
||||
console.error('Search error:', error)
|
||||
// Suppress console spam from HTML responses
|
||||
if (!error.message.includes('<!DOCTYPE')) {
|
||||
console.warn('Search failed:', error.message)
|
||||
}
|
||||
searchResults.innerHTML = `
|
||||
<div class="text-center py-4 text-red-400">
|
||||
<p>Vyhledávání selhalo. Zkuste to prosím znovu.</p>
|
||||
<div class="text-center py-4 text-yellow-400">
|
||||
<p class="mb-2">⚠️ Hledání dočasně nedostupné</p>
|
||||
<p class="text-xs text-gray-400">Zkontrolujte, zda běží backend server</p>
|
||||
</div>
|
||||
`
|
||||
}
|
||||
@@ -65,17 +75,29 @@ async function displaySearchResults(clubs) {
|
||||
try {
|
||||
const logosResponse = await fetch(`${API_BASE_URL}/logos`)
|
||||
if (logosResponse.ok) {
|
||||
const data = await logosResponse.json()
|
||||
existingLogos = data || []
|
||||
const contentType = logosResponse.headers.get('content-type')
|
||||
if (contentType && contentType.includes('application/json')) {
|
||||
const data = await logosResponse.json()
|
||||
existingLogos = data || []
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('Could not fetch existing logos:', error)
|
||||
// Silently fail - this is optional data
|
||||
}
|
||||
|
||||
searchResults.innerHTML = clubs.map(club => {
|
||||
// Check if we have this logo in our API
|
||||
const existingLogo = existingLogos.find(l => l.id === club.id)
|
||||
const logoUrl = existingLogo ? existingLogo.logo_url : (club.logo_url || '')
|
||||
|
||||
// Priority: 1. Our API logos, 2. FACR API logos
|
||||
let logoUrl = ''
|
||||
if (existingLogo) {
|
||||
// Use our API endpoint (proxied through /api)
|
||||
logoUrl = `${API_BASE_URL}/logos/${club.id}`
|
||||
} else if (club.logo_url) {
|
||||
// Use FACR logo as fallback
|
||||
logoUrl = club.logo_url
|
||||
}
|
||||
|
||||
// Create logo HTML with fallback icon
|
||||
let logoHtml = ''
|
||||
|
||||
@@ -72,11 +72,15 @@ async function loadLogos() {
|
||||
|
||||
// Display logos in grid
|
||||
function displayLogos(logos) {
|
||||
logoGrid.innerHTML = logos.map(logo => `
|
||||
logoGrid.innerHTML = logos.map(logo => {
|
||||
// Construct logo URL properly through API proxy
|
||||
const logoUrl = `${API_BASE_URL}/logos/${logo.id}`
|
||||
|
||||
return `
|
||||
<div class="logo-card bg-dark-card rounded-xl p-4 border border-dark-border hover:border-accent-blue transition-smooth cursor-pointer group" data-logo-id="${logo.id}">
|
||||
<div class="aspect-square bg-dark-bg rounded-lg flex items-center justify-center mb-3 overflow-hidden">
|
||||
<img
|
||||
src="${logo.logo_url}"
|
||||
src="${logoUrl}"
|
||||
alt="${logo.club_name}"
|
||||
class="max-w-full max-h-full object-contain p-2 group-hover:scale-110 transition-transform duration-300"
|
||||
loading="lazy"
|
||||
@@ -90,7 +94,8 @@ function displayLogos(logos) {
|
||||
${logo.has_png ? '<span class="px-2 py-0.5 bg-green-500/20 text-green-400 rounded text-xs">PNG</span>' : ''}
|
||||
</div>
|
||||
</div>
|
||||
`).join('')
|
||||
`
|
||||
}).join('')
|
||||
|
||||
// Animate logo cards
|
||||
gsap.from('.logo-card', {
|
||||
|
||||
@@ -46,8 +46,8 @@ function displayLogoDetails(logo) {
|
||||
document.getElementById('clubName').textContent = logo.club_name
|
||||
document.getElementById('clubMeta').textContent = `${logo.club_type || 'fotbal'}`
|
||||
|
||||
// Logo Previews
|
||||
const previewUrl = logo.logo_url || logo.logo_url_png || logo.logo_url_svg
|
||||
// Logo Previews - construct URL through API proxy
|
||||
const previewUrl = `${API_BASE_URL}/logos/${logoId}`
|
||||
document.getElementById('logoPreviewLight').src = previewUrl
|
||||
document.getElementById('logoPreviewDark').src = previewUrl
|
||||
|
||||
@@ -55,20 +55,20 @@ function displayLogoDetails(logo) {
|
||||
const formatsGrid = document.getElementById('formatsGrid')
|
||||
const formats = []
|
||||
|
||||
if (logo.has_png && logo.logo_url_png) {
|
||||
if (logo.has_png) {
|
||||
formats.push({
|
||||
name: 'PNG',
|
||||
url: logo.logo_url_png,
|
||||
url: `${API_BASE_URL}/logos/${logoId}?format=png`,
|
||||
size: formatFileSize(logo.file_size_png),
|
||||
icon: '🖼️',
|
||||
color: 'bg-blue-600'
|
||||
})
|
||||
}
|
||||
|
||||
if (logo.has_svg && logo.logo_url_svg) {
|
||||
if (logo.has_svg) {
|
||||
formats.push({
|
||||
name: 'SVG',
|
||||
url: logo.logo_url_svg,
|
||||
url: `${API_BASE_URL}/logos/${logoId}?format=svg`,
|
||||
size: formatFileSize(logo.file_size_svg),
|
||||
icon: '📐',
|
||||
color: 'bg-green-600'
|
||||
|
||||
Reference in New Issue
Block a user