Skip to content

Commit f305419

Browse files
committed
Make page dynamic and fix scroll loading on ios
1 parent 0b2ff44 commit f305419

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

packages/skin-database/app/(modern)/scroll/Events.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import UserContext from "../../../data/UserContext";
77
export async function logUserEvent(sessionId: string, event: UserEvent) {
88
const timestamp = Date.now();
99

10+
console.log("Logging user event:", {
11+
sessionId,
12+
timestamp,
13+
event,
14+
});
15+
1016
await knex("user_log_events").insert({
1117
session_id: sessionId,
1218
timestamp: timestamp,

packages/skin-database/app/(modern)/scroll/SkinScroller.tsx

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,33 @@ export default function SkinScroller({
3636
return;
3737
}
3838

39-
function onSnap(e) {
40-
const md5 = e.snapTargetBlock.getAttribute("skin-md5");
41-
const index = parseInt(e.snapTargetBlock.getAttribute("skin-index"));
42-
setVisibleSkinIndex(index);
43-
}
39+
// Use IntersectionObserver for cross-browser compatibility (iOS doesn't support scrollsnapchange)
40+
const observer = new IntersectionObserver(
41+
(entries) => {
42+
entries.forEach((entry) => {
43+
// When an element becomes mostly visible (> 50% intersecting)
44+
if (entry.isIntersecting && entry.intersectionRatio > 0.5) {
45+
const index = parseInt(
46+
entry.target.getAttribute("skin-index") || "0"
47+
);
48+
setVisibleSkinIndex(index);
49+
}
50+
});
51+
},
52+
{
53+
root: containerRef,
54+
threshold: 0.5, // Trigger when 50% of the element is visible
55+
}
56+
);
4457

45-
containerRef.addEventListener("scrollsnapchange", onSnap);
58+
// Observe all skin page elements
59+
const skinElements = containerRef.querySelectorAll("[skin-index]");
60+
skinElements.forEach((element) => observer.observe(element));
4661

4762
return () => {
48-
containerRef.removeEventListener("scrollsnapchange", onSnap);
63+
observer.disconnect();
4964
};
50-
}, [containerRef]);
65+
}, [containerRef, skins.length]);
5166

5267
useEffect(() => {
5368
logUserEvent(sessionId, {

packages/skin-database/app/(modern)/scroll/page.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import SkinScroller, { ClientSkin } from "./SkinScroller";
55
import { getScrollPage } from "../../../data/skins";
66
import SkinModel from "../../../data/SkinModel";
77

8+
// Ensure each page load gets a new session
9+
export const dynamic = "force-dynamic";
10+
811
async function getClientSkins(sessionId: string): Promise<ClientSkin[]> {
912
"use server";
1013
const ctx = new UserContext();

0 commit comments

Comments
 (0)