// The complete ui.js file with the correct worker URL. // Define the backend URL as a constant for easy access. const BACKEND_URL = 'https://stream-ai-backend.smplushypermedia.workers.dev'; async function loadRecommendations() { const container = document.getElementById('recommendations-container'); if (!container) return; try { // Fetch recommendations from your live backend. const response = await fetch(`${BACKEND_URL}/api/recommendations`); if (!response.ok) { throw new Error(`Network response was not ok. Status: ${response.status}`); } const listings = await response.json(); container.innerHTML = ''; // Clear previous listings if (listings.length === 0) { container.innerHTML = `
No recommendations available yet. Be the first to add one!
`; return; } listings.forEach(item => { const card = document.createElement('div'); const pinnedClass = item.is_pinned ? 'border-2 border-indigo-400' : 'shadow-md'; card.className = `stream-card bg-white rounded-lg overflow-hidden hover:shadow-xl transition duration-300 p-4 relative ${pinnedClass}`; card.innerHTML = ` ${item.is_pinned ? '${item.description || ''}
Could not load recommendations. Please ensure the backend is running and the URL is correct.
`; } } } export function initUI() { // This will run our function on page load to populate the recommendations. loadRecommendations(); }