Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

fix: track first page no matter what

Marc Seitze3bb709efd9d
diff --git a/components/PagesViewer.tsx b/components/PagesViewer.tsx
index d4f9ff6e..7d424382 100644
--- a/components/PagesViewer.tsx
+++ b/components/PagesViewer.tsx
@@ -4,13 +4,25 @@ import { BlurImage } from "@/components/shared/blur-image";
export default function PagesViewer({pages, linkId, documentId, viewId}: {pages: { file: string, pageNumber: string }[], linkId: string, documentId: string, viewId: string}) {
const [pageNumber, setPageNumber] = useState<number>(1); // start on first page
+ const [isMounted, setIsMounted] = useState(false);
+
const startTimeRef = useRef(Date.now());
const pageNumberRef = useRef<number>(pageNumber);
const isInitialPageLoad = useRef(true);
+ // const initialPageLoadDone = useRef(false);
+
const numPages = pages.length;
+ useEffect(() => {
+ setIsMounted(true);
+
+ // Clean up function
+ return () => {
+ setIsMounted(false);
+ };
+ }, []);
// Update the previous page number after the effect hook has run
useEffect(() => {
pageNumberRef.current = pageNumber;
@@ -56,12 +68,12 @@ export default function PagesViewer({pages, linkId, documentId, viewId}: {pages:
async function trackPageView(duration: number = 0) {
// If this is the initial page load, don't send the request
- if (isInitialPageLoad.current) {
- console.log("Initial page load detected, not tracking.");
- isInitialPageLoad.current = false;
- return;
- }
-
+ // if (isInitialPageLoad.current) {
+ // console.log("Initial page load detected, not tracking.");
+ // isInitialPageLoad.current = false;
+ // return;
+ // }
+
console.log("Tracking page view.");
await fetch("/api/record_view", {