Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add collabsible visitors rows
Marc Seitz7839ce24da22
diff --git a/components/links/links-table.tsx b/components/links/links-table.tsxindex 08663e23..46572a9d 100644--- a/components/links/links-table.tsx+++ b/components/links/links-table.tsx@@ -29,6 +29,8 @@ import BarChart from "../shared/icons/bar-chart";import { nFormatter, timeAgo } from "@/lib/utils";import MoreHorizontal from "../shared/icons/more-horizontal";import { Skeleton } from "../ui/skeleton";+import LinksVisitors from "./links-visitors";+import ChevronDown from "../shared/icons/chevron-down";export default function LinksTable() {@@ -59,7 +61,7 @@ export default function LinksTable() {<Table><TableHeader><TableRow>- <TableHead className="font-medium">Name</TableHead>+ <TableHead className="font-medium hidden sm:table-cell">Name</TableHead><TableHead className="font-medium w-[250px]">Link</TableHead><TableHead className="font-medium">Views</TableHead><TableHead className="font-medium">Last Viewed</TableHead>@@ -72,7 +74,7 @@ export default function LinksTable() {<Collapsible asChild><><TableRow key={link.id} className="group/row">- <TableCell>{link.name || "No link name"}</TableCell>+ <TableCell className="hidden sm:table-cell">{link.name || "No link name"}</TableCell><TableCell className="min-w-[260px] sm:min-w-[450px]"><div className="group/cell flex items-center gap-x-4 rounded-md bg-gray-700 px-3 py-1 group-hover/row:ring-1 group-hover/row:ring-gray-100 hover:bg-gray-200 transition-all"><div className="whitespace-nowrap hidden sm:flex text-sm text-gray-300 group-hover/cell:hidden">{`https://papermark.io/view/${link.id}`}</div>@@ -88,7 +90,7 @@ export default function LinksTable() {</TableCell><TableCell><CollapsibleTrigger asChild>- <div className="flex items-center space-x-1">+ <div className="flex items-center space-x-1 [&[data-state=open]>svg.chevron]:rotate-180"><BarChart className="h-4 w-4 text-gray-400" /><p className="whitespace-nowrap text-sm text-gray-400">{nFormatter(link._count.views)}@@ -96,6 +98,7 @@ export default function LinksTable() {views</span></p>+ <ChevronDown className="h-4 w-4 text-gray-400 shrink-0 transition-transform duration-200 chevron" /></div></CollapsibleTrigger></TableCell>@@ -133,12 +136,14 @@ export default function LinksTable() {</TableCell></TableRow><CollapsibleContent asChild>- <TableRow className="bg-gray-700 hover:bg-gray-700">- <TableCell colSpan={5}>- Yes. Free to use for personal and commercial projects.- No attribution required.- </TableCell>- </TableRow>+ {/* <div className="hover:bg-transparent">+ <div className="w-full p-0"> */}+ <LinksVisitors+ linkName={link.name || "No link name"}+ linkId={link.id}+ />+ {/* </div>+ </div> */}</CollapsibleContent></></Collapsible>diff --git a/components/links/links-visitors.tsx b/components/links/links-visitors.tsxnew file mode 100644index 00000000..ec66e679--- /dev/null+++ b/components/links/links-visitors.tsx@@ -0,0 +1,60 @@+import { durationFormat, timeAgo } from "@/lib/utils";+import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";+import { TableCell, TableRow } from "@/components/ui/table";+import { useLinkVisits } from "@/lib/swr/use-link";+import { Gauge } from "@/components/ui/gauge";++++export default function LinksVisitors({linkId, linkName}: {linkId: string, linkName: string}) {+ const { views } = useLinkVisits(linkId);++ return (+ // <div className="w-full overflow-auto">+ <>+ {views+ ? views.map((view) => (+ <TableRow key={view.id} className="">+ <TableCell className="flex items-center space-x-3">+ <Avatar className="flex-shrink-0">+ <AvatarFallback>+ {view.viewerEmail?.slice(0, 2).toUpperCase()}+ </AvatarFallback>+ </Avatar>+ <div className="min-w-0 flex-1">+ <div className="focus:outline-none">+ {/* <span className="absolute inset-0" aria-hidden="true" /> */}+ <p className="text-sm font-medium text-gray-200">+ {view.viewerEmail}+ </p>+ <p className="text-sm text-gray-500">+ <span>{linkName}</span>+ </p>+ </div>+ </div>+ </TableCell>+ <TableCell className="text-sm text-gray-400 text-right">+ {durationFormat(view.totalDuration)}+ </TableCell>+ <TableCell className="text-sm text-gray-400">+ <Gauge+ value={view.completionRate}+ size={"small"}+ showValue={true}+ />+ </TableCell>+ <TableCell>+ <time+ className="truncate text-sm text-gray-400"+ dateTime={new Date(view.viewedAt).toISOString()}+ >+ {timeAgo(view.viewedAt)}+ </time>+ </TableCell>+ </TableRow>+ ))+ : null}+ </>+ // </div>+ );+}\ No newline at end of filediff --git a/components/shared/icons/chevron-down.tsx b/components/shared/icons/chevron-down.tsxnew file mode 100644index 00000000..05e64cd3--- /dev/null+++ b/components/shared/icons/chevron-down.tsx@@ -0,0 +1,18 @@+export default function ChevronDown({ className }: { className?: string }) {+ return (+ <svg+ width="14"+ height="14"+ viewBox="0 0 24 24"+ fill="none"+ stroke="currentColor"+ strokeWidth="2"+ strokeLinecap="round"+ strokeLinejoin="round"+ className={className}+ shapeRendering="geometricPrecision"+ >+ <path d="m6 9 6 6 6-6" />+ </svg>+ );+}\ No newline at end of filediff --git a/components/ui/avatar.tsx b/components/ui/avatar.tsxnew file mode 100644index 00000000..991f56ec--- /dev/null+++ b/components/ui/avatar.tsx@@ -0,0 +1,48 @@+import * as React from "react"+import * as AvatarPrimitive from "@radix-ui/react-avatar"++import { cn } from "@/lib/utils"++const Avatar = React.forwardRef<+ React.ElementRef<typeof AvatarPrimitive.Root>,+ React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Root>+>(({ className, ...props }, ref) => (+ <AvatarPrimitive.Root+ ref={ref}+ className={cn(+ "relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",+ className+ )}+ {...props}+ />+))+Avatar.displayName = AvatarPrimitive.Root.displayName++const AvatarImage = React.forwardRef<+ React.ElementRef<typeof AvatarPrimitive.Image>,+ React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image>+>(({ className, ...props }, ref) => (+ <AvatarPrimitive.Image+ ref={ref}+ className={cn("aspect-square h-full w-full", className)}+ {...props}+ />+))+AvatarImage.displayName = AvatarPrimitive.Image.displayName++const AvatarFallback = React.forwardRef<+ React.ElementRef<typeof AvatarPrimitive.Fallback>,+ React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback>+>(({ className, ...props }, ref) => (+ <AvatarPrimitive.Fallback+ ref={ref}+ className={cn(+ "flex h-full w-full items-center justify-center rounded-full bg-muted",+ className+ )}+ {...props}+ />+))+AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName++export { Avatar, AvatarImage, AvatarFallback }diff --git a/components/ui/gauge.tsx b/components/ui/gauge.tsxnew file mode 100644index 00000000..a716c6f5--- /dev/null+++ b/components/ui/gauge.tsx@@ -0,0 +1,80 @@+export const Gauge = ({+ value,+ size = "small",+ showValue = true,+}: {+ value: number;+ size: "small" | "medium" | "large";+ showValue: boolean;+}) => {+ const circumference = 332; //2 * Math.PI * 53; // 2 * pi * radius+ const valueInCircumference = (value / 100) * circumference;+ const strokeDasharray = `${circumference} ${circumference}`;+ const initialOffset = circumference;+ const strokeDashoffset = initialOffset - valueInCircumference;++ const sizes = {+ small: {+ width: "36",+ height: "36",+ textSize: "text-xs",+ },+ medium: {+ width: "72",+ height: "72",+ textSize: "text-lg",+ },+ large: {+ width: "144",+ height: "144",+ textSize: "text-3xl",+ },+ };++ return (+ <div className="flex flex-col items-center justify-center relative">+ <svg+ fill="none"+ shapeRendering="crispEdges"+ height={sizes[size].height}+ width={sizes[size].width}+ viewBox="0 0 120 120"+ strokeWidth="2"+ className="transform -rotate-90"+ >+ <circle+ className="text-[#333]"+ strokeWidth="12"+ stroke="currentColor"+ fill="transparent"+ shapeRendering="geometricPrecision"+ r="53"+ cx="60"+ cy="60"+ />+ <circle+ className="text-[hsla(131,41%,46%,1)] animate-gauge_fill"+ strokeWidth="12"+ strokeDasharray={strokeDasharray}+ strokeDashoffset={initialOffset}+ shapeRendering="geometricPrecision"+ strokeLinecap="round"+ stroke="currentColor"+ fill="transparent"+ r="53"+ cx="60"+ cy="60"+ style={{+ strokeDashoffset: strokeDashoffset,+ transition: "stroke-dasharray 1s ease 0s,stroke 1s ease 0s",+ }}+ />+ </svg>+ {showValue ? (+ <div className="absolute flex opacity-0 animate-gauge_fadeIn">+ <p className={`text-gray-100 ${sizes[size].textSize}`}>{value}</p>+ </div>+ ) : null}+ </div>+ );+};diff --git a/lib/utils.ts b/lib/utils.tsindex 09ccf58a..024dfd02 100644--- a/lib/utils.ts+++ b/lib/utils.ts@@ -123,6 +123,18 @@ export const timeAgo = (timestamp?: Date): string => {return `${ms(diff)} ago`;};+export const durationFormat = (durationInMilliseconds?: number): string => {+ if (!durationInMilliseconds) return "0 secs";++ if (durationInMilliseconds < 60000) {+ return `${Math.round(durationInMilliseconds / 1000)} secs`;+ } else {+ const minutes = Math.floor(durationInMilliseconds / 60000);+ const seconds = Math.round((durationInMilliseconds % 60000) / 1000);+ return `${minutes}:${seconds.toString().padStart(2, "0")} mins`;+ }+};+export function nFormatter(num?: number, digits?: number) {if (!num) return "0";const lookup = [diff --git a/tailwind.config.js b/tailwind.config.jsindex d852d0d8..69b31f1e 100644--- a/tailwind.config.js+++ b/tailwind.config.js@@ -151,18 +151,18 @@ module.exports = {//** END: TREMOR fontSize **//},keyframes: {- "accordion-down": {- from: { height: 0 },- to: { height: "var(--radix-accordion-content-height)" },+ gauge_fadeIn: {+ from: { opacity: "0" },+ to: { opacity: "1" },},- "accordion-up": {- from: { height: "var(--radix-accordion-content-height)" },- to: { height: 0 },+ gauge_fill: {+ from: { "stroke-dashoffset": "332", opacity: "0" },+ to: { opacity: "1" },},},animation: {- "accordion-down": "accordion-down 0.2s ease-out",- "accordion-up": "accordion-up 0.2s ease-out",+ gauge_fadeIn: "gauge_fadeIn 1s ease forwards",+ gauge_fill: "gauge_fill 1s ease forwards",},},},