Skip to content

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

New and Updated link badge

Ashish Viradiya9524b3284b47
diff --git a/components/links/links-table.tsx b/components/links/links-table.tsx
index 58cdb2e6..67f5b3cc 100644
--- a/components/links/links-table.tsx
+++ b/components/links/links-table.tsx
@@ -1,9 +1,10 @@
import { useRouter } from "next/router";
-import { useState } from "react";
+import { useMemo, useState } from "react";
import { useTeam } from "@/context/team-context";
import { DocumentVersion } from "@prisma/client";
+import { isWithinInterval, subMinutes } from "date-fns";
import {
ArchiveIcon,
BoxesIcon,
@@ -52,6 +53,7 @@ import FileProcessStatusBar from "../documents/file-process-status-bar";
import BarChart from "../shared/icons/bar-chart";
import ChevronDown from "../shared/icons/chevron-down";
import MoreHorizontal from "../shared/icons/more-horizontal";
+import { Badge } from "../ui/badge";
import { ButtonTooltip } from "../ui/tooltip";
import EmbedCodeModal from "./embed-code-modal";
import LinkSheet, {
@@ -71,10 +73,49 @@ export default function LinksTable({
primaryVersion?: DocumentVersion;
mutateDocument?: () => void;
}) {
+ const now = Date.now();
const router = useRouter();
const { plan } = usePlan();
const teamInfo = useTeam();
+ const processedLinks = useMemo(() => {
+ if (!links?.length) return [];
+
+ const oneMinuteAgo = subMinutes(now, 1);
+ const sortedLinks = links.sort(
+ (a, b) =>
+ new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime(),
+ );
+
+ const latestUpdatedLink = links.reduce((latest, current) => {
+ return new Date(current.updatedAt) > new Date(latest.updatedAt)
+ ? current
+ : latest;
+ }, links[0]);
+
+ return sortedLinks.map((link) => {
+ const createdDate = new Date(link.createdAt);
+ const updatedDate = new Date(link.updatedAt);
+
+ return {
+ ...link,
+ isNew:
+ link.id === sortedLinks[0].id &&
+ isWithinInterval(createdDate, {
+ start: oneMinuteAgo,
+ end: now,
+ }),
+ isUpdated:
+ link.id === latestUpdatedLink.id &&
+ isWithinInterval(updatedDate, {
+ start: oneMinuteAgo,
+ end: now,
+ }) &&
+ updatedDate.getTime() !== createdDate.getTime(),
+ };
+ });
+ }, [links, now]);
+
const { canAddLinks } = useLimits();
const { data: features } = useSWR<{
embedding: boolean;
@@ -285,8 +326,8 @@ export default function LinksTable({
</TableRow>
</TableHeader>
<TableBody>
- {links && links.length > 0 ? (
- links
+ {processedLinks && processedLinks.length > 0 ? (
+ processedLinks
.filter((link) => !link.isArchived)
.map((link) => (
<Collapsible key={link.id} asChild>
@@ -300,7 +341,22 @@ export default function LinksTable({
</ButtonTooltip>
) : null}
{link.name || `Link #${link.id.slice(-5)}`}
-
+ {link.isNew && !link.isUpdated && (
+ <Badge
+ variant="outline"
+ className="animate-pulse border-transparent bg-emerald-500/15 text-emerald-600 transition-colors hover:bg-emerald-500/20 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2"
+ >
+ New
+ </Badge>
+ )}
+ {link.isUpdated && (
+ <Badge
+ variant="outline"
+ className="animate-pulse border-blue-500/30 text-blue-500"
+ >
+ Updated
+ </Badge>
+ )}
{link.domainId && hasFreePlan ? (
<span className="ml-2 rounded-full bg-destructive px-2.5 py-0.5 text-xs text-foreground ring-1 ring-destructive">
Inactive
@@ -562,14 +618,30 @@ export default function LinksTable({
</TableRow>
</TableHeader>
<TableBody>
- {links &&
- links
+ {processedLinks &&
+ processedLinks
.filter((link) => link.isArchived)
.map((link) => (
<>
<TableRow key={link.id} className="group/row">
<TableCell className="w-[180px] truncate">
{link.name || "No link name"}
+ {link.isNew && !link.isUpdated && (
+ <Badge
+ variant="outline"
+ className="animate-pulse border-transparent bg-emerald-500/15 text-emerald-600 transition-colors hover:bg-emerald-500/20 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2"
+ >
+ New
+ </Badge>
+ )}
+ {link.isUpdated && (
+ <Badge
+ variant="outline"
+ className="border-blue-500/30 text-blue-500"
+ >
+ Updated
+ </Badge>
+ )}
</TableCell>
<TableCell className="max-w-[250px] sm:min-w-[300px] md:min-w-[400px] lg:min-w-[450px]">
<div className="flex items-center gap-x-4 whitespace-nowrap rounded-sm bg-secondary px-3 py-1.5 text-xs text-secondary-foreground sm:py-1 sm:text-sm">