Update index.html
Browse files- index.html +62 -70
index.html
CHANGED
@@ -1,77 +1,69 @@
|
|
1 |
<script>
|
2 |
-
const state
|
3 |
-
|
4 |
-
tileType
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
tileSize: null
|
9 |
-
};
|
10 |
-
|
11 |
-
// ... (keep all previous DOM references and resetConversation as-is)
|
12 |
-
|
13 |
-
function selectTileType(type) {
|
14 |
-
state.tileType = type;
|
15 |
-
state.step = 'length';
|
16 |
-
|
17 |
-
addMessage('user', type === 'floor' ? 'Floor tiles' : 'Wall tiles');
|
18 |
showTyping();
|
19 |
-
|
20 |
-
setTimeout(() => {
|
21 |
hideTyping();
|
22 |
-
addMessage('bot',
|
23 |
-
|
|
|
|
|
|
|
|
|
24 |
}
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
addMessage('user', message);
|
31 |
-
userInput.value = '';
|
32 |
-
|
33 |
-
processUserMessage(message);
|
34 |
}
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
state.
|
60 |
-
|
61 |
-
state.
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
76 |
}
|
|
|
77 |
</script>
|
|
|
1 |
<script>
|
2 |
+
const state={step:'tileType',tileType:null,area:null,length:null,width:null};
|
3 |
+
function selectTileType(t){
|
4 |
+
state.tileType=t;state.step='area';
|
5 |
+
addMessage('user',t+' tiles'); ask('area');
|
6 |
+
}
|
7 |
+
function ask(field){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
showTyping();
|
9 |
+
setTimeout(()=>{
|
|
|
10 |
hideTyping();
|
11 |
+
addMessage('bot',
|
12 |
+
field==='area' ? "Total area (sq.ft)?" :
|
13 |
+
field==='length' ? "Tile length (ft)?" : "Tile width (ft)?"
|
14 |
+
);
|
15 |
+
state.step=field;
|
16 |
+
},1000);
|
17 |
}
|
18 |
+
function sendMessage(){
|
19 |
+
const m=userInput.value.trim(); if(!m)return;
|
20 |
+
addMessage('user',m);userInput.value='';
|
21 |
+
handleUser(m);
|
|
|
|
|
|
|
|
|
|
|
22 |
}
|
23 |
+
function handleUser(msg){
|
24 |
+
if(state.step==='area'){
|
25 |
+
const v=parseFloat(msg);
|
26 |
+
return isNaN(v)? addBot("Enter valid area.") : (state.area=v,ask('length'));
|
27 |
+
}
|
28 |
+
if(state.step==='length'){
|
29 |
+
const v=parseFloat(msg);
|
30 |
+
return isNaN(v)? addBot("Enter valid length.") : (state.length=v,ask('width'));
|
31 |
+
}
|
32 |
+
if(state.step==='width'){
|
33 |
+
const v=parseFloat(msg);
|
34 |
+
return isNaN(v)? addBot("Enter valid width.") : (
|
35 |
+
state.width=v,
|
36 |
+
showResults()
|
37 |
+
);
|
38 |
+
}
|
39 |
+
}
|
40 |
+
function showResults(){
|
41 |
+
const c = state.length * state.width;
|
42 |
+
const tiles = Math.ceil((state.area/c)*1.1);
|
43 |
+
addBot(`📦 You need ${tiles} tiles (~10% buffer).`);
|
44 |
+
fetch('/recommend', {
|
45 |
+
method:'POST', headers:{'Content-Type':'application/json'},
|
46 |
+
body:JSON.stringify({
|
47 |
+
tile_type: state.tileType,
|
48 |
+
area: state.area,
|
49 |
+
length: state.length,
|
50 |
+
width: state.width,
|
51 |
+
price_range: [3,10]
|
52 |
+
})
|
53 |
+
})
|
54 |
+
.then(r=>r.json())
|
55 |
+
.then(r=>{
|
56 |
+
if(r.recommended_products && r.recommended_products.length){
|
57 |
+
recommendations.innerHTML = '';
|
58 |
+
r.recommended_products.forEach(p=>{
|
59 |
+
recommendations.innerHTML += `
|
60 |
+
<div class="card">
|
61 |
+
<h4>${p.name}</h4>
|
62 |
+
<p>${p.size} — ₹${p.price}/box</p>
|
63 |
+
</div>`;
|
64 |
+
});
|
65 |
+
} else addBot("No recommendations.");
|
66 |
+
});
|
67 |
}
|
68 |
+
// Helper functions: addBot, addMessage, showTyping, hideTyping (as before)...
|
69 |
</script>
|