Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
add views to document list
Marc Seitz03b1f6bc02d8
diff --git a/components/documents/document-card.tsx b/components/documents/document-card.tsxindex 09fce653..0b690ae7 100644--- a/components/documents/document-card.tsx+++ b/components/documents/document-card.tsx@@ -2,14 +2,14 @@ import { getExtension, nFormatter, timeAgo } from "@/lib/utils";import { ChevronRightIcon } from "@heroicons/react/20/solid";import { DocumentDuplicateIcon } from "@heroicons/react/24/outline";import Link from "next/link";-import { DocumentWithLinksAndLinkCount } from "@/lib/types";+import { DocumentWithLinksAndLinkCountAndViewCount } from "@/lib/types";import toast from "react-hot-toast";import Notification from "@/components/Notification";export default function DocumentsCard({document,}: {- document: DocumentWithLinksAndLinkCount;+ document: DocumentWithLinksAndLinkCountAndViewCount;}) {function handleCopyToClipboard(id: string) {navigator.clipboard@@ -67,10 +67,19 @@ export default function DocumentsCard({</div></div>- <ChevronRightIcon- className="h-5 w-5 flex-none text-gray-400"- aria-hidden="true"- />+ <Link+ onClick={(e) => {+ e.stopPropagation();+ }}+ href={`/documents/${document.id}/stats`}+ className="flex items-center z-10 space-x-1 rounded-md bg-gray-700 px-2 py-0.5 transition-all duration-75 hover:scale-105 active:scale-100"+ >+ <BarChart className="h-4 w-4 text-gray-400" />+ <p className="whitespace-nowrap text-sm text-gray-400">+ {nFormatter(document._count.views)}+ <span className="ml-1 hidden sm:inline-block">views</span>+ </p>+ </Link></li>);}@@ -96,3 +105,24 @@ function Copy({ className }: { className?: string }) {</svg>);}++function BarChart({ className }: { className?: string }) {+ return (+ <svg+ width="14"+ height="14"+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ stroke-width="2"+ stroke-linecap="round"+ stroke-linejoin="round"+ className={className}+ shapeRendering="geometricPrecision"+ >+ <line x1="12" x2="12" y1="20" y2="10" />+ <line x1="18" x2="18" y1="20" y2="4" />+ <line x1="6" x2="6" y1="20" y2="16" />+ </svg>+ );+}diff --git a/lib/swr/use-documents.ts b/lib/swr/use-documents.tsindex 3730bd68..9c75f776 100644--- a/lib/swr/use-documents.ts+++ b/lib/swr/use-documents.ts@@ -1,13 +1,13 @@import { useRouter } from "next/router";import useSWR from "swr";import { fetcher } from "@/lib/utils";-import { DocumentWithLinksAndLinkCount } from "@/lib/types";+import { DocumentWithLinksAndLinkCountAndViewCount } from "@/lib/types";export default function useDocuments() {const router = useRouter();const { data: documents, isValidating } = useSWR<- DocumentWithLinksAndLinkCount[]+ DocumentWithLinksAndLinkCountAndViewCount[]>(router.isReady && `/api/documents`, fetcher, {revalidateOnFocus: false,dedupingInterval: 30000,diff --git a/lib/types.ts b/lib/types.tsindex ef17d927..5ec30f0f 100644--- a/lib/types.ts+++ b/lib/types.ts@@ -13,9 +13,10 @@ export interface CreateUserEmailProps {};}-export interface DocumentWithLinksAndLinkCount extends Document {+export interface DocumentWithLinksAndLinkCountAndViewCount extends Document {_count: {links: number;+ views: number;};links: Link[];}diff --git a/pages/api/documents/index.ts b/pages/api/documents/index.tsindex 7639a0df..4c3506c0 100644--- a/pages/api/documents/index.ts+++ b/pages/api/documents/index.ts@@ -26,7 +26,7 @@ export default async function handle(},include: {_count: {- select: { links: true },+ select: { links: true, views: true },},links: {take: 1,