Update index.html
Browse files- index.html +57 -2
index.html
CHANGED
@@ -153,7 +153,7 @@
|
|
153 |
|
154 |
state.area = area;
|
155 |
state.step = 'tileLength';
|
156 |
-
addMessage('bot', 'Now, please enter the tile length (
|
157 |
|
158 |
} else if (state.step === 'tileLength') {
|
159 |
const length = parseFloat(message);
|
@@ -164,7 +164,7 @@
|
|
164 |
|
165 |
state.tileLength = length;
|
166 |
state.step = 'tileWidth';
|
167 |
-
addMessage('bot', 'Now, please enter the tile width (
|
168 |
|
169 |
} else if (state.step === 'tileWidth') {
|
170 |
const width = parseFloat(message);
|
@@ -194,6 +194,61 @@
|
|
194 |
</div>
|
195 |
`);
|
196 |
state.step = 'complete';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
}
|
198 |
|
199 |
function addMessage(sender, message) {
|
|
|
153 |
|
154 |
state.area = area;
|
155 |
state.step = 'tileLength';
|
156 |
+
addMessage('bot', 'Now, please enter the tile length (in feet):');
|
157 |
|
158 |
} else if (state.step === 'tileLength') {
|
159 |
const length = parseFloat(message);
|
|
|
164 |
|
165 |
state.tileLength = length;
|
166 |
state.step = 'tileWidth';
|
167 |
+
addMessage('bot', 'Now, please enter the tile width (in feet):');
|
168 |
|
169 |
} else if (state.step === 'tileWidth') {
|
170 |
const width = parseFloat(message);
|
|
|
194 |
</div>
|
195 |
`);
|
196 |
state.step = 'complete';
|
197 |
+
|
198 |
+
// Fetch recommended products
|
199 |
+
fetchRecommendedProducts();
|
200 |
+
}
|
201 |
+
|
202 |
+
function fetchRecommendedProducts() {
|
203 |
+
fetch('/recommend', {
|
204 |
+
method: 'POST',
|
205 |
+
headers: {
|
206 |
+
'Content-Type': 'application/json',
|
207 |
+
},
|
208 |
+
body: JSON.stringify({
|
209 |
+
tile_type: state.tileType,
|
210 |
+
coverage: state.tileLength * state.tileWidth,
|
211 |
+
area: state.area,
|
212 |
+
price_range: [3, 10] // Example price range
|
213 |
+
})
|
214 |
+
})
|
215 |
+
.then(response => response.json())
|
216 |
+
.then(data => {
|
217 |
+
if (data.recommended_products && data.recommended_products.length > 0) {
|
218 |
+
loadProductRecommendations(data.recommended_products);
|
219 |
+
} else {
|
220 |
+
recommendations.innerHTML = `
|
221 |
+
<div class="col-span-4 text-center py-4 text-gray-500">
|
222 |
+
No strong recommendations available for these parameters.
|
223 |
+
</div>
|
224 |
+
`;
|
225 |
+
}
|
226 |
+
})
|
227 |
+
.catch(error => {
|
228 |
+
console.error('Error fetching recommendations:', error);
|
229 |
+
});
|
230 |
+
}
|
231 |
+
|
232 |
+
function loadProductRecommendations(products) {
|
233 |
+
recommendations.innerHTML = '';
|
234 |
+
|
235 |
+
products.slice(0, 4).forEach(product => {
|
236 |
+
const productCard = document.createElement('div');
|
237 |
+
productCard.className = 'bg-white rounded-lg overflow-hidden shadow-sm border border-gray-100';
|
238 |
+
productCard.innerHTML = `
|
239 |
+
<div class="h-32 bg-gray-200 flex items-center justify-center">
|
240 |
+
<svg xmlns="http://www.w3.org/2000/svg" class="h-12 w-12 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
241 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1" d="M4 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2V6zM14 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V6zM4 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2v-2zM14 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z" />
|
242 |
+
</svg>
|
243 |
+
</div>
|
244 |
+
<div class="p-3">
|
245 |
+
<h4 class="font-medium text-gray-800">${product.name || 'Tile Product'}</h4>
|
246 |
+
<p class="text-sm text-gray-600 mt-1">${product.price || '$0.00'}/box</p>
|
247 |
+
<button class="mt-2 w-full bg-indigo-600 text-white py-1 rounded text-sm hover:bg-indigo-700 transition">View Details</button>
|
248 |
+
</div>
|
249 |
+
`;
|
250 |
+
recommendations.appendChild(productCard);
|
251 |
+
});
|
252 |
}
|
253 |
|
254 |
function addMessage(sender, message) {
|