Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
update document list design and add timeAgo utility
Marc Seitz84040a455bfb
diff --git a/components/documents/document-card.tsx b/components/documents/document-card.tsxindex ae0fe831..09fce653 100644--- a/components/documents/document-card.tsx+++ b/components/documents/document-card.tsx@@ -1,4 +1,4 @@-import { getExtension } from "@/lib/utils";+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";@@ -28,31 +28,38 @@ export default function DocumentsCard({}return (- <li className="relative flex justify-between items-center space-x-4 px-4 py-4 sm:px-6 lg:px-8">- <div className="min-w-0 flex">+ <li className="relative rounded-lg bg-gray-800 p-3 pr-1 border-0 ring-1 ring-gray-700 transition-all hover:ring-gray-600 sm:p-4 mx-5 my-2 flex justify-between items-center max-w-4xl ml-auto">+ <div className="min-w-0 flex shrink items-center space-x-4">+ <div className="rounded-full p-2 bg-gray-700 w-10 text-center flex justify-center items-center">+ <span className="text-white whitespace-nowrap">+ {getExtension(document.file)}+ </span>+ </div><div className="flex-col"><div className="flex items-center"><h2 className="min-w-0 text-sm font-semibold leading-6 text-white">- <Link href={`/documents/${document.id}`} className="flex gap-x-2">+ <Link href={`/documents/${document.id}`}><span className="truncate">{document.name}</span>- <span className="text-gray-400">/</span>- <span className="whitespace-nowrap text-gray-500">- {getExtension(document.file)}- </span><span className="absolute inset-0" /></Link></h2><div className="flex ml-2"><button- className="text-gray-500 hover:text-gray-700 z-10"+ className="group rounded-full bg-gray-700 z-10 p-1.5 transition-all duration-75 hover:scale-105 hover:bg-blue-50 active:scale-95"onClick={() => handleCopyToClipboard(document.links[0].id)}title="Copy to clipboard">- <DocumentDuplicateIcon className="h-5 w-5" aria-hidden="true" />+ {/* <DocumentDuplicateIcon className="h-5 w-5 text-gray-500 group-hover:text-blue-800" aria-hidden="true" /> */}+ <Copy+ className="text-gray-400 group-hover:text-blue-800"+ aria-hidden="true"+ /></button></div></div>- <div className="mt-3 flex items-center gap-x-2.5 text-xs leading-5 text-gray-400">+ <div className="mt-1 flex items-center space-x-1 text-xs leading-5 text-gray-400">+ <p className="truncate">{timeAgo(document.createdAt)}</p>+ <p>•</p><p className="truncate">{`${document._count.links} ${document._count.links === 1 ? "Link" : "Links"}`}</p>@@ -67,3 +74,25 @@ export default function DocumentsCard({</li>);}+++function Copy({ 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"+ shapeRendering="geometricPrecision"+ className={className}+ >+ <path d="M15.5 2H8.6c-.4 0-.8.2-1.1.5-.3.3-.5.7-.5 1.1v12.8c0 .4.2.8.5 1.1.3.3.7.5 1.1.5h9.8c.4 0 .8-.2 1.1-.5.3-.3.5-.7.5-1.1V6.5L15.5 2z" />+ <path d="M3 7.6v12.8c0 .4.2.8.5 1.1.3.3.7.5 1.1.5h9.8" />+ <path d="M15 2v5h5" />+ </svg>+ );+}diff --git a/components/links/links-container.tsx b/components/links/links-container.tsxindex 15f2eb57..ec84b081 100644--- a/components/links/links-container.tsx+++ b/components/links/links-container.tsx@@ -7,6 +7,7 @@ import { formatDistance, parseISO } from "date-fns";import { useRouter } from "next/router";import { useState } from "react";import { mutate } from "swr";+import { timeAgo } from "@/lib/utils";export default function LinksContainer() {const { links } = useDocumentLinks();@@ -143,13 +144,7 @@ export default function LinksContainer() {<timedateTime={new Date(link.views[0].viewedAt).toISOString()}>- {formatDistance(- parseISO(- new Date(link.views[0].viewedAt).toISOString()- ),- new Date(),- { addSuffix: true }- )}+ {timeAgo(link.views[0].viewedAt)}</time>) : ("-"diff --git a/lib/utils.ts b/lib/utils.tsindex c81d50db..a7e4e173 100644--- a/lib/utils.ts+++ b/lib/utils.ts@@ -1,5 +1,6 @@import { clsx, type ClassValue } from "clsx";import { twMerge } from "tailwind-merge";+import ms from "ms"export function cn(...inputs: ClassValue[]) {return twMerge(clsx(inputs));@@ -100,3 +101,46 @@ export function capitalize(str: string) {return str.charAt(0).toUpperCase() + str.slice(1);}++export const timeAgo = (timestamp?: Date): string => {+ if (!timestamp) return "Just now";+ const diff = Date.now() - new Date(timestamp).getTime();+ if (diff < 60000) {+ // less than 1 second+ return "Just now";+ } else if (diff > 82800000) {+ // more than 23 hours – similar to how Twitter displays timestamps+ return new Date(timestamp).toLocaleDateString("en-US", {+ month: "short",+ day: "numeric",+ year:+ new Date(timestamp).getFullYear() !== new Date().getFullYear()+ ? "numeric"+ : undefined,+ });+ }+ return `${ms(diff)} ago`;+};++export function nFormatter(num?: number, digits?: number) {+ if (!num) return "0";+ const lookup = [+ { value: 1, symbol: "" },+ { value: 1e3, symbol: "K" },+ { value: 1e6, symbol: "M" },+ { value: 1e9, symbol: "G" },+ { value: 1e12, symbol: "T" },+ { value: 1e15, symbol: "P" },+ { value: 1e18, symbol: "E" },+ ];+ const rx = /\.0+$|(\.[0-9]*[1-9])0+$/;+ var item = lookup+ .slice()+ .reverse()+ .find(function (item) {+ return num >= item.value;+ });+ return item+ ? (num / item.value).toFixed(digits || 1).replace(rx, "$1") + item.symbol+ : "0";+}\ No newline at end of filediff --git a/package-lock.json b/package-lock.jsonindex 8078bbb4..571e3648 100644--- a/package-lock.json+++ b/package-lock.json@@ -31,6 +31,7 @@"eslint-config-next": "13.4.4","framer-motion": "^10.12.16","lucide-react": "^0.244.0",+ "ms": "^2.1.3","next": "13.4.4","next-auth": "^4.22.1","postcss": "8.4.23",@@ -52,6 +53,7 @@},"devDependencies": {"@tailwindcss/forms": "^0.5.3",+ "@types/ms": "^0.7.31","@types/ua-parser-js": "^0.7.36","prisma": "^4.15.0"},@@ -1983,6 +1985,12 @@"resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz","integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ=="},+ "node_modules/@types/ms": {+ "version": "0.7.31",+ "resolved": "https://registry.npmjs.org/@types/ms/-/ms-0.7.31.tgz",+ "integrity": "sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==",+ "dev": true+ },"node_modules/@types/node": {"version": "20.2.5","resolved": "https://registry.npmjs.org/@types/node/-/node-20.2.5.tgz",@@ -3151,6 +3159,11 @@}}},+ "node_modules/debug/node_modules/ms": {+ "version": "2.1.2",+ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",+ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="+ },"node_modules/decimal.js-light": {"version": "2.5.1","resolved": "https://registry.npmjs.org/decimal.js-light/-/decimal.js-light-2.5.1.tgz",@@ -5956,9 +5969,9 @@}},"node_modules/ms": {- "version": "2.1.2",- "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",- "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="+ "version": "2.1.3",+ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",+ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="},"node_modules/mz": {"version": "2.7.0",@@ -10173,6 +10186,12 @@"resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz","integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ=="},+ "@types/ms": {+ "version": "0.7.31",+ "resolved": "https://registry.npmjs.org/@types/ms/-/ms-0.7.31.tgz",+ "integrity": "sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==",+ "dev": true+ },"@types/node": {"version": "20.2.5","resolved": "https://registry.npmjs.org/@types/node/-/node-20.2.5.tgz",@@ -10963,6 +10982,13 @@"integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==","requires": {"ms": "2.1.2"+ },+ "dependencies": {+ "ms": {+ "version": "2.1.2",+ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",+ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="+ }}},"decimal.js-light": {@@ -12974,9 +13000,9 @@}},"ms": {- "version": "2.1.2",- "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",- "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="+ "version": "2.1.3",+ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",+ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="},"mz": {"version": "2.7.0",diff --git a/package.json b/package.jsonindex 0640f7ef..19b32fe1 100644--- a/package.json+++ b/package.json@@ -36,6 +36,7 @@"eslint-config-next": "13.4.4","framer-motion": "^10.12.16","lucide-react": "^0.244.0",+ "ms": "^2.1.3","next": "13.4.4","next-auth": "^4.22.1","postcss": "8.4.23",@@ -57,6 +58,7 @@},"devDependencies": {"@tailwindcss/forms": "^0.5.3",+ "@types/ms": "^0.7.31","@types/ua-parser-js": "^0.7.36","prisma": "^4.15.0"}