Skip to content

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

remove duplication

Ashish Viradiya0cc2f7ef668b
diff --git a/components/view/document-view.tsx b/components/view/document-view.tsx
index 05f109dc..b9f9f97e 100644
--- a/components/view/document-view.tsx
+++ b/components/view/document-view.tsx
@@ -19,6 +19,7 @@ import AccessForm, {
import EmailVerificationMessage from "./access-form/email-verification-form";
import ViewData, { TViewDocumentData } from "./view-data";
+import { useDisablePrint } from "@/lib/hooks/use-disable-print";
type RowData = { [key: string]: any };
type SheetData = {
diff --git a/components/view/hooks/use-disable-print.ts b/components/view/hooks/use-disable-print.ts
deleted file mode 100644
index 9f77e5e4..00000000
--- a/components/view/hooks/use-disable-print.ts
+++ /dev/null
@@ -1,59 +0,0 @@
-import { useEffect } from "react";
-
-interface UseDisablePrintOptions {
- className?: string;
- styleId?: string;
-}
-
-export function useDisablePrint({
- className = "printing-disabled",
- styleId = "printing-disabled-style",
-}: UseDisablePrintOptions = {}) {
- useEffect(() => {
- let style = document.getElementById(styleId) as HTMLStyleElement | null;
- if (!style) {
- style = document.createElement("style");
- style.id = styleId;
- style.textContent = `
- @media print {
- body.${className} * {
- display: none !important;
- }
- }
- `;
- document.head.appendChild(style);
- }
-
- const handleBeforePrint = () => {
- document.body.classList.add(className);
- };
-
- const handleAfterPrint = () => {
- document.body.classList.remove(className);
- };
-
- window.addEventListener("beforeprint", handleBeforePrint);
- window.addEventListener("afterprint", handleAfterPrint);
-
- const mediaQueryList = window.matchMedia?.("print");
- const mediaQueryHandler = (e: MediaQueryListEvent) => {
- if (e.matches) {
- handleBeforePrint();
- } else {
- handleAfterPrint();
- }
- };
-
- mediaQueryList?.addEventListener?.("change", mediaQueryHandler);
-
- return () => {
- if (style && style.textContent?.includes(`body.${className}`)) {
- style.remove();
- }
-
- window.removeEventListener("beforeprint", handleBeforePrint);
- window.removeEventListener("afterprint", handleAfterPrint);
- mediaQueryList?.removeEventListener?.("change", mediaQueryHandler);
- };
- }, [className, styleId]);
-}
\ No newline at end of file