Skip to content

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

feat: add ismobile media query

Marc Seitz478023777271
diff --git a/components/view/PagesViewerNew.tsx b/components/view/PagesViewerNew.tsx
index 7117fc45..10819b02 100644
--- a/components/view/PagesViewerNew.tsx
+++ b/components/view/PagesViewerNew.tsx
@@ -19,6 +19,7 @@ import {
import { toast } from "sonner";
import { cn } from "@/lib/utils";
+import { useMediaQuery } from "@/lib/utils/use-media-query";
import LoadingSpinner from "../ui/loading-spinner";
import { ScreenProtector } from "./ScreenProtection";
@@ -151,6 +152,8 @@ export default function PagesViewer({
const hasTrackedUpRef = useRef<boolean>(false);
const pinchRefs = useRef<(ReactZoomPanPinchContentRef | null)[]>([]);
+ const { isMobile } = useMediaQuery();
+
// Update the previous page number after the effect hook has run
useEffect(() => {
pageNumberRef.current = pageNumber;
@@ -599,10 +602,11 @@ export default function PagesViewer({
isDataroom={dataroomId ? true : false}
setDocumentData={setDocumentData}
documentRefs={pinchRefs}
+ disableZoom={isVertical && isMobile}
/>
<div
style={{ height: "calc(100vh - 64px)" }}
- className={cn("relative flex items-center", isVertical && "h-screen")}
+ className={cn("relative flex items-center", isVertical && "h-dvh")}
>
<div
className={`relative flex h-full w-full ${
@@ -623,8 +627,8 @@ export default function PagesViewer({
initialScale={scale}
initialPositionX={0}
initialPositionY={0}
+ disabled={isVertical && isMobile}
panning={{
- // disabled: isVertical,
lockAxisY: isVertical,
velocityDisabled: true,
wheelPanning: false,
@@ -656,7 +660,7 @@ export default function PagesViewer({
>
<div
key={index}
- style={{ height: "calc(100vh - 64px)" }}
+ style={{ height: "calc(100dvh - 64px)" }}
className={cn(
"relative w-full",
pageNumber - 1 === index
@@ -685,7 +689,7 @@ export default function PagesViewer({
feedback &&
(isVertical || pageNumber === numPagesWithFeedback) ? (
<div
- className={cn("relative block h-screen w-full")}
+ className={cn("relative block h-dvh w-full")}
style={{ height: "calc(100vh - 64px)" }}
>
<Question
@@ -700,7 +704,7 @@ export default function PagesViewer({
{showStatsSlideWithAccountCreation &&
(isVertical || pageNumber === numPagesWithAccountCreation) ? (
<div
- className={cn("relative block h-screen w-full")}
+ className={cn("relative block h-dvh w-full")}
style={{ height: "calc(100vh - 64px)" }}
>
<ViewDurationSummary
diff --git a/components/view/nav.tsx b/components/view/nav.tsx
index 29c57387..e36fd056 100644
--- a/components/view/nav.tsx
+++ b/components/view/nav.tsx
@@ -54,6 +54,7 @@ export default function Nav({
isDataroom,
setDocumentData,
documentRefs,
+ disableZoom,
}: {
pageNumber?: number;
numPages?: number;
@@ -68,6 +69,7 @@ export default function Nav({
isDataroom?: boolean;
setDocumentData?: React.Dispatch<React.SetStateAction<TDocumentData | null>>;
documentRefs?: MutableRefObject<(ReactZoomPanPinchContentRef | null)[]>;
+ disableZoom?: boolean;
}) {
const downloadFile = async () => {
if (!allowDownload || type === "notion") return;
@@ -215,7 +217,7 @@ export default function Nav({
<Download className="h-5 w-5" />
</Button>
) : null}
- {documentRefs ? (
+ {!disableZoom && documentRefs ? (
<div className="flex gap-1">
<Button
onClick={() =>
diff --git a/lib/utils/use-media-query.ts b/lib/utils/use-media-query.ts
new file mode 100644
index 00000000..1740639d
--- /dev/null
+++ b/lib/utils/use-media-query.ts
@@ -0,0 +1,46 @@
+import { useEffect, useState } from "react";
+
+export function useMediaQuery() {
+ const [device, setDevice] = useState<"mobile" | "tablet" | "desktop" | null>(
+ null,
+ );
+ const [dimensions, setDimensions] = useState<{
+ width: number;
+ height: number;
+ } | null>(null);
+
+ useEffect(() => {
+ const checkDevice = () => {
+ if (window.matchMedia("(max-width: 640px)").matches) {
+ setDevice("mobile");
+ } else if (
+ window.matchMedia("(min-width: 641px) and (max-width: 1024px)").matches
+ ) {
+ setDevice("tablet");
+ } else {
+ setDevice("desktop");
+ }
+ setDimensions({ width: window.innerWidth, height: window.innerHeight });
+ };
+
+ // Initial detection
+ checkDevice();
+
+ // Listener for windows resize
+ window.addEventListener("resize", checkDevice);
+
+ // Cleanup listener
+ return () => {
+ window.removeEventListener("resize", checkDevice);
+ };
+ }, []);
+
+ return {
+ device,
+ width: dimensions?.width,
+ height: dimensions?.height,
+ isMobile: device === "mobile",
+ isTablet: device === "tablet",
+ isDesktop: device === "desktop",
+ };
+}