privateuserh commited on
Commit
f909bae
·
verified ·
1 Parent(s): 0be9c61

Update scripts/ui.js

Browse files
Files changed (1) hide show
  1. scripts/ui.js +3 -36
scripts/ui.js CHANGED
@@ -1,38 +1,8 @@
1
- // scripts/ui.js -- Final version with dropdown form and instant UI update
2
 
3
- // --- THIS IS THE CRUCIAL UPDATE ---
4
  const BACKEND_URL = 'https://streamai-backend-v2.smplushypermedia.workers.dev';
5
 
6
- async function loadRecommendations() {
7
- const container = document.getElementById('recommendations-container');
8
- if (!container) return;
9
-
10
- try {
11
- // This now calls the NEW worker's recommendations endpoint
12
- const response = await fetch(`${BACKEND_URL}/api/recommendations`);
13
-
14
- if (!response.ok) {
15
- throw new Error(`Network response was not ok. Status: ${response.status}`);
16
- }
17
-
18
- const listings = await response.json();
19
- // ... (The rest of the rendering logic remains the same) ...
20
- container.innerHTML = '';
21
- listings.forEach(item => {
22
- const card = document.createElement('div');
23
- // ...card creation logic...
24
- container.appendChild(card);
25
- });
26
-
27
- } catch (error) {
28
- console.error("Failed to load recommendations:", error);
29
- if (container) {
30
- container.innerHTML = `<p class="text-center col-span-full text-red-500">Could not load recommendations.</p>`;
31
- }
32
- }
33
- }
34
-
35
- // ... (The rest of your ui.js file, including initUI, handleFormSubmit, etc., remains the same) ...
36
  // --- Helper Functions ---
37
  const getElement = (id) => document.getElementById(id);
38
 
@@ -98,12 +68,9 @@ async function handleFormSubmit(event) {
98
 
99
  showNotification('Success! Your recommendation has been added.');
100
 
101
- // --- BUG FIX: INSTANT UI UPDATE ---
102
- // 1. Create a new card with the data we just submitted.
103
  const newCard = createListingCard(listingData);
104
- // 2. Add it to the top of the list for an instant refresh.
105
  getElement('recommendations-container').prepend(newCard);
106
- // 3. Close the form.
107
  getElement('form-container').classList.add('hidden');
108
  getElement('form-chevron').classList.remove('rotate-180');
109
 
 
1
+ // scripts/ui.js -- Corrected and Final Version
2
 
3
+ // --- Configuration ---
4
  const BACKEND_URL = 'https://streamai-backend-v2.smplushypermedia.workers.dev';
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  // --- Helper Functions ---
7
  const getElement = (id) => document.getElementById(id);
8
 
 
68
 
69
  showNotification('Success! Your recommendation has been added.');
70
 
 
 
71
  const newCard = createListingCard(listingData);
 
72
  getElement('recommendations-container').prepend(newCard);
73
+
74
  getElement('form-container').classList.add('hidden');
75
  getElement('form-chevron').classList.remove('rotate-180');
76