mirror of
https://github.com/captbaritone/webamp.git
synced 2026-01-23 02:15:01 +00:00
Make page dynamic and fix scroll loading on ios
This commit is contained in:
parent
0b2ff44b1c
commit
f3054192e6
3 changed files with 32 additions and 8 deletions
|
|
@ -7,6 +7,12 @@ import UserContext from "../../../data/UserContext";
|
|||
export async function logUserEvent(sessionId: string, event: UserEvent) {
|
||||
const timestamp = Date.now();
|
||||
|
||||
console.log("Logging user event:", {
|
||||
sessionId,
|
||||
timestamp,
|
||||
event,
|
||||
});
|
||||
|
||||
await knex("user_log_events").insert({
|
||||
session_id: sessionId,
|
||||
timestamp: timestamp,
|
||||
|
|
|
|||
|
|
@ -36,18 +36,33 @@ export default function SkinScroller({
|
|||
return;
|
||||
}
|
||||
|
||||
function onSnap(e) {
|
||||
const md5 = e.snapTargetBlock.getAttribute("skin-md5");
|
||||
const index = parseInt(e.snapTargetBlock.getAttribute("skin-index"));
|
||||
setVisibleSkinIndex(index);
|
||||
}
|
||||
// Use IntersectionObserver for cross-browser compatibility (iOS doesn't support scrollsnapchange)
|
||||
const observer = new IntersectionObserver(
|
||||
(entries) => {
|
||||
entries.forEach((entry) => {
|
||||
// When an element becomes mostly visible (> 50% intersecting)
|
||||
if (entry.isIntersecting && entry.intersectionRatio > 0.5) {
|
||||
const index = parseInt(
|
||||
entry.target.getAttribute("skin-index") || "0"
|
||||
);
|
||||
setVisibleSkinIndex(index);
|
||||
}
|
||||
});
|
||||
},
|
||||
{
|
||||
root: containerRef,
|
||||
threshold: 0.5, // Trigger when 50% of the element is visible
|
||||
}
|
||||
);
|
||||
|
||||
containerRef.addEventListener("scrollsnapchange", onSnap);
|
||||
// Observe all skin page elements
|
||||
const skinElements = containerRef.querySelectorAll("[skin-index]");
|
||||
skinElements.forEach((element) => observer.observe(element));
|
||||
|
||||
return () => {
|
||||
containerRef.removeEventListener("scrollsnapchange", onSnap);
|
||||
observer.disconnect();
|
||||
};
|
||||
}, [containerRef]);
|
||||
}, [containerRef, skins.length]);
|
||||
|
||||
useEffect(() => {
|
||||
logUserEvent(sessionId, {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@ import SkinScroller, { ClientSkin } from "./SkinScroller";
|
|||
import { getScrollPage } from "../../../data/skins";
|
||||
import SkinModel from "../../../data/SkinModel";
|
||||
|
||||
// Ensure each page load gets a new session
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
async function getClientSkins(sessionId: string): Promise<ClientSkin[]> {
|
||||
"use server";
|
||||
const ctx = new UserContext();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue