Coots commited on
Commit
0b2ad96
·
verified ·
1 Parent(s): 0abe8e4

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +62 -70
index.html CHANGED
@@ -1,77 +1,69 @@
1
  <script>
2
- const state = {
3
- step: 'tileType',
4
- tileType: null,
5
- length: null,
6
- width: null,
7
- area: null,
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', `Great! What's the **length** of the area (in feet)?`);
23
- }, 1000);
 
 
 
 
24
  }
25
-
26
- function sendMessage() {
27
- const message = userInput.value.trim();
28
- if (!message) return;
29
-
30
- addMessage('user', message);
31
- userInput.value = '';
32
-
33
- processUserMessage(message);
34
  }
35
-
36
- function processUserMessage(message) {
37
- showTyping();
38
-
39
- setTimeout(() => {
40
- hideTyping();
41
-
42
- if (state.step === 'length') {
43
- const length = parseFloat(message);
44
- if (isNaN(length)) {
45
- addMessage('bot', 'Please enter a valid number for the length (e.g. 12).');
46
- return;
47
- }
48
- state.length = length;
49
- state.step = 'width';
50
- addMessage('bot', 'Great! Now enter the **width** of the area (in feet):');
51
- }
52
-
53
- else if (state.step === 'width') {
54
- const width = parseFloat(message);
55
- if (isNaN(width)) {
56
- addMessage('bot', 'Please enter a valid number for the width (e.g. 10).');
57
- return;
58
- }
59
- state.width = width;
60
- state.area = state.length * state.width;
61
- state.step = 'tileSize';
62
- addMessage('bot', `✅ Got it! Your total area is **${state.area.toFixed(2)} sq.ft**. Now, enter the tile size (e.g. "2x2", "600x600 mm", or "200*200"):`);
63
- }
64
-
65
- else if (state.step === 'tileSize') {
66
- const tileArea = parseTileSize(message);
67
- if (!tileArea) {
68
- addMessage('bot', 'I couldn\'t understand that tile size. Try: "2x2", "600x600 mm", or "200*200".');
69
- return;
70
- }
71
-
72
- state.tileSize = tileArea;
73
- calculateTiles();
74
- }
75
- }, 1000);
 
 
 
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>