Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
fix: remove annotations from view
Marc Seitzf876766835f2
diff --git a/components/view/viewer/pages-horizontal-viewer.tsx b/components/view/viewer/pages-horizontal-viewer.tsxindex c00ce0fe..2eccc462 100644--- a/components/view/viewer/pages-horizontal-viewer.tsx+++ b/components/view/viewer/pages-horizontal-viewer.tsx@@ -5,22 +5,18 @@ import React from "react";import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";import { useSession } from "next-auth/react";-import useSWR from "swr";-import { useViewerAnnotations } from "@/lib/swr/use-annotations";import { useSafePageViewTracker } from "@/lib/tracking/safe-page-view-tracker";import { getTrackingOptions } from "@/lib/tracking/tracking-config";import { WatermarkConfig } from "@/lib/types";-import { cn, fetcher } from "@/lib/utils";+import { cn } from "@/lib/utils";import {- ResizableHandle,ResizablePanel,ResizablePanelGroup,} from "@/components/ui/resizable";import { ScreenProtector } from "../ScreenProtection";-import { AnnotationPanel } from "../annotations/annotation-panel";import Nav, { TNavData } from "../nav";import { PoweredBy } from "../powered-by";import Question from "../question";@@ -102,11 +98,6 @@ export default function PagesHorizontalViewer({const [submittedFeedback, setSubmittedFeedback] = useState<boolean>(false);const [accountCreated, setAccountCreated] = useState<boolean>(false);- const [annotationsEnabled, setAnnotationsEnabled] = useState(false);-- // Fetch annotations for this link- const { annotations } = useViewerAnnotations(linkId, documentId, viewId);- const hasAnnotations = annotations && annotations.length > 0;const [scale, setScale] = useState<number>(1);const initialViewedPages = Array.from({ length: numPages }, (_, index) => ({@@ -601,17 +592,6 @@ export default function PagesHorizontalViewer({return () => window.removeEventListener("keydown", handleKeyDown);}, [containerRef.current, pageNumber, imageDimensions]);- const handleToggleAnnotations = (enabled: boolean) => {- setAnnotationsEnabled(enabled);- };-- const navDataWithAnnotations = {- ...navData,- annotationsEnabled,- hasAnnotations,- onToggleAnnotations: handleToggleAnnotations,- };-// Compute scaled sizer dimensions for accurate scroll areaconst currentDims = imageDimensions[pageNumber - 1];const scaledWidthPx = currentDims ? currentDims.width * scale : undefined;@@ -627,7 +607,7 @@ export default function PagesHorizontalViewer({handleZoomIn={handleZoomIn}handleZoomOut={handleZoomOut}handleFullscreen={handleFullscreen}- navData={navDataWithAnnotations}+ navData={navData}/><divstyle={{ height: "calc(100dvh - 64px)" }}@@ -635,9 +615,7 @@ export default function PagesHorizontalViewer({><ResizablePanelGroup direction="horizontal">{/* Document Content */}- <ResizablePanel- defaultSize={annotationsEnabled && hasAnnotations ? 75 : 100}- >+ <ResizablePanel defaultSize={100}><div className="flex h-full w-full items-center"><divclassName={cn(@@ -924,24 +902,6 @@ export default function PagesHorizontalViewer({</div></ResizablePanel>- {/* Annotation Panel - Right Side */}- {navData.annotationsFeatureEnabled &&- annotationsEnabled &&- hasAnnotations && (- <>- <ResizableHandle className="w-1 bg-transparent transition-colors hover:bg-white/20" />- <ResizablePanel defaultSize={25} minSize={20} maxSize={40}>- <AnnotationPanel- brand={brand}- linkId={linkId}- documentId={documentId}- viewId={viewId}- currentPage={pageNumber}- isVisible={true}- />- </ResizablePanel>- </>- )}</ResizablePanelGroup></div></>diff --git a/components/view/viewer/pages-vertical-viewer.tsx b/components/view/viewer/pages-vertical-viewer.tsxindex 52b235e6..d6d7fc09 100644--- a/components/view/viewer/pages-vertical-viewer.tsx+++ b/components/view/viewer/pages-vertical-viewer.tsx@@ -5,7 +5,6 @@ import React from "react";import { ChevronDownIcon, ChevronUpIcon } from "lucide-react";-import { useViewerAnnotations } from "@/lib/swr/use-annotations";import { useSafePageViewTracker } from "@/lib/tracking/safe-page-view-tracker";import { getTrackingOptions } from "@/lib/tracking/tracking-config";import { WatermarkConfig } from "@/lib/types";@@ -13,13 +12,11 @@ import { cn } from "@/lib/utils";import { useMediaQuery } from "@/lib/utils/use-media-query";import {- ResizableHandle,ResizablePanel,ResizablePanelGroup,} from "@/components/ui/resizable";import { ScreenProtector } from "../ScreenProtection";-import { AnnotationPanel } from "../annotations/annotation-panel";import Nav, { TNavData } from "../nav";import { PoweredBy } from "../powered-by";import Question from "../question";@@ -117,11 +114,6 @@ export default function PagesVerticalViewer({const [submittedFeedback, setSubmittedFeedback] = useState<boolean>(false);const [accountCreated, setAccountCreated] = useState<boolean>(false);const [scale, setScale] = useState<number>(1);- const [annotationsEnabled, setAnnotationsEnabled] = useState(false);-- // Fetch annotations for this link- const { annotations } = useViewerAnnotations(linkId, documentId, viewId);- const hasAnnotations = annotations && annotations.length > 0;const initialViewedPages = Array.from({ length: numPages }, (_, index) => ({pageNumber: index + 1,@@ -773,17 +765,6 @@ export default function PagesVerticalViewer({return () => window.removeEventListener("keydown", handleKeyDown);}, []);- const handleToggleAnnotations = (enabled: boolean) => {- setAnnotationsEnabled(enabled);- };-- const navDataWithAnnotations = {- ...navData,- annotationsEnabled,- hasAnnotations,- onToggleAnnotations: handleToggleAnnotations,- };-return (<><Nav@@ -794,7 +775,7 @@ export default function PagesVerticalViewer({handleZoomIn={handleZoomIn}handleZoomOut={handleZoomOut}handleFullscreen={handleFullscreen}- navData={navDataWithAnnotations}+ navData={navData}/><divstyle={{ height: "calc(100dvh - 64px)" }}@@ -802,9 +783,7 @@ export default function PagesVerticalViewer({><ResizablePanelGroup direction="horizontal">{/* Document Content */}- <ResizablePanel- defaultSize={annotationsEnabled && hasAnnotations ? 75 : 100}- >+ <ResizablePanel defaultSize={100}><divclassName={cn("h-full w-full",@@ -1082,24 +1061,6 @@ export default function PagesVerticalViewer({{/* </div> */}</ResizablePanel>- {/* Annotation Panel - Right Side */}- {navData.annotationsFeatureEnabled &&- annotationsEnabled &&- hasAnnotations && (- <>- <ResizableHandle className="w-1 bg-transparent transition-colors hover:bg-white/10" />- <ResizablePanel defaultSize={25} minSize={20} maxSize={40}>- <AnnotationPanel- brand={brand}- linkId={linkId}- documentId={documentId}- viewId={viewId}- currentPage={pageNumber}- isVisible={true}- />- </ResizablePanel>- </>- )}</ResizablePanelGroup></div></>diff --git a/lib/swr/use-annotations.ts b/lib/swr/use-annotations.tsindex 8f42480b..55dcc857 100644--- a/lib/swr/use-annotations.ts+++ b/lib/swr/use-annotations.ts@@ -48,11 +48,17 @@ export function useViewerAnnotations(documentId?: string,viewId?: string,) {+ // Don't fetch annotations if viewId is not available+ // This prevents 404 errors when the view hasn't been created yet+ const shouldFetch = !!viewId;+// For dataroom document links, use the specific document endpoint// For regular document links, use the general link endpoint- const endpoint = documentId- ? `/api/links/${linkId}/documents/${documentId}/annotations?viewId=${viewId}`- : `/api/links/${linkId}/annotations?viewId=${viewId}`;+ const endpoint = shouldFetch+ ? documentId+ ? `/api/links/${linkId}/documents/${documentId}/annotations?viewId=${viewId}`+ : `/api/links/${linkId}/annotations?viewId=${viewId}`+ : null;const { data, error, mutate } = useSWR<Omit<Annotation, "createdBy">[]>(endpoint,@@ -65,7 +71,7 @@ export function useViewerAnnotations(return {annotations: data,- loading: !error && !data,+ loading: shouldFetch && !error && !data,error,mutate,};