-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvipPickup.js
More file actions
220 lines (196 loc) · 6.65 KB
/
vipPickup.js
File metadata and controls
220 lines (196 loc) · 6.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import { itemCoverImage } from "./general";
import QRCode from "qrcode";
function startAutoScroll(itemListElement) {
if (!itemListElement) return;
let autoScrollActive = true;
let animationFrameId = null;
let isProgrammaticScroll = false;
let lastScrollLeft = itemListElement.scrollLeft;
const scrollSpeed = 0.5; // pixels per frame (adjust for speed)
// Check if there's content to scroll
const maxScroll = itemListElement.scrollWidth - itemListElement.clientWidth;
if (maxScroll <= 0) return; // No scrolling needed
const autoScroll = () => {
if (!autoScrollActive) return;
const currentScroll = itemListElement.scrollLeft;
const maxScroll = itemListElement.scrollWidth - itemListElement.clientWidth;
// Stop if we've reached the end
if (currentScroll >= maxScroll - 1) {
return;
}
// Scroll to the right programmatically
isProgrammaticScroll = true;
itemListElement.scrollLeft += scrollSpeed;
lastScrollLeft = itemListElement.scrollLeft;
isProgrammaticScroll = false;
animationFrameId = requestAnimationFrame(autoScroll);
};
// Pause auto-scroll on user interaction
const pauseAutoScroll = () => {
autoScrollActive = false;
if (animationFrameId) {
cancelAnimationFrame(animationFrameId);
animationFrameId = null;
}
};
// Detect user scroll (when scroll position changes without our programmatic scroll)
const handleScroll = () => {
if (isProgrammaticScroll) {
lastScrollLeft = itemListElement.scrollLeft;
return;
}
const currentScrollLeft = itemListElement.scrollLeft;
// If scroll changed and it wasn't our programmatic scroll, user is interacting
if (Math.abs(currentScrollLeft - lastScrollLeft) > scrollSpeed * 1.5) {
pauseAutoScroll();
itemListElement.removeEventListener('scroll', handleScroll);
} else {
lastScrollLeft = currentScrollLeft;
}
};
// Listen for direct user interactions (these immediately pause)
itemListElement.addEventListener('touchstart', pauseAutoScroll, { once: true });
itemListElement.addEventListener('mousedown', pauseAutoScroll, { once: true });
itemListElement.addEventListener('wheel', pauseAutoScroll, { once: true });
itemListElement.addEventListener('scroll', handleScroll);
// Start auto-scroll after a short delay to ensure content is rendered
setTimeout(() => {
if (autoScrollActive) {
lastScrollLeft = itemListElement.scrollLeft;
animationFrameId = requestAnimationFrame(autoScroll);
}
}, 500);
}
function loadRecentlySold() {
const recentlySoldItems = callBackendApi("/api/items/recentlySold");
recentlySoldItems
.then((result) => {
// Read result of the Cloud Function.
const itemListRecentlySold1 = document.getElementById(
"itemListRecentlySold1"
);
itemListRecentlySold1.innerHTML = "";
result.data.forEach((item, index) => {
const brand = item.brand;
const soldPrice = item.soldPrice;
const soldDate = new Date(item.soldDate);
const publishedDate = new Date(item.publishedDate);
const imageUrl = itemCoverImage(item);
const daysToSold = Math.floor(
(soldDate.getTime() - publishedDate.getTime()) / (1000 * 3600 * 24)
);
if (soldPrice >= 180 || daysToSold <= 20) {
const itemCardHTML = `<div class="item-card-recently-sold"><div class="ratio-box _16-9"><div class="content-block with-image">
<div class="img-container" style="background-image: url('${imageUrl}');"></div></div></div>
<div>
<div>${brand}</div>
<div>Såld för ${soldPrice} kr</div>
</div>
</div>`;
itemListRecentlySold1.innerHTML += itemCardHTML;
}
});
// Start auto-scroll after items are loaded
startAutoScroll(itemListRecentlySold1);
})
.catch((error) => {
errorHandler.report(error);
// Getting the Error details.
var code = error.code;
var message = error.message;
console.log("Error message: ", message, code);
});
// [END fb_functions_call_add_message_error]
}
function showDownloadAppLink() {
const elm = document.getElementById("downloadAppLink");
elm.style.display = "flex";
}
// Load recently sold items
loadRecentlySold();
// Show download app link for iOS devices
if (isIos) {
showDownloadAppLink();
}
// Show intercom messenger
window.intercomSettings = {
app_id: "klyy0le5",
};
(function () {
var w = window;
var ic = w.Intercom;
if (typeof ic === "function") {
ic("reattach_activator");
ic("update", w.intercomSettings);
} else {
var d = document;
var i = function () {
i.c(arguments);
};
i.q = [];
i.c = function (args) {
i.q.push(args);
};
w.Intercom = i;
var l = function () {
var s = d.createElement("script");
s.type = "text/javascript";
s.async = true;
s.src = "https://widget.intercom.io/widget/klyy0le5";
var x = d.getElementsByTagName("script")[0];
x.parentNode.insertBefore(s, x);
};
if (w.attachEvent) {
w.attachEvent("onload", l);
} else {
w.addEventListener("load", l, false);
}
}
})();
// Track VIP pickup button clicks with Intercom
function setupVipPickupHandler() {
const buttonIds = [
"bookVipPickupCtaButton",
"stickyBookVipPickupButton",
"centerBookVipPickupButton"
];
buttonIds.forEach((buttonId) => {
const button = document.getElementById(buttonId);
if (button) {
button.addEventListener("click", () => {
if (typeof Intercom === "function") {
Intercom('startSurvey', 57206742)
}
});
}
});
}
// Setup tracking after Intercom is loaded
if (typeof Intercom === "function") {
setupVipPickupHandler();
} else {
// Wait for Intercom to load
const checkIntercom = setInterval(() => {
if (typeof Intercom === "function") {
clearInterval(checkIntercom);
setupVipPickupHandler();
}
}, 100);
// Timeout after 5 seconds if Intercom doesn't load
setTimeout(() => clearInterval(checkIntercom), 5000);
}
// Generate QR code for desktop users
var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
if (!isMobile) {
const qrCanvas = document.getElementById('qrCanvas');
if (qrCanvas) {
QRCode.toCanvas(qrCanvas, window.location.href, function (error) {
if (error) {
console.error('QR code generation error:', error);
errorHandler.report(error);
} else {
console.log('QR code generated successfully');
}
});
}
}